Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I have created a procedure to display rows from a table like following:
SQL
CREATE PROCEDURE SPGETDEPT
(P_CUR OUT SYS_REFCURSOR)
AS
BEGIN
OPEN P_CUR FOR
SELECT * FROM DEPT;
END;
/


and to run it:
SQL
var cur REFCURSOR
exec spgetdept(:cur);
print cur;


My question is how to club the above two parts so that output can be obtained by executing one procedure only:
SQL
execute newStoredProcedure;


Any help or idea is highly appreciated....
Thank you...!!
Posted
Updated 15-Aug-17 18:05pm

If I understand your question correctly, instead of using a stored procedure, I'd go with a table function, possibly pipelined if the amount of data is larger. A table function can return a result set that can be used also in a query.

Have a look at topics:
- Function Returning a Result Set
- Creating a Pipelined Function
in Examples for Creating Oracle Functions[^]
 
Share this answer
 
Comments
planetz 16-Aug-15 14:21pm    
Hello Mika,

What I wanted to do is connect this procedure to dropdownlist at design time through sqlDataSource to show the dept name in the drop down. Just for practice. But there is no option to include function. Is there any way to create procedure for same?
Wendelius 16-Aug-15 14:47pm    
Ok, I see. Have a look at Using Oracle Stored Procedures in SqlDataSource Select Command[^]. Would that be what you're after?
Wendelius 16-Aug-15 23:51pm    
Just for a clarification, you could try using syntax

SELECT ... FROM TABLE(FunctionName...)

So from the SqlDataSource point of view this would be a simple SELECT, not a function nor a stored procedure.
hey..i tried something like this:
SQL
CREATE OR REPLACE PROCEDURE sp AS
DEPT_REC     tbldept%TABLETYPE;
CURSOR p_cur IS SELECT * FROM tbldept;
BEGIN
OPEN p_cur;
DBMS_OUTPUT.PUT_LINE('HI');
LOOP
    FETCH p_cur INTO DEPT_REC;
    EXIT WHEN p_cur%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(DEPT_REC);            
  END LOOP;
CLOSE p_cur; 
END;


output is coming as expected but the column headers are not coming in output..i guess this wont serve my purpose...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900