我正在创建将在last_laoaded日期之后加载数据的过程。 我有一个LOAD_DATES表和last_load_date列。
create or replace
PROCEDURE LOAD_DATA
AS
last_load_date date;
BEGIN
SELECT LAST_LOAD_DATE INTO last_load_date FROM LOAD_DATES WHERE source='LIMS_ANALYTICAL';
EXECUTE IMMEDIATE 'INSERT INTO SAMPLE SELECT * FROM SRC.TBL1@DBLINK WHERE CHANGED_ON > last_load_date';
有谁知道为什么这不起作用? 这是一个错误:
Connecting to the database db1 222.
ORA-00904: "LAST_LOAD_DATE": invalid identifier
ORA-06512: at "db1.LOAD_DATA", line 7
ORA-06512: at line 2
Process exited.
答案 0 :(得分:2)
INSERT
声明只能是您程序的一部分。将这些放在一起,这样的事情应该有效
create or replace
PROCEDURE LOAD_DATA
AS
l_last_load_date date;
BEGIN
SELECT LAST_LOAD_DATE
INTO l_last_load_date
FROM LOAD_DATES
WHERE source='LIMS_ANALYTICAL';
INSERT INTO SAMPLE
SELECT *
FROM SRC.TBL1@DBLINK
WHERE CHANGED_ON > l_last_load_date;
END;
如果您确实想要出于某种原因使用动态SQL,请使用绑定变量。您的本地变量不在动态SQL语句的范围内。
EXECUTE IMMEDIATE
'INSERT INTO SAMPLE ' ||
' SELECT * FROM SRC.TBL1@DBLINK WHERE CHANGED_ON > :1'
USING l_last_load_date;