I have a stored procedure like this
CREATE OR REPLACE PROCEDURE schema_name.CHECKS IS tbl_name VARCHAR2 (50); constraint_nm VARCHAR2 (100); CURSOR cur_constraint IS SELECT DISTINCT table_name, constraint_name FROM all_constraints WHERE constraint_type = 'R' AND STATUS = 'ENABLED' AND R_OWNER = 'owner1' AND r_constraint_name = 'constraint1'; BEGIN DBMS_OUTPUT.put_line ('Constraint Name'); OPEN cur_constraint; LOOP FETCH cur_constraint INTO tbl_name, constraint_nm; EXIT WHEN cur_constraint%NOTFOUND; DBMS_OUTPUT.put_line (constraint_nm||'~~'||tbl_name); END LOOP; close cur_constraint; END CHECKS;
And I perform this procedure
set serveroutput on BEGIN schema_name.CHECKS (); END;
And I get the conclusion
Procedure created. Constraint Name PL/SQL procedure successfully completed.
It does not return any result, but ideally it should return a string (the select query used to determine the cursor returns a string).
When I execute the above code as a PL / SQL block like this
DECLARE tbl_name VARCHAR2 (50); constraint_nm VARCHAR2 (100); CURSOR cur_constraint IS SELECT DISTINCT table_name, constraint_name FROM all_constraints WHERE constraint_type = 'R' AND STATUS = 'ENABLED' AND R_OWNER = 'owner1' AND r_constraint_name = 'constraint1'; BEGIN FOR i IN cur_constraint LOOP EXIT WHEN cur_constraint%NOTFOUND; DBMS_OUTPUT.put_line (i.constraint_name||' is in '||i.table_name); END LOOP; END;
It returns a single row as expected.
Please help me understand why it behaves strangely when the logic is the same, except for how I execute it.
Vivek source share