在这个过程中,在我的控制台中打印的最终sql语句是正确的,当你在程序内部运行它作为静态sql语句时,它运行时没有任何错误。但是在动态sql里面它失败了。
我尝试使用DYNAMIC_SQL包执行,但它会导致相同的错误。另外,我尝试将其作为' table(testCodes)'的绑定变量。那也失败了。标签oracleplsqldynamicquerystored-procedures建议标签:oracle你的问题无法提交。
create or replace TYPE "INPUTCODE" as object (pc varchar2(100) )
create or replace TYPE "INPUTCODEARR" IS TABLE OF inputcode;
create or replace PROCEDURE "TEST_PROC" (
testCodes IN inputcodeArr,
timeHorizon IN NUMBER,
p_recordset OUT SYS_REFCURSOR)
AS var_sqlStmt VARCHAR2(4096);
BEGIN
var_sqlStmt := 'select t.a,t.b, t.c';
var_sqlStmt := var_sqlStmt || 'from test t';
if testCodes is not null then
var_sqlStmt := var_sqlStmt || ', table(testCodes) tc';
var_sqlStmt := var_sqlStmt || 'where tc.pc = t.name';
end if;
dbms_output.put_line('Final SQL Statement::' || var_sqlStmt);
open p_recordset for var_sqlStmt;
END TEST_PROC;
答案 0 :(得分:-1)
var_sqlStmt := 'select t.a,t.b, t.c';
var_sqlStmt := var_sqlStmt || ' from test t';
if testCodes is not null then
var_sqlStmt := var_sqlStmt || ', table('||testCodes||') tc';
var_sqlStmt := var_sqlStmt || ' where tc.pc = t.name';
这应该有用。