简体   繁体   中英

Oracle 11g R2 Express, Auto Increment in lowercase

I have problem on auto increment in lowercase. Based on this Auto Increment for Oracle question, I'm able to create auto increment but the table still in uppercase character.

How can I actually do it in lower case.

Here is my list of SQL:

CREATE TABLE  "myTable" 
   (    "tableID" NUMBER(*,0) primary key, 
        "tableColumn" VARCHAR2(30) 
   ) ;

CREATE SEQUENCE "tableID_SEQUENCE"
START WITH 1
INCREMENT BY 1;

CREATE OR REPLACE TRIGGER "tableID_TRIGGER"
BEFORE INSERT ON "myTable"
FOR EACH ROW
BEGIN
SELECT tableID_SEQUENCE.nextval INTO NEW.tableID FROM dual; //at this line, what changes needed to?
END;

INSERT INTO "myTable" ("tableColumn") VALUES ('ABC');

So currently I'm stuck at trigger query :

SELECT tableID_SEQUENCE.nextval INTO NEW.tableID FROM dual; 

In Oracle database objects are case-insensitive (their names) even when you use doublequotes. According to Oracle documentation:

You can use either quoted or nonquoted identifiers to name any database object. However, database names, global database names, and database link names are always case insensitive and are stored as uppercase. If you specify such names as quoted identifiers, then the quotation marks are silently ignored.

EDIT: Trying to answer more precisely.

You need to put a colon in front of the "NEW" variable and reference object names in quotes (because you used quotes):

CREATE OR REPLACE TRIGGER "tableID_TRIGGER"
   BEFORE INSERT
   ON "myTable"
   FOR EACH ROW
BEGIN
   SELECT "tableID_SEQUENCE".NEXTVAL INTO :NEW."tableID" FROM DUAL;
END;
/

You need to reference all quoted names with - quotes!:

"tableID" <> tableID
"tableID" <> TABLEID
"tableID" <> tableid
"tableID" = "tableID"
 tableID  =  tableID
 tableID  =  TABLEID
 tableID  =  tableid

So unless you really need to distinguish cases then don't use quotes in object naming.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM