为什么我的动态 sql 过程不起作用?我要做的就是从表格中显示一个简单的列。我收到以下错误:
第 1 行出现错误:ORA-06550:第 1 行,第 7 列:PLS-00905:对象 SYSTEM.JOIN 无效 ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略
create or replace procedure join
(p_table1 in varchar2,
p_joincolumn1 in varchar2,
p_joincolumn2 in varchar2)
AS
lv_query varchar2(500);
lv_cursor number;
lv_col1 VARCHAR2(30);
lv_col2 VARCHAR2(30);
loopcount number:=0;
cursor_return_value integer;
begin
lv_cursor:=dbms_sql.open_cursor;
dbms_output.put_line('Value assigned to cursor= ' || lv_cursor );
lv_query:='select p_joincolumn1 from p_table1';
dbms_output.put_line(lv_query);
dbms_sql.parse(lv_cursor, lv_query, dbms_sql.native);
dbms_sql.define_column (lv_cursor, 1, lv_col1);
dbms_sql.define_column (lv_cursor, 2, lv_col2);
cursor_return_value := dbms_sql.execute (lv_cursor);
LOOP
loopcount:=loopcount+1;
dbms_output.put_line('loopcount= ' || loopcount );
if dbms_sql.fetch_rows (lv_cursor)=0 then
EXIT;
end if;
dbms_sql.column_value(lv_cursor, 1, lv_col1);
dbms_sql.column_value (lv_cursor, 2, lv_col2);
dbms_output.put_line(lv_col1 || ' ' || lv_col2 );
END LOOP;
dbms_output.put_line('At end of loop');
dbms_sql.close_cursor(lv_cursor);
end;
/
execute join ('PROJECT', 'PROJECT.P_ID', 'PROJECT.SKILL_ID');
错误:
Procedure created.
SQL>
SQL> execute testing_j ('PROJECT', 'PROJECT.P_ID', 'PROJECT.SKILL_ID');
Value assigned to cursor= 20
select p_joincolumn1 from p_table1
BEGIN testing_j ('PROJECT', 'PROJECT.P_ID', 'PROJECT.SKILL_ID'); END;
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_SYS_SQL", line 906
ORA-06512: at "SYS.DBMS_SQL", line 39
ORA-06512: at "SYSTEM.TESTING_J", line 17