PL/SQL - Call Out Ref Cursor returned by a stored procedure
Hello
I am creating a procedure where a Ref Cursor is defined as an OUT parameter, my question is how to shout that the Ref Cursor when I run for example here is how I want to call my EXEC sql command:
EXEC film_not_in_stock (2,2,vcur);
Here is the procedure:
CREATE OR REPLACE PROCEDURE film_not_in_stock (p_film_id in NUMBER, p_store_id number, vcur ON SYS_REFCURSOR)
IS
News sys_refcursor;
v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id
v_cur sys_refcursor;
BEGIN
Heart OPEN to SELECT inventory_id
INVENTORY
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_id NOT IN (SELECT inventory_in_stock (inventory_id) FROM dual);
News of FETCH in v_cur;
OUTPUT WHEN heart % NOTFOUND;
END;
/
I know there are typos in the procedure, you will appreciate if you can help me to put it right.
Thank you very much!
Tonya.
In fact, based on your previous post, function inventory_in_stock returns 0 or 1. If so, there are:
CREATE OR REPLACE
PROCEDURE film_not_in_stock)
p_film_id in NUMBERS
p_store_id in NUMBERS
p_cur ON SYS_REFCURSOR
)
IS
News sys_refcursor;
v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id
v_cur sys_refcursor;
BEGIN
OPEN p_cur
FOR
SELECT inventory_id
INVENTORY
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_in_stock (inventory_id) = 0;
News of FETCH in v_cur;
OUTPUT WHEN heart % NOTFOUND;
END;
/
SY.
Tags: Database
Similar Questions
-
How to read my ref cursor return user defined cursor type
Hello
I have the types defined as follows:
It is used as a return type in a stored procedure.TYPE MY_RECORD IS RECORD ( COL1 TABLE1.COL1%TYPE, COL2 TABLE1.COL2%TYPE ); TYPE MY_CURSOR IS REF CURSOR RETURN MY_RECORD;
I have a pl/sql block, where I make a call to MS that returns this cursor.
How to read individual values for SP?SQL> create or replace package pkg as type my_record is record (col1 emp.empno%type, col2 emp.ename%type); type my_cursor is ref cursor return my_record; procedure p (cur out my_cursor); end pkg; / Package created. SQL> create or replace package body pkg as procedure p (cur out my_cursor) as begin open cur for select empno, ename from emp where rownum <= 2; end p; end pkg; / Package body created. SQL> declare cur pkg.my_cursor; e_rec pkg.my_record; begin pkg.p (cur); loop fetch cur into e_rec; exit when cur%notfound; dbms_output.put ('Empno: ' || e_rec.col1); dbms_output.put_line ('; Ename: ' || e_rec.col2); end loop; close cur; end; / Empno: 7369; Ename: SMITH Empno: 7499; Ename: ALLEN PL/SQL procedure successfully completed.
-
Hello
I have a package that returns a Ref Cursor, in this procedure, I have a dynamic sql code that is built according to certain values, and the query is a select query, is it possible that I can put that dynamic sql in the ref cursor and return of the procedure.
Or y at - it no alternative better workaround.
Thanks in advance.
NaveenYes you can.
Try this...
create or replace package test_pack is type ref_cur is ref cursor; procedure just_print(ref_var ref_cur); end; / create or replace package body test_pack is procedure just_print(ref_var ref_cur) is l_var emp%rowtype; begin loop fetch ref_var into l_var; exit when ref_var%notfound; dbms_output.put_line(l_var.ename); end loop; end; end; / declare cur_var test_pack.ref_cur; dsql varchar2(100); begin dsql := 'select * from emp where deptno=10'; open cur_var for dsql; test_pack.just_print(cur_var); end; / CLARK KING MILLER PL/SQL procedure successfully completed. Elapsed: 00:00:00.00
Kind regards
Prazy -
Made Oracle 6i LOV with ref cursor returned by a function of database
Hi all
I want to dynamically create a LOV in oracle forms 6i using the value of ref cursor returned by the function of database.
is this possible?
Using loop, I could able to display the values returned by the ref cursor, but how can I assign these values in the LOV?
You will need to loop through your REF Cursor and assign each value to a group of registration of forms and then assign the Group Record to your LOV. Take a look at the built-ins CREATE_GROUP, ADD_GROUP_COLUMN and ADD_GROUP_ROW in the help system of forms for more information about how to use these built-ins and examples of how to use them.
Craig...
-
Get the EXIT and the RETURN of a stored procedure parameters
I have a stored procedure (SQL Server 2008 R2 MS) as in the following example.
Thanks to the connectivity of database I get OUTPUT parameters, but I can't get the game DATA RECORDS and RETURN value.
Someone knows how to do this?
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
I finally found what was wrong... He had a line in the stored procedure only aditional. It should be like this:
CREATE PROCEDURE [dbo]. [TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR (20), @STATUS INT OUTPUT, OUTPUT OF NVARCHAR (500) OF @ERRO)
AS
BEGIN
SET NOCOUNT ON; -NEW LINE!DECLARE THE TABLE @TABLE (CODE INT, DESCRIPTION VARCHAR (30))
INSERT VALUES INTO @TABLE (51, 'A')
INSERT VALUES INTO @TABLE (52, 'B')INSERT VALUES INTO @TABLE (53, 'C')
SELECT * FROM @TABLE
SET @STATUS = 1
SET @ERRO = "Nenhum erro!
RETURN 0
END
-
I have a proc as below.
Input value will be in the format 123,9092
But even if the database is set to, the da returns null
Help, please
PROCEDURE GET_HIP_MED_CENTER_DESCR (p_in_provnum in varchar2 ,p_out_HIP_MED_CENTER OUT ref_cursor)is p_provnum varchar2(100); BEGIN SELECT '''' || REPLACE(p_in_provnum,',',''',''') || '''' into p_provnum FROM DUAL; dbms_output.put_line(p_provnum); OPEN p_out_HIP_MED_CENTER FOR SELECT distinct PROVNUM,MED_CENTER FROM hip.ref_hip_med_centers where PROVNUM IN (p_provnum) AND MED_CENTER_DIPLAY is not null order by MED_CENTER asc; end;
You need the dynamic SQL statement:
PROCEDURE GET_HIP_MED_CENTER_DESCR (p_in_provnum in varchar2 ,p_out_HIP_MED_CENTER OUT ref_cursor)is p_provnum varchar2(100); BEGIN SELECT '''' || REPLACE(p_in_provnum,',',''',''') || '''' into p_provnum FROM DUAL; dbms_output.put_line(p_provnum); OPEN p_out_HIP_MED_CENTER FOR 'SELECT distinct PROVNUM,MED_CENTER FROM hip.ref_hip_med_centers where PROVNUM IN (' || p_provnum || ') AND MED_CENTER_DIPLAY is not null order by MED_CENTER asc'; end;
However, I would suggest using the collection.
SY.
-
Best approach - whether to return Collections or the Ref Cursor?
I have the table that the column is a nested table (column address) type. Now, I want to fill the same
in a jsp page.
As his collection type I am thinking to send variable Collection to front-end. And most of java professionals
argue that the collections are the best approach.
But here, in a lot of posts, I read that collections at the front end is the worst approach and it degrades performance
and increases the load.
But java assert that even if connection fails they can always display the data as the data set is with them
How to get a set of results COLLECTION.
As ref cursor is just a pointer to the real cursor lies in the comics... they're going to make one record of the other instead and once the connection is lost... they can no longer display the data. This assertion seems
to be reasonable!
How you condemn it? and prove ref Cursor is good way?
Here's the example scenario that I have with me.
Using the Collectioncreate type t_adress is object(t_h_no varchar2(500),t_pin_code number); / create type t_address_tbl is table of t_adress; / create table r_dummy (emp_name varchar2(200),emp_id number,emp_address t_address_tbl) nested table emp_address store as emp_address_tbl; insert into r_dummy values('raghu',1,t_address_tbl(t_adress('598',500035),t_adress('600',500036))) insert into r_dummy values('raghu nadh',2,t_address_tbl(t_adress('598',500035),t_adress('600',500036)))
Using Ref CursorCreate or replace procedure p_using_col ( p_emp_id in r_dummy.emp_name%type, p_emp_dtls out t_address_tbl ) is begin Select t_adress(cl.t_h_no,cl.t_pin_code) bulk collect into p_emp_dtls from r_dummy,table(emp_address) cl where emp_id = p_emp_id; end; / set serveroutput on; declare l_emp_id r_dummy.emp_name%type := 1; l_emp_dtls t_address_tbl; begin p_using_col(l_emp_id,l_emp_dtls); for i in 1..l_emp_dtls.count loop dbms_output.put_line(l_emp_dtls(i).t_h_no); end loop; end;
ConcerningCreate or replace procedure p_using_ref ( p_emp_id in r_dummy.emp_name%type, p_emp_dtls out sys_refcursor ) is begin Open p_emp_dtls for Select cl.t_h_no,cl.t_pin_code from r_dummy,table(emp_address) cl where emp_id = p_emp_id; end; / set serveroutput on; declare l_emp_id r_dummy.emp_name%type := 1; l_emp_dtls sys_refcursor; l_h_no varchar2(500); l_pin_code number; begin p_using_ref(l_emp_id,l_emp_dtls); loop fetch l_emp_dtls into l_h_no,l_pin_code; exit when l_emp_dtls%notfound; dbms_output.put_line(l_h_no||' '||l_pin_code); end loop; close l_emp_dtls; end;
RUSSORUSSO says:
I would like to know what really happens behind the screen IE in PGA... when we return collections...A collection is a PL/SQL variable. Like all PL/SQL variables, it resides in the global area of the server process that executes PL/SQL code. This memory is part of the process the process's private memory.
If need more memory, more memory server be malloc' ed by the process.
As he is dedicated and private memory, no other process can reap the benefits of this memory in use. It is not 'ideal' - shared memory however benefits all the processes that are involved in sharing that allocated the memory. As is the case with the SGA
How long my set of data will reside in the PGA? He immediately fade after returning to the calling procedure? and how it degrades performance. Help me with a good link.
Assume that you create a collection of 10 MB. The process server malloc' ed 10 MB of server memory. The PGA has thus extended.
When your code executes the variable usage (it is out of reach of runtime), the PL/SQL engine can theoretically free up 10 MB of memory. However, it may have allocated 4 KB memory after this assignment of 10 MB. Only 4 KB is still in use. This moment results in that the process cannot shrink its allocated memory - as this free piece of 10 MB is slapbang in the middle of the used memory space.
PGA memory is 'expensive' because it's not shared memory is private, with only the current process. PGA in memory is not so easy to decline. Memory management is a complex issue and you who ceases to use a large part of the PGA memory almost never means that this memory suddenly become free and available for other processes to use.
Also, you have to ask yourself why you want to copy data from disk blocks into the SGA buffer (for SQL procedures) cache, then copy these data blocks of APG in the PGA (using a collection and extraction in bulk) and then copy this PGA memory on the network to the client process (TOAD or .net or Java or whatever).
It's a lot of moving parts - which increases the complexity, lowers the performance and scalability and ups the risk of something going wrong due to the increased complexity.
It is much simpler and much stronger, to maintain the number of moving parts to a minimum. For example to copy data directly from cache buffers of the SGA to the customer via a ref cursor
-
REP-0737: must be a function of return type 'ref cursor.
Hi all
I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.
Here is my code
function QR_1RefCurDS return sys_refcursor is My_Cur Sys_Refcursor; begin Open My_Cur for select * from scott.emp order by deptno; return My_Cur end;
fate of the screen.
Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.
However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.
So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.
The predefined SYS_REFCURSOR type is introduced in Oracle 9i.
Use this:
PACKAGE test_rc IS
TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;
END;
FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS
test_rc.rc_type RC;
BEGIN
OPEN the RC to SELECT * FROM emp;
RETURN rc;
END;
Kind regards
Zlatko
-
The stored procedure PL/SQL - t - it accept the custom Ref Cursor type?
I am not able to compile the following procedure in the HR schema comes with default oracle... I use Oracle 11g Release 11.2.0.2.0 Express edition. It gives me an error (given after the code block):
Block of code:
CREATE OR REPLACE PROCEDURE TEST_REF IS
DECLARE
TYPE REF_EMP IS REF CURSOR RETURN % ROWTYPE EMPLOYEES;
RF_EMP REF_EMP;
V_EMP EMPLOYEES % ROWTYPE;
BEGIN
DBMS_OUTPUT. ENABLE (1000000);
OPEN FOR RF_EMP
SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
EXTRACT THE RF_EMP IN V_EMP;
DBMS_OUTPUT. PUT_LINE (V_EMP. FIRST_NAME. ' ' || V_EMP. LAST_NAME);
CLOSE RF_EMP;
EXCEPTION
WHILE OTHERS
THEN DBMS_OUTPUT. PUT_LINE (SQLERRM);
END TEST_REF;
/
Error:
Errors in PROCEDURE TEST_REF:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1 PLS-00103: encountered the symbol "DECLARE" when waiting for an a
What follows:
Start function < an ID > pragma procedure subtype type
< between double quote delimited identifiers > delete the current cursor
There are the external language prior
The symbol 'start' is substituted for 'DECLARE' continue.
16/13 PLS-00103: encountered the symbol "end-of-file" when waiting for him
one of the following values:
(begin case declare exit end exception for goto if loop mod)
pragma raise return null select update while withGet rid of the DECLARED:
SQL> CREATE OR REPLACE PROCEDURE TEST_REF IS 2 TYPE REF_EMP IS REF CURSOR RETURN HR.EMPLOYEES%ROWTYPE; 3 RF_EMP REF_EMP; 4 V_EMP EMPLOYEES%ROWTYPE; 5 BEGIN 6 DBMS_OUTPUT.ENABLE(1000000); 7 OPEN RF_EMP FOR 8 SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100; 9 FETCH RF_EMP INTO V_EMP; 10 DBMS_OUTPUT.PUT_LINE(V_EMP.FIRST_NAME || ' ' || V_EMP.LAST_NAME); 11 CLOSE RF_EMP; 12 EXCEPTION 13 WHEN OTHERS 14 THEN DBMS_OUTPUT.PUT_LINE(SQLERRM); 15 END TEST_REF; 16 / Procedure created. SQL> set serveroutput on SQL> exec TEST_REF; Donald OConnell PL/SQL procedure successfully completed. SQL>
SY.
-
Return of the ref cursor of procedure where the cursor is defined in the specification
Hello
Here's pseudo-code
create or replace package test
as
cursor c_emp (number cv_emp_id)
is
Select emp_name emp where emp_id = cv_emp_id;
type ref_c is ref cursor;
function get_emp_name (number p_emp_id) return ref_c;
end test;
/
create or replace the test physics package
as
ref_c function get_emp_name (number p_emp_id)
is
ret_val ref_c;
Start
Open c_emp (p_emp_id);
ret_val: = c_emp;
return ret_val;
end get_emp_name;
end test;
/
Returns me "PLS-00382: expression is of the wrong type. I tried to use a strongly typed Ref cursor based on the cursor, but nothing helped.
Clearly, I understand something... and if I can't assign as ' ret_val: = c_emp "and if there is another key way it so please let me know.
Thank you
Ralph
Published by: user13024707 on May 5, 2010 04:43user13024707 wrote:
Clearly the point of my question is being missed.Or maybe the question is not been clearly asked. ;)
I want to set the cursor in the PACKAGE SPECIFICATION, and not in the package body. The issue of the bind variable and the string is neither here nor there because I pass parameters to the cursor.
What you ask is to use a PL/SQL cursor (defined in the specifications of the package or elsewhere) and that convert a Ref Cursor. N ° cannot be done.
PL/SQL cursors should be used in the PL/SQL code. REF CURSOR is primary used to pass back a reference to a cursor (and all queries are cursors) to a layer of application outside of PL/SQL for example .net, java, etc.. Once you start using the ref Cursor only really, you have the choice of opening it based on a (dynamic) or a fixed query string as in the examples given. You cannot open a cursor of a PL/SQL cursor definition Ref.The difference is that when you do:
CURSOR cur_mycursor IS SELECT ...
you declare a cursor in pl/sql definition, not actually a slider itself. The cursor itself is created when you issue an OPENING or a statement FOR etc. So a Ref Cursor (reference to a slider) cannot refer to the definition of the cursor because it is only a definition, not a cursor (i.e. it has not been sent engine sql and instantiated at that time here). Instead the Ref Cursor must reference a cursor (query), itself, and that may be presented as a string or as the query itself that is issued against the sql engine and then the ref cursor points
Thus, slider ref and PL/SQL cursors are different concepts, both designed to manage cursors in a slightly different way of programming. You cannot mix them.
-
REF CURSOR - re using in different blocks of sql pl
Hello
I do not understand how different pl/sql blocks accesses the same cursor variable.
Looks like the ref cursor is filled in one procedure, so how can it be visible to the other blocks?
Thanks a lot for your help.
JBM.Ooops,
I missed you speak from cursor variable. In this case, you declare on client-side and use it as a bind variable. For example, if your SQL client tool * the more you use the VARIABLE command:
SQL> variable g_emp_cur refcursor SQL> begin 2 open :g_emp_cur for 'select ename from emp'; 3 end; 4 / PL/SQL procedure successfully completed. SQL> declare 2 v_ename varchar2(20); 3 begin 4 fetch :g_emp_cur into v_ename; 5 dbms_output.put_line(v_ename); 6 end; 7 / SMITH PL/SQL procedure successfully completed. SQL> begin 2 close :g_emp_cur; 3 end; 4 / PL/SQL procedure successfully completed. SQL>
SY.
-
using plsql table and ref cursor in oracle's 10 g
Hi all
Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.
And in this process, I created a pl/sql table and a Ref cursor at the database level.
CREATE OR REPLACE PACKAGE SCOTT. TYPE BONUS_PKG IS bonus_rec
IS (RECORD
EmpNo bonus_EMP.empno%TYPE,
Ename bonus_EMP.ename%TYPE,
employment bonus_EMP.job%TYPE,
SAL bonus_EMP.sal%TYPE,
Comm bonus_EMP.comm%TYPE);
TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
TYPE bontab IS TABLE OF bonus_rec INDEX DIRECTORY.
PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor);
PROCEDURE bonus_query (bonus_data IN OUT bontab);
END bonus_pkg;
CREATE OR REPLACE PACKAGE BODY SCOTT. BONUS_PKG IS
PROCEDURE bonus_query (bonus_data IN OUT bontab) IS
II NUMBER;
CURSOR bonselect IS
SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
BEGIN
OPEN bonselect.
II: = 1;
LOOP
Look FOR bonselect IN
.EmpNo bonus_data (ii),
.ename bonus_data (ii),
.job bonus_data (ii),
.Sal bonus_data (ii),
.comm bonus_data (ii);
EXIT WHEN bonselect % NOTFOUND;
II: = ii + 1;
END LOOP;
END bonus_query;
PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor) IS
BEGIN
Bonus_data OPEN to SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
END bonus_refcur;
END bonus_pkg;
I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.
Please answer...Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.
In general, you will use a block of proceedings based when you have a collection of data from several tables presented in a form and your username must be able to update the information displayed.
In your sample code, looks like you are using Oracle Support document "Melting a block on a Stored Procedure - examples of Code [ID 66887.1]". If this is the case, continue to follow the document - it guides you through all the steps. There is no need to manually configure things that the data block Wizard will work for you!
I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.
Why? Let the wizard block configuration data of your block based on a procedure for you. There is no need to manually browse the data! I did what you're trying, and it's more work needed. Leave forms to do the work for you. :)
If you absolutely have to do things manually, I recommend that you use the PROCEDURE bonus_query (bonus_data IN OUT bontab) instead of bonus_refcur (bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB, and then call the bonus_query procedure. Then, it's a simple case of a loop in the table of records returned by the bonus_query procedure. For example:
DECLARE t_bonus bonus_pkb.bontab; BEGIN bonus_pkg.bonus_query(t_bonus); FOR i in 1 .. t_bonus.count LOOP :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno; :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename; :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job; :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal; :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm; END LOOP; END;
This code example shows the basics, but as is the sample code - you will need to adapt to your situation.
Also, I highly recommend that you look at the article inol listed. It is a very thorough debate on the REF CURSOR. If you have set up using a procedure based on the data source - it is more effective to spend the record table to your form that it must pass a ref cursor Using a ref cursor, you might as well just using a standard called cursor and loops on your named cursor. The effect is the same (a line returned at the same time creating lots of network traffic). Using the table of records is more efficient because the data set is returned if the network traffic is reduced.
Hope this helps,
Craig B-)If someone useful or appropriate, please mark accordingly.
-
How to start the view off of the ref cursor Oracle as input/output param
Hello world
We use JDev 11.1.2.3 WL 10.3.6 and Java 7.
We are at the beginning of our transition from Oracle Forms to ADF. We have a very large forms that uses many store procedures that have IN/OUT ref Cursor parameters and tables plsql. I tried to find information on best practices to achieve, but only seemed to find tutorials on SEO of the Oracle ref Cursor return functions. I hope we don't have to rewrite our code of database to work with ADF.
This is an example of a proc currently a block on a form based on directly
The ref cursor parameter is input/output to satisfy the way the form handles this type of paradigm.
ADF we want I hope to reuse these procs existing (without the need to wrap/overload them) on the basis of the display objects.
Example:
/ * my record type which houses the information I want to go back * /.
TYPE rec_hist_vacpac_status IS RECORD)
rec_order NUMBER (5),
rec_rownum NUMBER (5),
return_column SAM_VACPAC.vacpac_status%TYPE,
rec_login_id SAM_VACPAC.ins_user%TYPE,
status_date SAM_VACPAC.status_date%TYPE
);
/ * Sets the ref cursor type * /.
TYPE lcur_hist_vacpac_status IS REF CURSOR;
/ * This is a procedure that would take some info link go / return
Return the ref cursor of this information as an in / out * /.
PROCEDURE prc_myinfo_refcur)
pnum_identify_seq_id in NUMBERS
pcur_myinfo IN OUT lcur_hist_vacpac_status);
Can anyone point me in the right direction on documentation on this?
Thank you!
Hi Cemerson:
See this example:
- 1. create a TYPE as an object
CREATE OR REPLACE
TYPE GOTYOB_EQUI
AS AN OBJECT
(
CDELEM VARCHAR2 (50).
TIELEM VARCHAR2 (2)
);
- 2. create a TABLE TYPE AS
CREATE OR REPLACE
TYPE GOTYTA_EQUI
AS THE GOTYOB_EQUI TABLE;
- 3 create a function, it returns the TYPE of the TABLE
FUNCTION fn_equiposarriba)
pa_cdelem IN VARCHAR2,
pa_nucomp in NUMBERS
pa_anperi in NUMBERS
pa_meperi in NUMBERS
)
Gotyta_equi RETURN PIPELINED IS
CURSOR trae_equimani (va_cdelem VARCHAR2) IS
SELECT cdelem, tielem, cdelempadr,
(SELECT cdequi
Of evm_alim
WHERE anperi = eq.anperi
AND meperi = eq.meperi
AND nucomp = eq.nucomp
AND cdalim = eq.cdalim) cdalim
Of evm_equimani eq
WHERE anperi = pa_anperi
AND meperi = pa_meperi
AND nucomp = pa_nucomp
AND cdelem = va_cdelem
AND cdelempadr <> cdelem
AND tielem <> 'A ';
equimani trae_equimani % ROWTYPE;
va_cdalim VARCHAR2 (100);
BEGIN
-Loading los equipos aguas arriba
WHILE equimani.cdelempadr IS NOT NULL LOOP
OPEN trae_equimani (equimani.cdelempadr);
equimani: = NULL;
SEEK trae_equimani INTO equimani;
CLOSE Trae_equimani;
IF equimani.cdelem IS NOT NULL THEN
PIPE ROW (gotyob_equi (equimani.cdelem, equimani.tielem));
END IF;
END LOOP;
RETURN;
END;
- 4 SQL Query with the help of the function... you can use this SQL in a display object
SELECT
*
Of
TABLE (gopq_eventos.fn_equiposarriba (' F-SCZ-043-103', '))
1,
2013,
6
)
)
Best regards, Marcelo
-
Hello
Here is the plsql code, I try to extract the data from the refcursor
Declare
number of l_ecg_id_in;
number of l_error_code_out;
l_cur_out sys_refcursor;
Begin
l_ecg_id_in: = 1249551;
-Call the procedure
pkg_dispatch.sp_getecgreport (p_ecg_id_in = > l_ecg_id_in,)
p_cur_out = > l_cur_out, / / p_cur_out is back refcursor datat
p_error_code_out = > l_error_code_out);
Now my requirement is data retrieves in l_cur_out have too many columns, the columns are mentioned below.
HUMAN RESOURCES
PR
DR
BATTERY
ETC.
I want to just HR to be extacted in a variable or a collection of type
We can extract a particular of ref cursor column, please suggest me
End;Sudhir_Bangalore wrote:
Now my requirement is data retrieves in l_cur_out have too many columns, the columns are mentioned below.
HUMAN RESOURCES
PR
DR
BATTERY
ETC.I want to just HR to be extacted in a variable or a collection of type
Then, you use the wrong cursor and you performance degradation because the cursor returns data that is not required.
We can extract a particular of ref cursor column, please suggest me
You can not.
Workaround would be to copy the handle of the cursor ref to a handle to the cursor DBMS_SQL and then use cursor DBMS_SQL to treat the projection of SQL. But it would be an ugly hack.
The right approach would be to correctly use the SQL cursors in PL/SQL. And no, ref Cursor in PL/SQL (created by code PL/SQL to PL/SQL code) is almost always the WRONG choice.
There are better native cursor data types in PL/SQL in particular supported cursors created by PL/SQL and PL/SQL.
REF CURSOR is provided mainly as the cursors created by PL/SQL for an external client. There are very few reasons to create Ref cursors to use PL/SQL code.
-
Hi all
We have a defined as Ref Cursor.
CREATE or REPLACE procedure Pspdetails_proc (supplier_id in varchar2, supplier_partno in varchar2)
as
type rc is REF CURSOR;
l_cursor rc;
l_query varchar2 (512)
by default ' SELECT C2. N ° supplier, C2. SupplierPartNumber, Lon1.lse_Index, Lon1.lse_String
C2PlantSpecificPricingTab C2, Lon1 LongStringElementTab
WHERE C2.ls_Strings = Lon1.lvId AND C2.rootId = Lon1.rootId
AND (C2. Active = 1) AND (C2. PurgeState = 0)';
cursor l_template is SELECT C2. N ° supplier, C2. SupplierPartNumber, Lon1.lse_Index, Lon1.lse_String
CVXPlantSpecificPricingTab C2, Lon1 LongStringElementTab
WHERE C2.ls_Strings = Lon1.lvId AND C2.rootId = Lon1.rootId AND (C2. Active = 1) AND (C2. PurgeState = 0);
l_rec l_template % rowtype;
BEGIN
If (supplier_id isn't supplier_partno NULL AND IS NOT NULL) then
l_query: = l_query | "AND C2. SupplierID = "' | supplier_id | " ' AND C2. SUPPLIERPARTNUMBER = "' | supplier_partno | " ' ;
end if;
dbms_output. Put_line (l_query);
Open the l_cursor for l_query;
loop
extract the l_cursor in l_rec;
When the output l_cursor % notfound;
dbms_output. Put_line (l_rec.lse_String);
end loop;
close l_cursor;
end;
/
What should be the approach in case I want to return the value "l_rec.lse_String" of the piece of code above OR propose a different approach.
Thank you very much in advance.What should be the approach in case I want to return the value "l_rec.lse_String" of the coin above the cod
You can introduce an output parameter.
In addition you don't need all this dynamic sql: a simplified version would becreate or replace procedure pspdetails_proc ( supplier_id in varchar2, supplier_partno in varchar2, lse_string out varchar2) as begin if supplier_id is not null and supplier_partno is not null then select max (lon1.lse_string) into lse_string from c2plantspecificpricingtab c2, longstringelementtab lon1 where c2.ls_strings = lon1.lvid and c2.rootid = lon1.rootid and (c2.active = 1) and (c2.purgestate = 0) and c2.supplierid = supplier_id and c2.supplierpartnumber = supplier_partno; else select max (lon1.lse_string) into lse_string from c2plantspecificpricingtab c2, longstringelementtab lon1 where c2.ls_strings = lon1.lvid and c2.rootid = lon1.rootid and c2.active = 1 and c2.purgestate = 0; end if; end pspdetails_proc; /
Maybe you are looking for
-
My button for Firefox on Windows7 disappearing task bar when I open Firefox which allows to open several windows a pain. How can I keep always a button on the taskbar? Explore the fact. Thank you people.
-
When I used to go on Facebook, I could print things. At the top left of the screen was file, I think that it was. Click on, then comes print and print preview. He's gone now, and I can't get it back. Why do you change these things?
-
IM using a probook 4530 s. It worked fine a few hours ago, until now. It gets stuck to the screen... with nothing else than the "windows 7 Home premium' down... It usually takes about 10 seconds after that. The pointer still works and I can activate
-
Download this warning "caution 1 importer of Type libraries detected an accessor property 'sessionPlaylistCount' Get the type"WMPLib.IWMPNowPlayingHelperDispatch"without a valid return type." The importer will try to import this property as a method
-
Could someone how looks to the Middle East from Adobe photoshop cs version 6 for mac or box dvd cover and what to check on the sticker on the dvd box