create or replace
PROCEDURE PROCEDURE1
AS
MYCOLUMNVAR VARCHAR2(50);
BEGIN
SELECT <<some query>> INTO MYCOLUMNVAR FROM DUAL; --this query contains
-- a regular expression
-- and some other criteria
-- to store a column
-- name into MYCOLUMNVAR
INSERT INTO TABLE_TMP(ID,COLUMN1)
(SELECT a.ID,b.MYCOLUMNVAR FROM TAB1 a, TAB2 b WHERE...)
上述查询中分配给MYCOLUMNVAR
的值为DATA
。我在表DATA
中有一个列名TAB2
。在尝试运行我正在进行的程序时
Error(50,3): PL/SQL: ORA-00904: "B"."MYCOLUMNVAR": invalid identifier.
答案 0 :(得分:1)
您需要dynamic query才能解决此类问题:
EXECUTE IMMEDIATE 'INSERT INTO TABLE_TMP(ID,COLUMN1)
(SELECT a.ID,b.' || MYCOLUMNVAR || ' FROM TAB1 a, TAB2 b WHERE...)'