[英]Is possible to create a for loop feeding a SQL procedure with result set in PL/SQL?
In an attempt to feed the result (owner, object_name) of a query into DBMS_STATS I've tried the following PL/SQL fragment: 为了将查询的结果(所有者,object_name)输入DBMS_STATS,我尝试了以下PL / SQL片段:
DECLARE
CCLOB VARCHAR2(500);
BEGIN
FOR rec IN (
select o.owner own,o.object_name obn
from sys.col_group_usage$ cg,dba_objects o
where cg.obj#=o.object_id
group by owner,object_name
)
LOOP
DBMS_OUTPUT.put_line (rec.own||' '||rec.obn);
SELECT dbms_stats.report_col_usage(ownname =>'''rec.own''', tabname =>'''rec.obn''') into CCLOB from dual;
DBMS_OUTPUT.PUT_LINE(CCLOB);
END LOOP;
END;
/
but the result is: 但结果是:
DWI DWATOBP
ORA-20001: 'REC.OWN' is an invalid identifier
################SNPI#################
AGUN RDC
ORA-20001: 'REC.OWN' is an invalid identifier
PL/SQL procedure successfully completed.
Some variations on the code with their errors: 代码的一些变体及其错误:
a) with no quotes: a)没有引号:
SELECT dbms_stats.report_col_usage(ownname =>rec.own, tabname =>rec.obn) into CCLOB from dual;
DWI DWATOBP
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 14
b) with 1 single quote: b)单引号:
SELECT dbms_stats.report_col_usage(ownname =>'rec.own', tabname =>'rec.obn') into CCLOB from dual;
DWI DWATOBP
ORA-20001: REC.OWN is an invalid identifier
c) with 2 single quotes: c)用2个单引号引起来:
SELECT dbms_stats.report_col_usage(ownname =>''rec.own'', tabname =>''rec.obn'') into CCLOB from dual;
ERROR at line 14:
ORA-06550: line 14, column 54:
PL/SQL: ORA-00907: missing right parenthesis
ORA-06550: line 14, column 7:
PL/SQL: SQL Statement ignored
By passing the parameters in as '''rec.own''' and '''rec.obn''', you're actually passing in the strings: 'rec.own' and 'rec.obn'. 通过将参数传递为'''rec.own'''和'''rec.obn''',实际上就是在传递字符串:'rec.own'和'rec.obn'。 Neither of which are valid identifier names!
两者都不是有效的标识符名称!
Remove the single quotes, and it should work. 删除单引号,它应该工作。
ETA: Also, change the variable CCLOB to be CLOB datatype, as dbms_stats.report_col_usage returns a CLOB. ETA:另外,将变量CCLOB更改为CLOB数据类型,因为dbms_stats.report_col_usage返回一个CLOB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.