Calling a procedure that returns a cursor in a procedure
HelloI have two stored procedures. They both return a cursor as output variables. However, I have another stored procedure that calls these procedures and return their results once again an output variable. I know that sounds strange to want to do something like this, but how can I do this?
Mikhail says:
My first procedure returns a cursor. But the cursor is opened on one condition. Like, if PARAM1 = 1 THEN OPEN cursor_1 to SELECT... OTHERWISE, OPEN CURSOR_1 TO SELECT... And the second slider has the same structure. The thing is in the two procedures if I declare that a single CURSOR_1 IN OUT parameter that the procedure will not work. So in both entities, I have two variables IN OUT SYS_REFCURSOR: c1 and c2. Then, in the third procedure I first call the first procedure, then the second. How can I write my third procedure in order to obtain the result two procedures United?
Why the appellant (3rd procedure) need to have 2 ref Cursor? How will the appellant to "unite" the sliders?
The actual data, a power of work must be done inside sliders. Not in PL/SQL or other languages. The SQL language is a very powerful and flexible language.
So if the SQL 2 data sets (or more) must be "United", then you should not use the 3rd procedure and PL/SQL code to do. Should use you 2 sliders.
You should watch this by using SQL only. The 2 sets of data can be merged, joined, union'ed. You can determine the intersection. You can determine the difference (with a negative sign). It can be rotated. It can be aggregated. It can be cube' ed. Etc.
This SQL will then be used as a single slider and a unique reference cursor handle will be used to consume the output of the cursor.
The basic rule to develop Oracle applications is simple. Optimize SQL. Minimize the PL/SQL.
Use the SQL language to the data of the crisis. No PL/SQL.
Tags: Database
Similar Questions
-
test a SP that returns a CURSOR
I am using Oracle 11 and trying to use SQL Developer. However, I can't seem to get the DEBUGGING to work to test the call a SP that returns a cursor.
I wrote a small test program to test, but they do not compile and I'm not sure why not. Can help you?
the first code fragment is a package that I have that has a defined CURTYPE. It is used throughout my request, when you declare a cursor:
now, here's the first part of the SP I want to test. Note that I've defined PriceCur as using the CURTYPE package.create or replace PACKAGE "SP_STATE" Is type curtype is ref cursor; ...
Now, here's my m.o.:create or replace PROCEDURE "USP_GETL_ACCOUNT_PRICES" ( AcctNo in marketer_account.mka_last_full_css_acct_no%type, MktrNo in marketer_account.mka_mktr_no%type, Status in varchar2 default null, PriceCur out sp_state.curtype ) as begin Open Pricecur For Select ...
They do not compile. What I'm doing here is call SP - pass 3 incoming parameters and retrieve a cursor.Declare Price_Cur Sp_State.Curtype; price_rec price_cur%rowtype; Begin Usp_Getl_Account_Prices('302189139000026', 11813,'A', price_cur); Open Price_Cur; Loop Fetch Price_Cur Into Price_Rec; Exit When Price_Cur%Notfound; dbms_output.put_line(price_cur%rowcount || ') ' || price_rec.apr_account_price_id); End Loop; close price_cur; end;
so I want to loop through the cursor and list some fields on...
Where I'm going wrong? Any help would be greatly appreciated.
SeanuserLynx wrote:
I get this error:Error report:
ORA-06504: PL/SQL: return variables of the game results or the query types do not match
ORA-06512: at line 7
+ 06504. 00000 - "PL/SQL: return of the variable result set or query types do not match." + "
* Cause: Numbers or types of columns in a query does not match declared.
return type of a variable result is defined or declared two result types
Set of variables do not match.
* Action: Change the program or the declaration statement. Check what query variable +.
actually we want during execution.He doesn't like the var defined as varchar2. I can change that to a % rowType heart?
When I proposed to modify the code according to your needs, I assume that you would like to change the instruction WRT Fetch your columns retrieved in the Refcursor; And so I suggest no changes in it.
As riedelme says, a record would help for better maintainability. :)
You do not experience other errors, you met earlier, right?
Kind regards
PPublished by: Jen K on July 12, 2012 12:04 AM
-
How to execute a stored procedure that returns a cursor?
How to execute a stored procedure that returns a cursor?
Follow the code:
CREATE OR REPLACE PROCEDURE stp_cashin_grupo
(p_func in VARCHAR
p_cod_grup in full
p_des_grup in VARCHAR
p_logi in VARCHAR
p_curs_rset ON infoc.pck_cashin_grupo.curs_rset
)
IS
BEGIN
If p_func = "1" then
OPEN FOR P_curs_rset
Select
cod_grup
des_grup
dat_manu_grup
des_logi_manu
of infoc.tbl_cashin_grupo
order of des_grup;
end if;
END stp_cashin_grupo;
and packaging:
CREATE or REPLACE PACKAGE pck_cashin_grupo
AS
TYPE curs_rset IS REF CURSOR;
END pck_cashin_grupo;
My question is how to execute in sql plus?
Stp_cashin_grupo EXEC ('1', 0, ", '465990', my doubt is how to move the cursor as return)
Thank youIt is described in the manual
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14357/CH5.htm#sthref1122
-
Request report - use the function that returns the cursor
My requirement is to create a report, which the source will be a function that returns a cursor (the type of cursor is ref cursor).
How this can be done?
for example. function my_func (pol_no in number) return cur_type < ref cursor >
Edited by: viveks on October 27, 2009 10:09Better to look at a function that returns a query, or use a hose to treat your cursor returned, because the APEX at the moment can NOT handle the sliders in reports...
Thank you
Tony Miller
Webster, TX -
How to call a function that returns a SYS_REFCURSOR?
Here's the situation.
If I use ODP. NET to get a REF_CURSOR of a procedure in a package that it works without a hitch.
If I use ODP .NET to run an Oracle function that returns a REF CURSOR, all sorts of things fool you.
I use .NET 3.5 and ODP .NET version 2.112.1.2 (11 G). My Oracle database is 9.2.0.7.0
There is this function returns a REF CURSOR.
The code looks something like this.
.NET code looks like this. It's after a few adjustments.CREATE OR REPLACE FUNCTION SENDMEAREFCURSOR RETURN SYS_REFCURSOR IS X_REF genPkg.genericcursor; BEGIN OPEN X_REF for SELECT customer_id, name FROM CUSTOMERS; Return X_REF; END;
What should I do to get the refCursor?private static OracleDataReader FireMyFunc(OracleConnection oc) { try { OracleCommand cmd = new OracleCommand(); cmd.Connection = oc; //cmd.CommandText = "SELECT sendmearefcursor FROM DUAL"; //cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "sendmearefcursor"; cmd.CommandType = CommandType.StoredProcedure; OracleParameter prm = cmd.CreateParameter(); prm.OracleDbType = OracleDbType.RefCursor; prm.ParameterName = "returncurse"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); cmd.ExecuteNonQuery(); return (OracleDataReader) prm.Value; //Throws an UnableToCast exception. } catch (System.Exception ex) { Console.WriteLine(String.Format("FireMyFunc: {0}",ex.ToString())); throw; } }
Hello
You can use the GetDataReader of the OracleRefCursor object to return the datareader object.
OracleRefCursor rc is prm (OracleRefCursor). Value;
return of rc. GetDataReader();HTH
Jenny -
Return a cursor in function - Oracle 7.3.4
Hello
I need to implement a function (or stored procedure) in a 7.3.4 database that returns a cursor.
I did it for 11g and the code is something like this:
create or replace function foo( bar out SYS_REFCURSOR ) return number is begin OPEN bar FOR select arg1, arg2 ,arg3 from table; return 1; end;
How can I him re-implement the Oracle 7? (I wonder if it is still possible...)
Can I return the result set of the query "select arg1, arg2, arg3 table" in another way?
Thank you
Believe it or not, the code you posted will work in 7.3.4 with a change. SYS_REFCURSOR, if I'm not wrong, was introduced later. This means creating a package with Ref Cursor type declaration:
CREATE OR REPLACE
PACKAGE cv_types
AS
SYS_REFCURSOR TYPE IS REF CURSOR;END;
/
create or replace
function foo (bar on cv_types. SYS_REFCURSOR
) is back
Start
OPEN - bar TO select arg1, arg2, arg3 table;
Return 1;
end;
/
SY.
-
Calling an Oracle stored procedure that returns a REF cursor
Hi guys,.
I'm calling an Oracle stored procedure that returns a REF CURSOR. Here is the piece of code that I'm working on:
procedure TC307_MAIN (p_program varchar2, varchar2, varchar2, result_set OUT eng_cur p_engchgno p_project) as
Start
IF (p_program = 'Navybased' and p_project = 'PROTECTOR-BUILD') THEN
result_set: = comments. Tc307_Eng_Chg_Rpt.TC307_RNZN (p_engchgno, result_set = >);
END IF;
end TC307_MAIN;
procedure TC307_RNZN (p_engchgno varchar2, result_set IN OUT eng_cur) as
Start
end TC307_RNZN;
PL/SQL code behind TC307_RNZN is big enough, that's why I've not stuck here. Basically, the second stored procedure executes a PLSQL statement and returns a result set. I need to return the result_set in the main proceedings based on nested else statement which I am still trying to build. I get a compilation... error can someone guide me with the correct method to call the second stored procedure and returning in the main proceedings.
Thank you very much.Rohan,
Try this
procedure TC307_MAIN(p_program varchar2, p_project varchar2, p_engchgno varchar2, result_set OUT eng_cur) as begin IF (p_program = 'RNZN' and p_project = 'PROTECTOR-BUILD') THEN -- This is a procedure not a function guest.Tc307_Eng_Chg_Rpt.TC307_RNZN(p_engchgno, result_set); --UR compilation error on this line* END IF; end TC307_MAIN;
SS
http://DB-Oracl.blogspot.com -
Call a procedure that returns an array of the results of dotnet
Hi I have a function in the database (see below), I am creating a Web page and you want to call the function and get the results, how can I do this in dotnet using the ODP.net. does anyone have a code please... I called procedures in the database that return of refCursors but not tables.
Type rec_user is record (call varchar2 (200),)
Identification number);
Type tab_user is table of the rec_user;
function populate_user (piusername in varchar2) return tab_user;
------------------------------
Concerning
AshHello
Registration table is a PLSQL type and cannot be called from OIC (this is what ODP.NET is written in). If you change the procedure to return the table or Varray of the object instead, you could do that with the support of the UDT available in ODP 11106.21 and higher.
There is an example in this thread that you may find useful:
By the way the table of the UDT or Collection, as IN to the OracleDbType.InputOutput HELPIt will be useful,
Greg -
Call a procedure that returns a refcursor, use it in an another proc sql?
I have a procedure that returns a refcursor; How can I include this refcursor in a sql statement that is inside another procedure, or view etc.?
This is the kind of foolery, I tried so far (myproc1 returns a ref cursor):
create or replace procedure myproc2
(
slider ref RC
)
AS
RC1 of ref cursor;
Start
EXECUTE myproc1 (rc1).
Open rc for
Select rc1.* in the rc1;
end myproc2;If you want to use the result set in an SQL Ref Cursor won't be of any help. Can be read all nested Table Type. You can declare an object type and store your result in them and use them in SQL.
Thank you
Knani. -
Call a member function from a cursor in a procedure
Hello people
I'm a newbie in the process of learning of 10 G and oracle. My question is:
I created a type called row_po and set a member function getCost() that returns the total cost of the order with headings like the nested table, which I intend to call from a procedure. In the procedure my SELECT returns more than one record, and that's why I need to use a cursor. For each record, I've got display the order_no, quantity, and the order_cost (qty, and order_cost are part of a nested table headings). I am able to access the order_no and quantity, but do not know how to call the member function to get the order_cost. Here are my steps:
CREATE OR REPLACE PROCEDURE get_podet (part_num number)
AS
CURSOR c2 is
SELECT *.
OF po, TABLE (in. LineItemList_nestab) tab_po L
WHERE L.PartNo = part_num;
BEGIN
TO crec looped c2
DBMS_OUTPUT. Put_line (' ORDER NUMBER: ' | crec.) PONo);
DBMS_OUTPUT. Put_line (' LINE QTY: ' | crec.) Qty);
{color: #ff0000} * DBMS_OUTPUT. PUT_LINE (' ORDER VALUE: ' |) ''); -order_cost, which must be returned by the member function I mentioned-*.
{color} END LOOP;
EXCEPTION
WHILE OTHERS THEN
DBMS_OUTPUT. Put_line ('Failed' |) "SQLCODE: ' |" SQLCODE);
DBMS_OUTPUT. PUT_LINE ('SQL ERROR MESSAGE' |) SQLERRM);
END;
/
The red line is where I want to call my function getCost() which is a member of the tab_po in. as stated in my SELECTION.
All thoughts were highly appreciated.
Thanks and greetingsIt's always tricky with objects (or so I think...)
Modify the query in your procedure:
SELECT treat (value (po) as row_po).getCost() tot_cost , po.* , l.* FROM tab_po po, TABLE (po.LineItemList_nestab) L
This would make the function:
CREATE OR REPLACE PROCEDURE get_podet(part_num in number) AS CURSOR c2 is SELECT treat (value (po) as row_po).getCost() tot_cost , po.* , l.* FROM tab_po po, TABLE (po.LineItemList_nestab) L WHERE L.PartNo = part_num; BEGIN FOR crec in c2 LOOP DBMS_OUTPUT.PUT_LINE('ORDER NUMBER: ' || crec.PONo); DBMS_OUTPUT.PUT_LINE('LINE QTY: ' || crec.Qty); DBMS_OUTPUT.PUT_LINE('ORDER VALUE: ' ||crec.tot_cost ); -- order_cost which should be returned from the member function i've mentioned -- END LOOP; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Failed' || 'SQLCODE: ' || SQLCODE); DBMS_OUTPUT.PUT_LINE('SQL ERROR MESSAGE ' || SQLERRM); END;
Published by: Alex Nuijten on January 13, 2009 15:29
-
Error when the stored procedure returns a cursor in c pro
Hello
I tried to make things work, explained to the
[2537153 m]
He runs a stored procedure from pro c which returns a cursor.
But when I compllie to c pro I get following error. My name of the procedure's TEST.
If I change the output to an int value parameter. It compiles okay.
PLS-S-00306, wrong number or types of arguments in the call to 'TEST '.
Error on line 34, column 5 in file E:\C\Test\tt.pc
TEST(:test_cursor);
+.... 1 +.
PLS-S-00000, ignored statement
A semantic error on line 33, column 1, folder E:\C\Test\tt.pc:
BEGIN
+ 1 +
PCC-S-02346, PL/SQL found semantic errors
Can make a point about what could be the error?
I work from oracle 8i client. that connects to oracle 9.0.1.
Operating system is win 2000 sp4
Oh yes - differs from the code snippet I posted your with the declaration of the host cursor variable. A difference in the case. Is how important it?
( it's been almost 10 years since I've coded last in Pro * C, so be careful with these questions! ) ;-) )
-
Avoid calling the procedure in the cursor loop
Hi all
The following example of procedure the procedure written in cursor loop, is called each time until the end of the cursor loop...
What would be the alternative methods to write the procedure above instead to call the procedure inside the cursor for loopprocedure proc_main is DECLARE cursor c1 is select e.empno empno ,e.ename ename ,d.dname dname ,d.loc loc from emp e,dept d where e.deptno = d.deptno ; BEGIN for i in c1 LOOP proc_test(i.empno,i.ename,i.dname,i.loc) ; end loop; END; ----------- PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is --- --- begin select * into v1,v2,v3 .. from temp_tab where col1 =p_empno ---- ---- end;
My idea is to use collections... could you give me the code example using collections to meet the above criteria
Thank you
Published by: smile on February 28, 2012 15:45The ideal would be to collect all SQL logic and put as much of it in a single SQL statement as possible. It would be also great to determine what is the final outcome of the process and use it as a starting point for your SQL. For example, if the desired result is to upgrade the salaries of the employees where they have an entry in table x, you might find that you can avoid needing to separate the logic between multiple, i.e. instead of procedures
procedure proc_main is DECLARE cursor c1 is select e.empno empno ,e.ename ename ,d.dname dname ,d.loc loc from emp e,dept d where e.deptno = d.deptno ; BEGIN for i in c1 LOOP proc_test(i.empno,i.ename,i.dname,i.loc) ; end loop; END; ----------- PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is --- --- begin select * into v1,v2,v3 .. from temp_tab where col1 =p_empno ---- ---- UPDATE emp e SET sal = v2 WHERE e.empno = p_Empno; end;
You may simply have
procedure proc_main is BEGIN UPDATE emp e SET sal = ( SELECT t.new_sal FROM temp_tab t WHERE t.empno = e.empno ) WHERE EXISTS ( SELECT NULL FROM temp_tab t WHERE t.empno = e.empno ); END;
Even if your logic is more complex, you are likely to find that you can merge several of the statements that you could be running in a loop and replace that loop with a join.
Given the particular structure of what you posted if, instead of calling the procedure in a loop, you can simply move the cursor c1 as a parameter to proc_test that is
procedure proc_main is lc_c1 sys_refcursor; BEGIN OPEN lc_c1 FOR select e.empno empno ,e.ename ename ,d.dname dname ,d.loc loc from emp e,dept d where e.deptno = d.deptno ; proc_test(c1) ; END; ----------- PROCEDURE proc_test (p_Cursor sys_refcursor) is begin LOOP FETCH .... ...DO SOMETHING... EXIT WHEN p_Cursor%NOTFOUND; END LOOP; CLOSE p_Cursor; END;
But I highly recommend that you consider trying to merge as much of your SQL before considering the approach of cursor.
HTH
David
-
Function call that returns BOOLEAN
Hello
Could you suggest on below:
21 d
I call the existing function that returns a Boolean value (TRUE/FALSE), in my new code.
part of the new code should run only when the output more is true.
is logic below... right?
XX_TND_OUT is the existing function
=======================
IF (in_prod_id) XX_TND_OUT = TRUE
THEN
.. . Run my code
END IF;
Thank you.Be Boolean you can directly compare the function
IF XX_TND_OUT (in_prod_id) THEN ......execute my code END IF;
That is to say:
DECLARE FUNCTION iseven (num INTEGER) RETURN BOOLEAN IS BEGIN IF MOD (num, 2) = 0 THEN RETURN TRUE; ELSE RETURN FALSE; END IF; END iseven; BEGIN FOR i IN 1 .. 10 LOOP IF iseven (i) THEN DBMS_OUTPUT.put_line (i || ' is even'); ELSE DBMS_OUTPUT.put_line (i || ' is odd'); END IF; END LOOP; END; / 1 is odd 2 is even 3 is odd 4 is even 5 is odd 6 is even 7 is odd 8 is even 9 is odd 10 is even
Kind regards.
Al -
Hi friends I want to know how to call a procedure that has values arrary as parameter?
I have a procedure as shown below, and I am using oracle 11g.
create or replace procedure procedureName (v_hospital_id in NUMBER,
v_process_id VARR_VARRY,
v_cnt OUT NUMBER);
Now, how to call this procedure from PLSQL. If v_process_id values ('abc123', 'xyz234', 'sfs234')
Please present the definition of VARR_VARRY
If it's a simple table of varchar2.
declare
v_cnt NUMBER;
Start
procedureName (1, VARR_VARRY('abc123','xyz234','sfs234'), v_cnt);
end;
-
Calling stored procedures with parameters with the database connectivity Toolkit
Hi all
I'm new to the forum and struggling to find a solution to a particular problem I have in this respect, using the LabVIEW Database Connectivity Toolkit on a project, I am currently working on my work. I have a database in which I tables and stored procedures with parameters. Some of these stored procedures have input, output and return parameters.
I tried to follow this example, but to no avail: http://digital.ni.com/public.nsf/allkb/07FD130746083E0686257300006326C4?OpenDocument
Such a stored procedure I am working on the implementation is named "dbo.getAllowablePNs", running "SELECT * from DeviceType" (DeviceType is the table). In this case, it requires no input parameter, it has an output parameter that generates the table [cluster] and has a return parameter that returns an integer value (status code for execution) to show if an error occurred. The DeviceType table has 3 columns; ID (PK, int not null), PN (nvarchar ((15), null) and NumMACAddresses (int, null).) I have surpassed many examples and I talk to the support OR try to implement this and similar procedures stored in LabVIEW but have not been successful. I am able to connect to the database with the VI of open connection without error, but spin in some confusion as a result of this step. I then try to use the VI of parameter query create to call the stored procedure and set the parameters. I guess I would then use the Set parameter value for each parameter that is connected to the entry of parameters on the previous query with parameters VI VI? I am also having some confusion during and after these steps as well. I would greatly appreciate advice or suggestions that anyone could have in this situation because I am not a SQL expert. Also, I would be happy to provide more information that might be useful.
Kind regards
Jon
Here's what I use to do this. I think I had to change him create parameterized query VI for him to work. There is a post on the forum about this somewhere.
Maybe you are looking for
-
When I opened a second tab in Firefox, it won't go to my homepage. Instead, it goes to a page that shows what looks like a collection of pages (or links) that I visited in the recent past or distant. I rather go to my homepage, which is much more use
-
Hello guys: I face a problem recently, my boss asks me a program with the interface in several languages, just different and the same background block diagram code, so at - it advice or ideas? I considered a method, package the main code and develop
-
Unable to connect to the computer with the normal password
Suddenly, my computer won't let me by using my password to just disconnect stop any help welcome accepted gratefully thanks in advance Mary * original title - my computer has suddenly stopped to let me access it using my paswword it will disconnect j
-
Impossible to uninstall Lenovo Service bridge (Windows 10)
Since the installation of Lenovo Service bridge, I have been seeing this error frequently: "Local HTTP server for Lenovo Service bridge from error. Please check if any of the following ports is available: 50123, 50124. » I need to bridge service anyw
-
DLL Global\systemroot\system32\H8SRTmvumrxwnbv.dll
I tried to download malwarebytes and open it to fix the problem, but for some reason malwarebytes won't open. I tried in safe mode and it still not open. Any help would be greatly appreciated.Thank you.