Why doesn't my dynamic sql procedure work? All I'm trying to do is show a simple column from a table. I get the following erros:
ERROR at line 1: ORA-06550: line 1, column 7: PLS-00905: object SYSTEM.JOIN is invalid ORA-06550: line 1, column 7: PL/SQL: Statement ignored
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');
Errors:
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
execute join ('PROJECT', 'PROJECT.P_ID');and then runshow errors. BTW, is this-lv_col2 VARCHAR2(30;)a typo? if not this might be your problem - should belv_col2 VARCHAR2(30);