在编写PL / SQL块时,出现以下错误。请让我知道此错误的原因吗?
DECLARE
TYPE TABLE_NAME IS VARRAY(17) OF VARCHAR(255);
TABLENAME TABLE_NAME;
TOTAL INTEGER;
BEGIN
TABLENAME := TABLE_NAME ('FA_AS_ASSIGNMENTS','FA_PE_PHONES' );
TOTAL := TABLENAME.COUNT;
FOR i IN 1 .. TOTAL
LOOP
INSERT
INTO CUSTOM_ODILOAD_TABLE_COUNT
(
TABLE_NAME,
ROW_COUNT
)
VALUES
(
TABLENAME(i),
(SELECT COUNT(*) FROM TABLENAME(i)
)
);
END LOOP;
END;
错误:
ORA-06550:第19行,第40列:PL / SQL:ORA-00907:缺少右括号
ORA-06550:第10行,第5列:PL / SQL:忽略了SQL语句06550。00000-
“第%s行,第%s列:\ n%s”
*原因:通常是PL / SQL编译错误。
*操作:匿名阻止已完成
答案 0 :(得分:2)
您不能为静态查询使用动态表名(即无法对表名进行参数设置):
DECLARE
TYPE TABLE_NAME IS VARRAY(17) OF VARCHAR(255);
TABLENAME TABLE_NAME;
TOTAL INTEGER;
cnt INTEGER;
BEGIN
TABLENAME := TABLE_NAME ('FA_AS_ASSIGNMENTS','FA_PE_PHONES' );
TOTAL := TABLENAME.COUNT;
FOR i IN 1 .. TOTAL
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || TABLENAME(i) INTO cnt;
INSERT INTO CUSTOM_ODILOAD_TABLE_COUNT (TABLE_NAME, ROW_COUNT)
VALUES ( TABLENAME(i), cnt);
END LOOP;
END;