Priting a refcursor values
I have a function that returns a refcursor based on two dates.Here I'm unable to print the refcursor records. Please help me.
This is my sample code:
DECLARE
RetVal TYPES. REF_CURSOR;
DATE OF V_DATE_1;
DATE OF V_DATE_2;
BEGIN
"V_DATE_1: = July 20, 2008;
"V_DATE_2: = July 13, 2008;
RetVal: = GET_PSTPS_BY_MULT_DATES_SP (V_DATE_1, V_DATE_2);
for i in 1.RetVal.count
loop
DBMS_OUTPUT. Put_line (' cursor values are: ' |) RetVal.i);
end loop;
COMMIT;
END;
/
Thanks in advance
Rambeau
Here's an example of how you can use refcursor:
SQL> DECLARE
2 RetVal sys_refcursor;
3 l_val dual%rowtype;
4
5 BEGIN
6
7 open RetVal for select * from dual;
8
9
10 loop
11 fetch RetVal into l_val;
12 exit when RetVal%notfound;
13 dbms_output.put_line(l_val.dummy);
14 end loop;
15
16 END;
17 /
X
PL/SQL procedure successfully completed
SQL>
7. open RetVal to select * twice; -do the same things as RetVal: = GET_PSTPS_BY_MULT_DATES_SP (V_DATE_1, V_DATE_2);
Tags: Database
Similar Questions
-
How to store refcursor in collection
Hello
Storing refcursor values in the collection, I get this error
The game results or the query variables return types do not match.
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
{code
-drop type patdetail_tab;
-drop type patdetail_obj;
-drop pat table;
-drop table t_pat;
CREATE or REPLACE TYPE patdetail_obj
AS
OBJECT (patid varchar2 (20), supplierid number)
/
CREATE or REPLACE TYPE patdetail_tab AS TABLE OF THE patdetail_obj;
/
(Pat) CREATE TABLE
patid varchar2 (25).
Vendor number
);
/
INSERT INTO pat
(
patid, provider
)
VALUES ('A1', 1);
INSERT INTO pat
(
patid, provider
)
VALUES ('A2', 2);
COMMIT;
CREATE TABLE t_pat)
patid varchar2 (25).
Vendor number
);
/
DECLARE
vpatdetail patdetail_tab;
emp_cv sys_refcursor;
BEGIN
OPEN FOR Emp_cv
SELECT patid, provider
PAT;
Get the emp_cv COLLECT in BULK IN vpatdetail;
INSERT INTO t_pat
(
patid, provider
)
SELECT *.
TABLE (vpatdetail);
COMMIT;
END;ORA-06504: PL/SQL: Return types of Result Set variables or query do not match ORA-06512: at line 9 Please assist me Thanks Alen
Well, I hope this is something much more complex than what you mentioned (or you do not want to use a SINGLE SQL statement to insert in...) Select * from...), but assuming that you that boiled down to make a test case easy for us (thanks!), here's a solution.
You must inform the database that you are using the object type you'll be mining block, the
patdetail_obj(patid, supplier)
in the code below
DECLARE vpatdetail patdetail_tab; emp_cv sys_refcursor; BEGIN OPEN emp_cv FOR SELECT patdetail_obj(patid, supplier) FROM pat; FETCH emp_cv BULK COLLECT INTO vpatdetail; INSERT INTO t_pat ( patid, supplier ) SELECT * FROM table (vpatdetail); CLOSE emp_cv; COMMIT; END;
-
I know this isn't question of pl/sql, but I don't see any other place to ask this question.
It is possible to perform the procedure in the Toad and the print output will put in a grid format as when we run simple sql statement
will it be possible to do? Thank you
exec vendorsearch ("Read", 1, 'v.vnamel asc',: rc);You can do this in case if your ": rc ' is a refcursor. in this case when you hit f - 9, it gives you a popup named "variables", in which select 'name' as ': rc ' and ' type' slider. Once the procedure is running, it displays the refcursor values in the data grid. for scalar data types, I don't think that you will be able to view. You can also place them in a block "end begin" and post them (it's easy). for other objects and type LOB data, I've ever tried, and I think, it won't work either, even if I'm wrong.
-
Get multiple values in a select statement in a variable to a procedure
Hello
I'm trying to craete a procedure where the entry of the procedure will be a similar string "a, b, c, d" and output the values of a table that matches the value separated by commas of in sting.
For this.
create table test (varchar2 (10)) nm;
Insert test values ('a');
Insert test values ('b');
Insert test values ('c');
Insert test values (');
Select * from test;
NM
------
one
b
c
d
Now I'm doing a procedure where the parameter will be the column values NM of TEST table in a string separated by commas like "a, b, c, d, x, l" there could be false values also.
The procedure will return only the values that are adapted with column NM from the TEST table for this I created this procedure.
create or replace procedure p_test (p_nm IN varchar2 / *, THE sys_refcursor p_out * /)
is
number of l_len;
l_val varchar2 (10);
l_val1 varchar2 (10);
Start
l_len: = length (p_nm);
-dbms_output.put_line (l_len);
Start
because me in 1.l_len
loop
Select REGEXP_SUBSTR (p_nm, ' ([^,] *)(,|$)', 1, I, NULL, 1) in double l_val;
-dbms_output.put_line (l_val);
-Open p_out for
Select * into l_val1 of test where nm = l_val;
dbms_output.put_line (l_val1);
output when l_len is null;
end loop;
exception
When no_data_found then
null;
end;
exception
while others then
dbms_output.put_line (' error reason :'||) SQLERRM |' :'|| error code SQLCODE);
end;
EXECUTE p_test ('a, b, c, d, q, w');
OUTPUT-
one
b
c
d
This procedure gives me out as I need, but I need to get this in a variable which should be OUT the parameter of this procedure will be called by the JAVA for our application.
As I already tried to use the refcursor (see the commented part), but it gives me no output during a call there.
Its a call to this procedure when I use the refcursor (removing comments).
declare
l_out sys_refcursor;
l_val varchar2 (20);
l_str varchar2 (20): = 'a, b, c, d;
Start
p_test (l_str, l_out);
loop
extract the l_out in l_val;
dbms_output.put_line (l_val);
dbms_output.put_line ('a');
When the output l_out % notfound;
end loop;
end;
So here I am stuck with that, how to get the result of multiple or I'm missing something here and if there is a better approach to this requirement as I come with that so I'm sharing it here.
OR if someone can tell me what is the problem with this package-
create or replace package p_test_api
is
type t_rec is rendered (name varchar2 (200));
type t_tab is table of index by pls_integer t_rec;
procedure p_pest_proc (p_nm in varchar2, p_out to t_tab);
end p_test_api;
/
create or replace package body p_test_api
is
procedure p_pest_proc (p_nm in varchar2, p_out to t_tab)
is
number of l_len;
l_val varchar2 (10);
l_val1 varchar2 (10);
Start
l_len: = length (p_nm);
Start
because me in 1.l_len
loop
Select REGEXP_SUBSTR (p_nm, ' ([^,] *)(,|$)', 1, I, NULL, 1) in double l_val;
dbms_output.put_line (l_val);
Select * bulk collect into p_out test where nm = l_val;
output when l_len is null;
end loop;
exception
When no_data_found then
null;
end;
exception
while others then
dbms_output.put_line (' error reason :'||) SQLERRM |' :'|| error code SQLCODE);
end p_pest_proc;
end p_test_api;
CALL THIS PACKAGE-
declare
l_out p_test_api.t_tab;
l_str varchar2 (20): = 'a, b, c, d;
Start
P_TEST_API. P_PEST_PROC (l_str, l_out);
dbms_output.put_line ('b');
because me in 1.l_out.count
loop
dbms_output.put_line ('a');
dbms_output.put_line (l_out (i). (Name)
dbms_output.put_line ('a');
When the output l_out.count = 0;
end loop;
dbms_output.put_line ('a');
end;
It won't loop
I am using-
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Thank you
First of all, get rid of it WHEN OTHERS like William already noted. If you do not want to use the collections:
SQL > create or replace
function f_test () 2
3 p_nm varchar2
4 )
5 return varchar2
6 is
v_result 7 varchar2 (4000);
Start 8
9. Select listagg (nm, ',') within the Group (nm control)
10 in v_result
11 test
where the 12 «,» | p_nm | ',' like '%', | NM | ',%';
13 return v_result;
14 end;
15.The function is created.
SQL > start
2 dbms_output.put_line (f_test ('a, b, c, d, x, w'));
3 end;
4.
a, b, c and dPL/SQL procedure successfully completed.
SQL >
SY.
-
Not able to get the value of the type defined in the other program
Hi all
I have create a type in a single package spec (Globally), now I'm using the same type in another package. Simply I'm calling the first package and try to store the value in the Type and use the same type in the second package.
But I'm not able to get the value
Type declaration
Declared in package Spec TYPE t_aa_derive_tbl_type IS TABLE OF xxxx%ROWTYPE; t_aa_derive t_aa_derive_tbl_type;
Package 1
Package1. PROCEDURE name( some parameters); is Cursor c1 is Select * from dual; begin OPEN c_aa_derive; FETCH c_aa_derive BULK COLLECT INTO t_aa_derive; CLOSE c_aa_derive; END get_aa_derive;
In my second package
I'll call you
Package1. PROCEDURE name( some parameters); and then i am trying to for i in 1 .. package1.t_aa_derive.COUNT LOOP .... .... ... end loop;
I can not entered the loop for some reason any.
Could someone guide me if anything I missed.
See you soon,.
San
And what did you like refcursor c_aa_derive in the call to package1.name? Is it returns all rows? If this isn't the case, COUNT will be 0.
SY.
-
Hi all
I have a variable refcursor, to which I will assign running queries.
All are defined (union) queries, with 5 or 6 selects the union, each select returns the same variable where clause. Value of the variable will be known at run time.
For example: (just an example)
{code}
Start
v_sql: = ' select col1, col2
of the Department
where dept_no =: 1
Union
Select col1, col2
of eur_dept
where dept_no =: 1
Union
Select col1, col2
of us_dept
where dept_no =: 1 ';
Open the v_ref_cur for v_sql using 20, 20, 20;
-rest of the logic
------------
-----------------
end;
{code}
Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.
Thank you!
DS says:
Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.
Yes - can be done using a dynamic anonymous block to create the refcursor (containing the SQL text), as oppose to the creation of the refcursor directly from the SQL text.
Not an approach I consider myself - unless there is absolutely no better way to address this particular issue.
SQL > var refcursor c.
SQL >
SQL > declare
News 2 sys_refcursor;
3. start
4 immediate execution
5 ' declare
6 varchar2 (4000) var1: =: 1; -/ / simple definition var - used several times
7. start
open 8: news for
9 select * from emp where mgr = var1
10 the union all the
11. Select * from emp where empno = var1;
12 end; »
13 using 7698-past the variable once
14 in the news; -getting refcursor as answer
15
16: c: = cur;
end 17;
18.
PL/SQL procedure successfully completed.
SQL >
SQL > print c
EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981/02/22 00:00:00 1250 500 30
7654 MARTIN SALESMAN 7698 1981/09/28 00:00:00 1250 1400 30
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
7900 JAMES CLERK 7698 1981/12/03 00:00:00 950 30
7698 BLAKE MANAGER 7839 1981/05/01 00:00:00 2850 30
6 selected lines.
SQL >
-
Hi all
There will be no effect in performance if we declare refcurosr with suspicion NOCOPY parameter in a Stored procedure procedure/package?
AFAIK variable refcursor who will make reference to the calling environment will hold just pointer not data and so avoid a NOCOPY effect.
Thank you!!
DS says:
One of my senior team members asked me to NOCOPY in all existing procedures where refcursor is returned as a parameter in my output project.
I told him that this will not add any performance improvement and has no effect.
I did it, because I was forced to do so.
Want to just check and take the advice from here in this forum.
I still have the document (in e-mails and in the procedure itself at the top) all these changes so that the future code-reviewers know EXACTLY why this change has been made and who authorized it. Probably you are asking your "senior" you say the reasons to support the change that they requested; You should document those as well.
Sounds like your "senior" team member is not so superior after all. You can use this as a topic of discussion in your dev group.
See the doc of the PL/SQL language.
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i48500
Calls to PL/SQL Tuning subprogramme with NOCOPY hint
By default,
OUT
andIN
OUT
parameters are passed by value. The values of aIN
OUT
settings are copied before the delivery of the subprogramme. During the execution of the subprogramme, temporary variables to maintain the output parameter values. If the subprogram exits normally, these values are copied to the actual parameters. If the subprogram exits with an unhandled exception, the original settings are unchanged.When the parameters represent structures of large data such as collections, records and instances of object types, this reproduction slows down execution and uses memory. In particular, this overload applies to each call to a method of the object: temporary copies are made of all attributes, so that any changes made by the method are only apply if the method ends normally.
To avoid this overload, you can specify the
NOCOPY
trick, which allows the PL/SQL compiler to passOUT
andIN
OUT
parameters by reference. If the subprogram exits normally, the action is the same as usual. If the subprogramme leaves at the beginning with an exception, the values ofOUT
andIN
OUT
parameters (or the attributes of the object) can still change. To use this technique, check that the subroutine handles all exceptions.Note the reference to the "large data structures. As you already know a REFCURSOR isn't a large data structure, so will not use NOCOPY.
The most important side effect is that, as noted in the last paragraph above, the characteristics of the 'exit' are modified if you use NOCOPY.
Point out that the last clause in your "senior": ENSURE THAT THE subprogram MANAGES all THE EXCEPTIONS.
Normally (i.e. without using NOCOPY) a REFCURSOR lucifera is a parameter OUT will NOT have a value if the procedure stops with an exception if the caller is unable to use it eventually. Maybe this isn't the case if you use NOCOPY.
Generally however, the use of NOCOPY would simply be an amendment unnecessary, but harmless.
-
execution of the procedure with refcursor as output parameter
Hi I have the package following a procedure with parameter as refcursor OUT.
Here is an example of sample with the same structure with name in the other table, handling exceptions in my dev environment
When I try to execute this procedure with the followig blockCREATE OR REPLACE PACKAGE TEST_PACK IS Type refCursor is REF CURSOR; PROCEDURE TEST_PROC (out_data out refCursor); END; CREATE OR REPLACE PACKAGE BODY TEST_PACK IS Procedure test_proc ( out_data out refCursor ) is -- v_sql varchar2(4000); -- begin v_sql := 'select * from emp'; DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql ); open out_data for v_sql; Exception when others then DBMS_OUTPUT.PUT_LINE ( 'Error '|| SQLCODE ||','||SQLERRM ); END; end ;
I get the following errorDECLARE TYPE my_newcursor IS REF CURSOR; test_cur my_newcursor; out_text VARCHAR2 (4000); BEGIN TEST_PACK.test_proc(TEST_CUR) ; LOOP FETCH test_cur INTO out_text; EXIT WHEN test_cur%NOTFOUND; dbms_output.put_line('Value of refcur is:'||out_text); END LOOP; CLOSE test_cur; END;
Could you please help me where I am doing wrongORA-00932: inconsistent datatypes: expected - got - ORA-06512: at line 8
Thank youYou must extract your data to an appropriate data type.
(and note there is no need to declare your own ref cursor type as Oracle provides sys_refcursor at the end)
for example
SQL> set serverout on SQL> SQL> create or replace procedure test_proc(out_data out sys_refcursor) is 2 v_sql varchar2(4000); 3 begin 4 v_sql := 'select * from emp'; 5 DBMS_OUTPUT.PUT_LINE ( 'Select Query is: '||v_sql ); 6 open out_data for v_sql; 7 end; 8 / Procedure created. SQL> SQL> declare 2 rc sys_refcursor; 3 empRec emp%rowtype; 4 begin 5 test_proc(rc); 6 loop 7 fetch rc into empRec; 8 exit when rc%notfound; 9 dbms_output.put_line('Employee: '||empRec.empno||' - '||empRec.ename); 10 end loop; 11 close rc; 12 end; 13 / Select Query is: select * from emp Employee: 7369 - SMITH Employee: 7499 - ALLEN Employee: 7521 - WARD Employee: 7566 - JONES Employee: 7654 - MARTIN Employee: 7698 - BLAKE Employee: 7782 - CLARK Employee: 7788 - SCOTT Employee: 7839 - KING Employee: 7844 - TURNER Employee: 7876 - ADAMS Employee: 7900 - JAMES Employee: 7902 - FORD Employee: 7934 - MILLER PL/SQL procedure successfully completed. SQL>
Why do you use a slider ref anyway?
{: identifier of the thread = 886365}
-
Exception during the update of a value of clob using dbms_lob.fragment_insert
Hello
This is the query
procedure tempProc (str3 in varchar2) is
CLOB QI;
-LOB (QI) STORE DO securefile;
v_cursor refcursor;
Str varchar2 (50);
i the number '30' default;
Start
Open v_cursor for select b.OCEAN_RATE_XML.getClobVal (B TNMAB_OCEAN_RATE_XML)
WHERE (XMLCast (XMLQuery (' declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder";))) ( : :) ObjectID/OceanOfferRate /'
PASSING B.OCEAN_RATE_XML REFERRING CONTENT) AS NUMBER (20))) = 200000000000050;
extract v_cursor in IQ;
close v_cursor;
dbms_output.put_line ('ABCD' |) DBMS_LOB. GetLength (QI));
DBMS_LOB.fragment_insert (QI, 3, DBMS_LOB.getlength (QI) - 17, "< abc / > '");
dbms_output.put_line (' ' inserted ');
DBMS_LOB. READ (QI, I, DBMS_LOB.getlength (QI) - I, str);
-DBMS_LOB. Read (QI, 20, DBMS_LOB. GetLength (QI) - 20, STR);
dbms_output.put_line ('jobs read');
dbms_output.put_line (STR);
end tempProc;
I get the exceptionError report below:
ORA-43856: LOB unsupported type for operation SECUREFILE LOB
ORA-06512: at "SYS." DBMS_LOB", line 1076
ORA-06512: at "TNM_PLSQL. TNM_AB_QI_UPDT_PKG', line 377
ORA-06512: at line 5
ORA-06512: at line 9 level
< OceanOfferRate xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" xmlns = "http://com.oocl.schema.tnm.agreementbuilder" >
< ObjectID > 200000000000050 < / ObjectID >
< RateID > 2 < / RateID >
< > 00000002 AgreementID < / AgreementID >
< StartingVersion > 0 < / StartingVersion >
< EndingVersion > 0 < / EndingVersion >
< EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
< EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
< RateStatus > QuoteExpired < / RateStatus >
Approved < ApprovalStatus > < / ApprovalStatus >
< flags > 3 < / Flags >
< rates > 015 < / rates >
< BaseRates >
20GP < SizeType > < / SizeType >
< amount > 65 < / amount >
< currency > $ < / currency >
< EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
< EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
< flags > 0 < / Flags >
< / BaseRates >
< BaseRates >
40GP < SizeType > < / SizeType >
< amount > 100 < / amount >
< currency > $ < / currency >
< EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
< EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
< flags > 0 < / Flags >
< / BaseRates >
< BaseRates >
40HQ < SizeType > < / SizeType >
< amount > 100 < / amount >
< currency > $ < / currency >
< EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
< EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
< flags > 0 < / Flags >
< / BaseRates >
default < ShippingPartyGroupName > < / ShippingPartyGroupName >
default < CustomerContactGroupName > < / CustomerContactGroupName >
default < NamedCustomerGroupName > < / NamedCustomerGroupName >
< LastSentDate > 2010-06-14T 22: 42:48.536000 < / LastSentDate >
< ValidityDays > 30 < / ValidityDays >
< ValidityExpirationDate > 2010-06-30T 00: 00:00.000000 < / ValidityExpirationDate >
< GuidelineRateReference >
< trunk >
< RateID > 100001510668470 < / RateID >
< SurchargeIDs > 684172719752758 < / SurchargeIDs >
< SurchargeIDs > 626856918161564 < / SurchargeIDs >
< SurchargeIDs > 680028613161439 < / SurchargeIDs >
< SurchargeIDs > 679555629913553 < / SurchargeIDs >
< SurchargeIDs > 673382151283681 < / SurchargeIDs >
< SurchargeIDs > 679789705628181 < / SurchargeIDs >
< SurchargeIDs > 653835218283772 < / SurchargeIDs >
< SurchargeIDs > 653955477367768 < / SurchargeIDs >
< SurchargeIDs > 653955477367759 < / SurchargeIDs >
< / trunk >
< / GuidelineRateReference >
< CreatedOn > 2010-05-16T 13: 40:29.201344 < / CreatedOn >
< CreatedBy > KRISHSA < / CreatedBy >
< vendor > COOKBR < / seller >
< BureauVentes > PHE < / BureauVentes >
< LastUpdated > 2010-06-30T 00: 13:06.000000 < / LastUpdated >
< LastUpdatedBy > TNM_APPLN < / LastUpdatedBy >
< origins >
< ID_Wrappers >
< value > 100000000026067 < / value >
< / ID_Wrappers >
< ID_Wrappers >
< value > 100000000008923 < / value >
< / ID_Wrappers >
< ID_Wrappers >
< value > 100000000024173 < / value >
< / ID_Wrappers >
< / origins >
< destination >
< ID_Wrappers >
< value > 100000000008923 < / value >
< / ID_Wrappers >
< ID_Wrappers >
< value > 100000000024173 < / value >
< / ID_Wrappers >
< ID_Wrappers >
< value > 100000000013006 < / value >
< / ID_Wrappers >
< ID_Wrappers >
< value > 100000000046704 < / value >
< / ID_Wrappers >
< / destination >
< DeliveryMode > YY < / DeliveryMode >
< TradeLane > IAT < / TradeLane >
< product >
< description > cotton for test < / Description >
< CargoNatureGroup > 32 < / CargoNatureGroup >
< / product >
< RateLevel > 1 < / RateLevel >
< / OceanOfferRate >
An adviser if there is other ways to update the clob with additional information at the end of the XML file before < / OceanOfferRate >?Hello
Funny approach ;)
I'm sure that you will find this more easy and much more supported:
SELECT appendChildXML( ocean_rate_xml , '/OceanOfferRate' , xmltype('
') , 'xmlns="http://com.oocl.schema.tnm.agreementbuilder"' ) FROM tnmab_ocean_rate_xml WHERE XMLCast( XMLQuery('declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder"; /OceanOfferRate/ObjectID' PASSING ocean_rate_xml RETURNING CONTENT) AS NUMBER(20) ) = 200000000000050 ; If your real goal is to update the column back, then you can do in a single statement:
UPDATE tnmab_ocean_rate_xml SET ocean_rate_xml = appendChildXML( ocean_rate_xml , '/OceanOfferRate' , xmltype('
') , 'xmlns="http://com.oocl.schema.tnm.agreementbuilder"' ) WHERE ... ; (BTW, to serialize the document use XMLSerialize rather than the old method of getClobVal function.)
In addition, new in version 11.2.0.3:
SELECT XMLQuery( 'declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder"; (: :) copy $d := /OceanOfferRate modify ( insert node
as last into $d ) return $d' passing ocean_rate_xml returning content ) FROM tnmab_ocean_rate_xml WHERE ... Published by: odie_63 on Dec 19. 2011 21:30 - added update of XQuery example
-
I have a function that returns a refcursor.
Now, I have view the output of this function, but only using dbms_output.put_line
Is this Possible and how.
Thanks in advance.A code example
CREATE OR REPLACE FUNCTION emp_by_job (p_job VARCHAR2,p_deptno NUMBER,pv_table VARCHAR2) RETURN SYS_REFCURSOR IS emp_refcur SYS_REFCURSOR; BEGIN OPEN emp_refcur FOR 'SELECT empno, ename FROM '||pv_table||' WHERE job = '||''''||p_job||''''||' and deptno= ' ||p_deptno; --Dynamic String where table name column values are parameters RETURN emp_refcur; END; / declare emp_refcur_local SYS_REFCURSOR; empno NUMBER(4); ename VARCHAR2(30); Begin --Calling the function using parameters emp_refcur_local:=emp_by_job('MANAGER',10,'EMP'); LOOP FETCH emp_refcur_local into empno,ename; EXIT WHEN emp_refcur_local%NOTFOUND; DBMS_OUTPUT.PUT_LINE('Employee no: '||empno||'/ Employee name: '||ename); END LOOP; end;
-
Working on a stored procedure that is called by the java application.
I do not know which of the following option is better and in which case:
1 stored procedure return/accepting a SYS_REFCURSOR parameter
or
2. at the level of schema:
TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
attribute_val VARCHAR2 (50)
);
create or replace
TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;
and then have a stored procedure accepts or returns a parameter of type emp_attrb_type
Thank you
RNRN says:
Working on a stored procedure that is called by the java application.I do not know which of the following option is better and in which case:
1 stored procedure return/accepting a SYS_REFCURSOR parameter
or
2. at the level of schema:TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
attribute_val VARCHAR2 (50)
);
create or replace
TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;and then have a stored procedure accepts or returns a parameter of type emp_attrb_type
Thank you
RNWell, a java application is unlikely to be able to pass a ref cursor, your procedure will therefore not need to accept a. Other than that, it really depends on how the data that you expect to get past back.
I have a number of stored procs called by java applications that return a single row in a table. In these cases, I often return an object, since it saves a step for Java guys who can use it more or less directly. Is there is not a limit on the number of rows returned exlplicit, then I would always return a refcursor.
If the java app must pass a set of values in the stored procedure (for example get this list of employees), then I would have java pass an array of objects (an array of records) to the stored procedure. It keeps me from having to parse a delimited string of values.
John
-
problem with the collection and refcursor
I have the 'ServerDisconnect2' function below. It should return as 'ref_cursor' on the parameter that is a data container of deleted rows slider, Java developers insist on using this type of data/collection. I don't know how to code to return the values of ID removed as 'ref_cursor '. See commented "open pDeleteList" - sentence, it is commented as does not compile.
Is it possible to convert the variable 'vDeleteList' in ref_cursor?CREATE OR REPLACE PACKAGE oe_ctx AS TYPE gIntegerTable IS TABLE OF INTEGER INDEX BY BINARY_INTEGER; TYPE cursor_type IS REF CURSOR; .... PROCEDURE ServerDisconnect2(pCasinoCode NUMERIC, pCasinoServerCode NUMERIC, pChannelServerCode CurrentLogins.ChannelServerCode%TYPE, pDeleteList OUT cursor_type) IS vDeleteList oe_ctx.gIntegerTable; BEGIN DELETE FROM ( SELECT cl.* FROM CurrentLogins cl, Accounts a WHERE cl.CasinoCode = pCasinoCode AND cl.CasinoServerCode = pCasinoServerCode AND cl.ChannelServerCode = pChannelServerCode AND cl.Code = a.code AND a.Type = 'lplayer' ORDER BY a.code ) RETURNING Code BULK COLLECT INTO vDeleteList; /* OPEN pDeleteList FOR SELECT * FROM TABLE(vDeleteList);*/ COMMIT; END ServerDisconnect2;
So my only solution would be to open the ref_cursor BEFORE delete-clause with the same query delete clause has. But I'm afraid that then after opening the instant cursor after a milliseconds the deletion clause removes different lines and the procedure would be data incorrect in pDeleteList.
Published by: CharlesRoos on August 26, 2010 06:10You need a collection of sql (created with CREATE TYPE...):
I'll use the predefined collection sys.odcivarchar2list demonstation purposes:
SQL> var cur refcursor SQL> declare ret_coll sys.odcivarchar2list; begin delete from emp returning ename bulk collect into ret_coll; open :cur for select * from table (ret_coll); end; / PL/SQL procedure successfully completed. SQL> print COLUMN_VALUE ----------------------------------------------------------------------------------------------------------------------------- SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER 14 rows selected.
-
Out of proc - values from multiple rows.
I have 5 tables. Every table has the following columns
TRANS_ID,
USER_ID,
OPRTN_TYPE,
STATUS,
DATE
I have to write a proc for which an entry is USER_ID and output must be TRANS_ID, OPRTN_TYPE, STATUS, DATE.
Is it possible to write the proc with the mentioned columns, the values will be more than one row in the table.user13024762 wrote:
I have 5 tables. And I need output of all tables at the same time. If I want to use Ref Cursor I write a cursor for each query with 5 outputs, or I can do it with a single output.No, just return a single Ref Cursor
Is it possible to bring together the tables? As I don't have your database or model, it is difficult to advise you on this.You could do something like
select TRANS_ID, USER_ID, OPRTN_TYPE, STATUS, DATE from table1 where user_id = p_parameter union all select TRANS_ID, USER_ID, OPRTN_TYPE, STATUS, DATE from table2 where user_id = p_parameter
and this return as a Ref Cursor
Thanks for the link refcursor.
You are welcome.. ;)
-
Value of aggrigate of procedure - Get Oracle on the comparison of two-column based
Hi all
I've written a procedure that accepts an input parameter and returns a refcursor.
The logic used in the procedure is:
The procedure is used to display the summary and the report in detail. When the input parameter has more than one saperated comma then it will act as a synthesis report, and when there is just a value as input, then it will act like a detailed report.
The input parameter is as "AA12345, BB45434, HJ89736," the first two characters is Brand_id and the rest of the 5 character is the propery_id.
The aggrigation of aggrigation query is:
Select Month_name, Year, sum (REVPAR), Sum (ADR) in the FIS_KPI_TREND where
Brand_id = 'AA' and SIte_id = '12345' Month_name group, year;
The above query will worke fine for detail report when there is just a value for the entry as 'AA12345 '.
The problem is coming to the summary report when I need to get the value of aggrigated for all the brand and the site which is entered in the input parameter.
So I changed the query in the form:
Select Month_name, Year, sum (REVPAR), Sum (ADR) in the FIS_KPI_TREND where
Brand_id | SIte_id in ('AA12345', 'BB45434', 'HJ89736') of the Group of Month_name, year;
(I use parser function to parse a comma saperated values.)
By doing this, I get the desired result, but the performance has decrised that the Index is based on Brand_id and Site_id but I'm using Brand_ID | Site_id for my research.
The one you suggest another way to rewrite this query so that it can take the index and not give me the output of sesired.
Database used: Oracle 10 g
Thanks in advance.
Sumit Narayan
Published by: Sumit Narayan, 11 April 2010 22:00I'd be inclined to do something like that to analyze the list separated by commas, that allows you to join without the concatenation of the columns as you do now.
ME_XE?select substr(column_value, 1, 2) as brand_id, substr(column_value, 3, length(column_value)) as site_id from table(sys.ODCIVARCHAR2LIST('AA12345','BB45434','HJ89736')); 2 3 4 BRAND_ID SITE_ID ---------- ---------- AA 12345 BB 45434 HJ 89736 3 rows selected. Elapsed: 00:00:00.20 ME_XE? ME_XE?select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for Linux: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production 5 rows selected. Elapsed: 00:00:00.39 ME_XE?
So for your case...
Select f.Month_name, f.Year, sum(f.REVPAR), Sum(f.ADR) from FIS_KPI_TREND f, table(sys.ODCIVARCHAR2LIST('AA12345','BB45434','HJ89736')) t where f.Brand_id = t.brand_id and f.SIte_id = t.site_id group by f.Month_name, f.Year;
Published by: Tubby 11 April 2010 22:12
-
Digital or value error on the conversion of the clob to SMLType
Hello
What I'm trying to do is
(i.) pass a value of xml string to the Oracle query variable
II.) use this XML as part of a join in a query and retrieve the results.
Approach:
Input variable type is CLOB and then running the petition below:
declare
TestXML clob.
Start
textxml: = ' < table1 > < root > < none > 1 < /no > < / root > < root > < none > 2 < / > < non-root / > < / table1 > '
Open: csr for
Select tt.no
de)
Select xmltype.extract (value (a), ' root/no/text()').getstringval () than no.)
table (xmlsequence (sys.xmltype(:testxml). Extract('/table1/root'))) a
) tt
Tt.no group;
end;
Problem:
The request as written above wake up a digital error or value to sys.xmltype (ORA-06502 & ORA-06512). But if I declare the testxml as varchar2; It works very well. Searched wrong, but without success.
Ideas please!
Other info: Oracle 10g, tool: PL/SQL Developer (Allround Automations).
3 days on Oracle; on SQL Server 7 years... :) {so be a bit elaborate}
Spacing of code does not work :( How do we code tags in this forum?
Published by: rajeev.ranjan on May 11, 2009 07:43XMLTABLE usage example:
SQL> ed Wrote file afiedt.buf 1 create or replace procedure get_nos(p_rc OUT sys_refcursor) is 2 testxml clob; 3 begin 4 testxml := '
'; 5 open p_rc for 6 select tt.no 7 from ( 8 select no 9 from xmltable('/table1/root/no' passing xmltype(testxml) columns no number path '/no/text()') 10 ) tt 11 group by tt.no; 12* end; SQL> / Procedure created. SQL> var rc refcursor SQL> exec get_nos(:rc); PL/SQL procedure successfully completed. SQL> print rc; NO ---------- 1 2 SQL>1 2
Maybe you are looking for
-
HP Envy 5540: blue light flashing
the printer that is connected directly to the laptop. Works very well. Now, all of a sudden, blue light flashing and will print still but at a snail's pace. What's wrong? Nothing has changed. Paper in the tray.
-
my laptop is g62 140es models, I have a problem it jst appeared now am trying to burn a CD. Unfortunately, it shows the process, like everything is ok, then finally to open the rom as the work is carried out. then when I try to listen to the probe wh
-
external speakers stopped working in windows xp svc pk 3
Hi, my system is four years old and custom built. (tour). ASUS, spin windows xp svc pk 3. I have a large and two small tweakers woofer? left and right. They are old to quit smoking, but sound as good as bose, so of course I kept it. They will work on
-
error 0 x 80070571 appears when you try to delete a file from my office exec
Maybe it's a larger problem. Using Vista - IE 8 continues to have questions, slowing down or suspended. On the automatic update (did an update last night) but even tried to do a manually and he has not left me. Tried to save the Google Chrome to m
-
Passport for blackBerry after mixture update is not connected desktop win8.1
After mixing, update the Passport, said software update required, but none is shown... was working fine before the update