简体   繁体   English

Oracle 11g R2 Express,小写自动递增

[英]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. 基于这个针对Oracle的自动增量问题,我能够创建自动增量,但表仍为大写字符。

How can I actually do it in lower case. 我如何实际使用小写字母呢?

Here is my list of SQL: 这是我的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. 在Oracle数据库中,即使使用双引号,对象也不区分大小写(它们的名称)。 According to Oracle documentation: 根据Oracle文档:

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): 您需要在“ NEW”变量前面加上一个冒号,并在引号中引用对象名称(因为您使用了引号):

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. 因此,除非您确实需要区分大小写,否则不要在对象命名中使用引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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