有人可以幫助我修復該代碼。它不會在PL/SQL上運行(SQLPLUS @ script.sql),給出 SP2-0552:未聲明綁定變量「NEW」。序列和觸發器PL/SQL腳本用於在表上自動生成ID
Script.SQL
prompt Creating Table SYSTEMDATALOG;
declare
counter1 integer;
counter2 integer;
begin
SELECT COUNT(*) INTO counter1 FROM ALL_TABLES WHERE TABLE_NAME='SYSTEMDATALOG' AND OWNER='MZMESDB';
if counter1 = 1 then
DROP TABLE SYSTEMDATALOG;
end if;
SELECT COUNT(*) INTO counter2 FROM ALL_SEQUENCES WHERE SEQUENCE NAME='SEQSYSTEMDATALOG';
if counter2 = 1 then
DROP SEQUENCE SEQSYSTEMDATALOGID;
endif;
CREATE TABLE "MZMESDB"."SYSTEMDATALOG" ("ID" INTEGER NOT NULL ,
"DATETIME" DATE NOT NULL ,
"TYPE" VARCHAR2(64) NOT NULL,
"SEVERITY" INTEGER NOT NULL,
"SOURCE" VARCHAR2(64) NOT NULL,
"USER" VARCHAR2(64) NOT NULL,
"MESSAGE" VARCHAR2(1024), PRIMARY KEY ("ID") VALIDATE);
CREATE SEQUENCE SEQSYSTEMDATALOGID;
CREATE OR REPLACE TRIGGER TRIGSYSTEMDATALOGID
BEFORE INSERT ON SYSTEMDATALOG
FOR EACH ROW
BEGIN
SELECT SEQSYSTEMDATALOGID.NEXTVAL INTO :NEW.ID FROM DUAL;
END TRIGSYSTEMDATALOGID;
end;
/
提前感謝任何形式的幫助。
[DEFINITIVE CODE]
提示創建表SYSTEMDATALOG;
申報 counter1 integer; counter2整數; SELECT COUNT(*)INTO counter1 FROM ALL_TABLES WHERE TABLE_NAME ='SYSTEMDATALOG'AND OWNER ='MZMESDB';其中,
if counter1 = 1 then
execute immediate 'DROP TABLE SYSTEMDATALOG';
end if;
SELECT COUNT(*) INTO counter2 FROM ALL_SEQUENCES WHERE SEQUENCE_NAME='SEQSYSTEMDATALOG';
IF counter2 = 1 then
execute immediate 'DROP SEQUENCE SEQSYSTEMDATALOGID';
END IF;
execute immediate 'CREATE TABLE "MZMESDB"."SYSTEMDATALOG" (
"ID" INTEGER NOT NULL ,
"DATETIME" DATE NOT NULL ,
"TYPE" VARCHAR2(64) NOT NULL,
"SEVERITY" INTEGER NOT NULL,
"SOURCE" VARCHAR2(64) NOT NULL,
"USER" VARCHAR2(64) NOT NULL,
"MESSAGE" VARCHAR2(1024), PRIMARY KEY ("ID") VALIDATE)';
execute immediate 'CREATE SEQUENCE SEQSYSTEMDATALOGID';
execute immediate 'CREATE OR REPLACE TRIGGER TRIGSYSTEMDATALOGID
BEFORE INSERT ON SYSTEMDATALOG
FOR EACH ROW
BEGIN
SELECT SEQSYSTEMDATALOGID.NEXTVAL INTO :NEW.ID FROM DUAL;
END TRIGSYSTEMDATALOGID;';
end;
我正在使用EXECUTE IMMEDIATE,但沒有成功。我改變了腳本,因爲它不起作用... – Cox
你在你的執行立即代碼中有一些語法錯誤: 1.一個'end if;'拼錯了''endif;' 2.一些字符串常量aren' t由單引號('SYSTEMDATALOG'應該是'SYSTEMDATALOG')。 –
Endif確實是一個錯誤。我試過了,沒有引號,行爲也是一樣的。即使修復endif,我仍然會遇到「遇到符號」;「當期待以下某種情況時:如果」在PL/SQL處理器的最後一行。 – Cox