【发布时间】:2013-07-07 16:16:03
【问题描述】:
我是第一次使用 Oracle,更习惯于使用 sql server 及其身份。但现在我正在尝试使用序列和触发器。但是不断收到这个我无法修复的错误。
identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
任何人都可以帮助解决它,这是我的代码。
EXECUTE IMMEDIATE' CREATE SEQUENCE stagechardata_stagecharid
START WITH 1
INCREMENT BY 1;';
EXECUTE IMMEDIATE' CREATE OR REPLACE TRIGGER stagechardata_stagecharid_TRG
BEFORE INSERT
ON stage_char_data
FOR EACH ROW
BEGIN
IF NEW.stage_char_id IS NULL THEN
SELECT stagechardata_stagecharid.NEXTVAL INTO NEW.stage_char_id
FROM DUAL;
END IF;
END;';
【问题讨论】:
-
你为什么使用
execute immediate?您是否有理由需要从 PL/SQL 而不是普通 SQL 动态创建这些? (事实上,您不应该在第一个动态语句的末尾使用分号,并且您的new引用缺少冒号,但这些不会导致该错误)。你能展示剩下的 PL/SQL 块或脚本吗? -
删除
create sequence语句末尾的;。使用execute immediate时,常规 SQL 语句不需要它,仅在创建 PL/SQL 过程时才需要。
标签: sql oracle triggers sequence