Fetch Refcursor into a GTT
Hello All,
I have a procedure
PROCEDURE get_tran_detail (
i_user_id IN NUMBER := 0,
i_portfolio_id_list IN NUM_ARRAY,
i_from_dt IN transaction.trade_dt%TYPE,
i_to_dt IN transaction.trade_dt%TYPE,
i_include_suppress_txn IN NUMBER,
o_transactions OUT TXN_SUMMARY_INFO_ARRAY_test, ----output
i_debugmode IN NUMBER := 0
How do I get the o_transactions to be inserted into a GTT?
This is what I have so far
CREATE OR REPLACE PROCEDURE get_control_ref_cursor( p_ref_cursor OUT SYS_REFCURSOR )
AS
l_base_proc_ref_cursor SYS_REFCURSOR;
l_result_rec MI_GET_TXN_GTT%rowtype;
BEGIN
mi_ade_service_pkg_test.get_tran_detail (
118
,num_array(7366975,7366976,7364727) --portfolio_id
,'22-aug-2011' --transaction_date
,sysdate
,1
,o_transactions
,0);
LOOP
FETCH l_base_proc_ref_cursor INTO l_result_rec;
INSERT INTO MI_GET_TXN_GTT VALUES( l_result_rec );
OPEN p_ref_cursor
FOR SELECT *
FROM MI_GET_TXN_GTT;
END;
Error:
LINE/COL ERROR
23/4 PLS-00103: Encountered the symbol ";" when expecting one of the
following:
loop
Thanks
>
How do I get the o_transactions to be inserted into a GTT?
>
Easy - DON'T DO THAT!
Why do you want to put the data into a GTT when all you do is then create a cursor on the data.
Just return the data in o_transactions directly the the caller.
Post the DDL for the objects you are using.
Here is a simple example you can try in the SCOTT schema. It uses a VARRAY and just queries it as a table.
CREATE OR REPLACE TYPE enamelist as VARRAY(20) of VARCHAR2(20)
CREATE OR REPLACE FUNCTION ename_fn
RETURN enamelist
AS
v_cursor_main enamelist := enamelist ();
BEGIN
SELECT ename
BULK COLLECT
INTO v_cursor_main
FROM emp;
RETURN v_cursor_main;
EXCEPTION
WHEN OTHERS
THEN
RETURN v_cursor_main;
END;
select * from table(ename_fn());
COLUMN_VALUE
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLERFor your use case you have
o_transactions OUT TXN_SUMMARY_INFO_ARRAY_testIf that 'ARRAY' is a VARRAY then you would just open the cursor on 'o_transactions'
OPEN p_ref_cursor
FOR SELECT * FROM TABLE(o_transactions);Get rid of the GTT.
CREATE OR REPLACE PROCEDURE get_control_ref_cursor( p_ref_cursor OUT SYS_REFCURSOR )
AS
l_base_proc_ref_cursor SYS_REFCURSOR;
v_cursor_main enamelist := enamelist ();
BEGIN
SELECT ename
BULK COLLECT
INTO v_cursor_main
FROM emp;
OPEN p_ref_cursor
FOR SELECT * FROM TABLE(v_cursor_main);
END;
SQL> var emp_dtls refcursor
SQL> execute get_control_ref_cursor(:emp_dtls);
PL/SQL procedure successfully completed.
SQL> print emp_dtls;
COLUMN_VALUE
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
COLUMN_VALUE
JAMES
FORD
MILLER
14 rows selected.
SQL>
Similar Messages
-
Error while fetching data into collection type.
Hi all,
I'm facing a problem while i'm fetching data into a table type.
Open c1;
open c2;
loop
Fetch c1 into partition_name_1;
fetch c2 into partition_name_2;
exit when c1%notfound or c2%notfound;
open C1_refcursor for 'select a.col1,b.col2 from table1 partition('||partition_name_1||') a, table2 partition('||partition_name_2) b
where a.col2=b.col2';
loop
fetch c1_refcursor BULK COLLECT into v1,v2 <-----This is the line where i'm getting the error as "ORA-01858: a non-numeric character was found where a numeric was expected"
limit 100000;
exit when v1.count=0;
forall i in 1..v1.count
end loop;
i also checked the data type of the table variable its same as the column selected in the refcursor.
Please help me out.
Message was edited by:
Sumit NarayanOk I see that, but I don't think you can use associative arrays in this manner then, because you cannot select data directly into an associative_array.
As far as I'm aware, they must be assigned an index and the error suggests to me that its missing an index.
You can select directly into records and maybe this is where you need to go. -
I have a form on a table containing a CLOB column. The form renders it using a "HTML Editor" item type. On another page, this is fetched into a "Display as Text" item using select clob_col into :P1_ITEM from t where ... When this is run, I get the 'character/string buffer too small' when dbms_log.getlength(clob_col) > 4000. I guess this is because the SQL engine cannot handle strings larger than 4000. I thought Apex would bind CLOB columns for select...into but looks like it binds a varchar2 and hence the 4000 limit.
What is the best way to handle this? ThanksHello Vikas,
Please check the following, as it might be helpful
http://www.danielmcghan.us/2010/02/ckeditor-and-those-pesky-clobs.html
I’m using Carl’s AJAX functions to save/fetch CLOB into/from a collection, and it works very well.
Hope this helps,
Arie.
♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
♦ Author of Oracle Application Express 3.2 – The Essentials and More -
Difference of fetching data, into a cursor variable and into a record?
whats the difference of fetching data via cursor, into a cursor variable and into a record.
i feel infact fetching data into cursor variable is more better, and plus lesser lines to code??Can you explain what you mean, preferably with an example? Generally, you fetch data from a cursor, not into one. I'm assuming by "fetching into a record" you mean inserting into a table?
Justin -
How to fetch data into my custom script configured in qc02 transaction
Hi All,
I configured the custom SAP-Script in place of standard script name in QC02 tcode.In my requirement when I execute QC22
transaction the custom script will be triggered along with some data based on material number,batch number and plant.I need to fetch QALS-KTEXTMAT , QALS-CHARG, MCH1-HSDAT and MCH1-VFDAT.Please help me how to fetch this data.Any Enahancement need to use or any spot is there Please specify.
Thanks in advance.
Regards,
Satya.
Edited by: satyareddygade on Sep 8, 2011 2:13 PMHi Satya,
Try like this in your Script window text element.
/: PERFORM FETCH_KTEXTMAT IN PROGRAM <Z Subroutine Pool program>
/: USING &QALS-PRUEFLOS&
/: CHANGING &GV_KTEXTMAT&
/: ENDPERFORM
in Z Subroutine Pool program
FORM fetch_ktextmat TABLES intab STRUCTURE itcsy
outtab STRUCTURE itcsy.
DATA:
lv_prueflos TYPE qals-prueflos,
lv_ktextmat TYPE qals-ktextmat.
*---Get Inspection Lot Number
READ TABLE intab WITH KEY 'QALS-PRUEFLOS'.
CHECK sy-subrc = 0.
lv_prueflos = intab-value.
SELECT SINGLE ktextmat FROM qals INTO lv_ktextmat WHERE prueflos EQ lv_prueflos.
outtab-value = lv_ktextmat.
MODIFY outtab FROM outtab TRANSPORTING value WHERE
name = 'GV_KTEXTMAT'.
CLEAR : intab,outtab.
ENDFORM. "FETCH_KTEXTMAT
/: PERFORM FETCH_HSDAT IN PROGRAM <Z Subroutine Pool program>
/: USING &*VBDPL-MATNR&
/: USING &VBDPL-CHARG&
/: CHANGING &GV_HSDAT&
FORM fetch_hsdat TABLES intab STRUCTURE itcsy
outtab STRUCTURE itcsy.
DATA:
lv_matnr TYPE vbdpl-matnr,
lv_charg TYPE vbdpl-charg,
lv_hsdat TYPE mch1-hsdat.
*---Get Material Number
READ TABLE intab WITH KEY '*VBDPL-MATNR'.
CHECK sy-subrc = 0.
lv_matnr = intab-value.
*---Get Batch Number
READ TABLE intab WITH KEY 'VBDPL-CHARG'.
CHECK sy-subrc = 0.
lv_charg = intab-value.
SELECT SINGLE hsdat FROM mch1 INTO lv_hsdat WHERE matnr EQ lv_matnr
AND charg EQ lv_charg.
outtab-value = lv_hsdat.
MODIFY outtab FROM outtab TRANSPORTING value WHERE
name = 'GV_HSDAT'.
CLEAR : intab,outtab.
ENDFORM. "FETCH_HSDAT
Use the following program symbols where you want to print.
&GV_KTEXTMAT& &QALS-CHARG& &GV_HSDAT& and &MCH1-VFDAT&
Regards,
Surya. -
Fetching data into a data grid or data table
Post Author: Mohd. Amir
CA Forum: .NET
I want to fetch data from ci_appobjects into my web page. How can I do it???
Data is like number of universes present in the repository, etcPost Author: Argan
CA Forum: .NET
query for the object you want then response.write out each property bag. -
hi all
I'm OCCI newbie, I want to fetch many column of unknow type into buffer
(eg: "select * from table ").
how to do ? thanksHi,
you have to deal with OCCI Metadata. To start look here
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14294/metadata.htm#BABFEDDJ
Regards,
Michael -
Diference bte fetch into statement fetch bulkcollect into statement.
hi,,
difference btw fetch into statement and bulk collect into statement.
differece btw for loop and forall loop.Hi,
Syntax:
(Select)(Fetch)(execute immediate) … BULK COLLECT Into collection_name [,collection_name, …] [LIMIT max_lines] ;
LIMIT is used to limit the number of rows returned.
BULK COLLECT can also be used to retrieve the result of a DML statement that uses the RETURNING INTO clause:
SQL> Declare
2 TYPE TYP_TAB_EMPNO IS TABLE OF EMP.EMPNO%Type ;
3 TYPE TYP_TAB_NOM IS TABLE OF EMP.ENAME%Type ;
4 Temp_no TYP_TAB_EMPNO ;
5 Tnoms TYP_TAB_NOM ;
6 Begin
7 -- Delete rows and return the result into the collection --
8 Delete From EMP where sal > 3000
9 RETURNING empno, ename BULK COLLECT INTO Temp_no, Tnoms ;
10 For i in Temp_no.first..Temp_no.last Loop
11 dbms_output.put_line( 'Fired employee : ' || To_char( Temp_no(i) ) || ' ' || Tnoms(i) ) ;
12 End loop ;
13 End ;
14 /
Fired employee : 7839 KING
try to understand this example.i think it is sufficient.
Thanks,
Sanjeev. -
Fetch data into internal table
Hi all,
I want to fetch all the opbel records from erdk table into an intrnal table.
Only opbel records.There are 100000000 records in erdk table.
How can I fetch into internal table ? what statement can I use to fetch the data faster keepin performance into consideration ?
Many thanksHi,
As far as data fetch is concerned you do the same as follows:
Select * from erdk into table itab
where..... < Your Where Condition if any>.
But as the number of records are very high, first try to put all the primary keys in the where clause and also if possible, try to narrow down the selection criteria by fetching data from some other table or widening the conditions in where clause.
Also try to fetch only thode fields which you actually need.
else your program will give performance problems.
Hope this helps!
Regards,
Lalit -
Regarding fetching data into internal table from D.B Tables, D.B View
Hi All,
I Have following 5 tables in my Database.
LTAP
TABNAME
FIELDNAME
KEYFLAG
LTAP
MANDT
X
LTAP
LGNUM
X
LTAP
TANUM
X
LTAP
TAPOS
X
LTAP
VLPLA
Z0MNH
TABNAME
FIELDNAME
KEYFLAG
Z0MNH
MANDT
X
Z0MNH
WERKS
X
Z0MNH
ZMANNO
X
Z0MNH
LGNUM
X
Z0MNH
AENAM
Z0MNH
BUDAT
Z0MNH
CPUTM
Z0MNH
LAEDA
Z0MNH
STATUS
Z0MNH
USNAM
Z0MNH
ZARDAT
Z0MNH
ZARTIM
Z0MNH
ZCLDAT
Z0MNH
ZCLTIM
Z0MNH
ZDPDAT
Z0MNH
ZDPTIM
Z0MNH
ZDRIVR
Z0MNH
ZINDAT
Z0MNH
ZINTIM
Z0MNH
ZLOAD
Z0MNH
ZNOTES
Z0MNH
ZPRDAT
Z0MNH
ZPRTIM
Z0MNH
ZSUPR
Z0MNH
ZTRAILR
Z3MANBOXIDHDR
TABNAME
FIELDNAME
KEYFLAG
Z3MANBOXIDHDR
MANDT
X
Z3MANBOXIDHDR
WERKS
X
Z3MANBOXIDHDR
ZMANNO
X
Z3MANBOXIDHDR
EXIDV
X
Z3MANBOXIDHDR
NLPLA
Z3MANBOXIDHDR
NLTYP
Z3MANBOXIDHDR
VLTYP
Z3MANBOXIDHDR
Z0PAL
Z3MANBOXIDHDR
Z3COMENT
Z3MANBOXIDHDR
Z3RECPT_FLAG
Z3MANBOXIDITM
TABNAME
FIELDNAME
KEYFLAG
Z3MANBOXIDITM
MANDT
X
Z3MANBOXIDITM
WERKS
X
Z3MANBOXIDITM
ZMANNO
X
Z3MANBOXIDITM
EXIDV
X
Z3MANBOXIDITM
ITEM_NO
Z3MANBOXIDITM
MATNR
Z3MANBOXIDITM
VEMEH
Z3MANBOXIDITM
VEMNG
Z3MANBOXIDITM
Z_CARTON
Z3MANBOXIDSERIAL
TABNAME
FIELDNAME
KEYFLAG
Z3MANBOXIDSERIAL
MANDT
X
Z3MANBOXIDSERIAL
WERKS
X
Z3MANBOXIDSERIAL
EXIDV
X
Z3MANBOXIDSERIAL
ZMANNO
X
Z3MANBOXIDSERIAL
ITEM_NO
Z3MANBOXIDSERIAL
SERNR
Based on all the above tables i need to fill in below internal table field as given below:
<b>Internal Table I_TAB
ZMANNO
LGNUM
WERKS
EXIDV
ITEM_NO
MATNR
SERNR
VEMNG
VEMEH
VLTYP
NLTYP
VLPLA
NLPLA
ZLOAD
USNAM
STATUS
BUDAT
CPUTM
ZINDAT
ZINTIM
ZARDAT
ZARTIM
ZCLDAT
ZCLTIM</b>
Extract data from Manifest header <b>Z0MNH, Z3MANBOXIDHDR,
Z3MANBOXIDITM, Z3MANBOXIDSER and LTAP</b> tables based on selection parameter.
Selection Screen will have folowing Select-option fields-
<b>LGNUM
WERKS
ZMANNO
USNAM
ZLOAD
EXIDV
MATNR
SERNR
VLTYP
NLTYP
VLPLA
NLPLA
BUDAT
ZINDAT
ZARDAT
ZCLDAT</b>
Based on above selection criteria i need to fetch above internal table fields data.
Then need to Move corresponding header and item data in ITAB_RESULT internal table.
I need to fetch above fields based on above 5 tables and put in final Internal Table.
Can anybody tell me the logic how can i write the same.
Also can anybody tell me i am trying to create a DataBaseView for
Z0MNH, Z3MANBOXIDHDR, Z3MANBOXIDITM, Z3MANBOXIDSERIAL and LTAP tables.
<b>Note:
1. Z3MANBOXIDITM table may contain multiple material[MATNR] for same box-id[EXIDV] (with another line item).
2. Z3MANBOXIDSERIAL table may contain multiple record for one box id[EXIDV]+item_no[ITEM_NO].</b>
But what are the <b>TABLE/JOIN Conditions</b> i need to write while creating <b>DB View</b> for above <b>5</b> tables.
Can anybody solve above 2 issues!
Thanks in advance.
Thanks,
Deep.Hi Deep,
While creation of DB view just make sure abt the key relation between the tables. Based on that u can join the tables...First fetch the data from header table then by using for all entries u can fetch the line items data.
Hope this helps you. Reply for queries, shall post the updates.
Regards.
Kumar. -
How to fetch data into xml file trom sql table.
Hi,
We r now working in oracle 9iAS portal.
We have installed xdk along with 9iAS.
I would like to know how to and where to run an xsql file,preferably with an example to fetch data from a database table to a xml file.Please download the latest version of XDK for Java at:
http://otn.oracle.com/tech/xml/xdk_java
In the downloaded package, there are demos for XSQL Servlet. The demo "emp" and "empdept" are good start. -
How to Fetch Data into internal table column wise?
The internal table contains huge set of data. Normally we fetch the data row wise using insert and select statements in work area.
But, the requirement is on fetching the data column wise for each field from the database.
So,can anyone help me on this issue for fetching the data column wise?Welcome to SDN.
What you want to do(if I understand correctly) is not possible with the statements available to us. You could do it, but I think it would be a lot of code and I don't think that its worth it. Why exactly do you want to do this?
Regards,
Rich Heilman -
Hello Friends,
In client proxy ,We have to fetch data from R/3 By executing the report in the Integration server.
But How the data is fetched from R/3 to XI ..By simply execting the Report.Hi Satya,
The report is written in the application system (R/3).When you execute the report in SE38, it automatically triggers the proxy.
once u execute the report ..the method execute_asynchronous ( in case of asynchronous scenario) will be called ..and the required data will be sent to XI.
Before going for Proxy scenarios you need to perform basic steps in application server(R3)...
Also, you need to set up a HTTP connection with XI and thus we are able to see IR objects for Proxy generation..
The following blogs will help you:
/people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
Client Proxy:
/people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy
Activation of ABAP Proxies:
/people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
coding ABAP Proxies /people/sravya.talanki2/blog/2006/07/28/smarter-approach-for-coding-abap-proxies
Communication between SAP System & Webservice Using Proxies
/people/siva.maranani/blog/2005/05/23/communication-between-sap-system-webservice-using-proxies
I have worked on Proxies, so if you have any question, please feel free to ask. -
Using dynamic value in procedure on column
I want a PL/sql procedure to select the data from the column dynamically into a variable .
My friend suggested its not possible in PL/sql ,its only possible in sql .
What i want is when i execute the PL/sql procedure the a_1 must get the value of the data in the table,i do not want to use execute immediate in pl/sql.
I create a table A
create table A (a1 number,a2 number,a3 number);
insert into a values (1,2,3);
then i create a procedure
create or replace
procedure test_a (var IN number)
as
a_1 number;
i number;
z varchar2(5);
begin
if var=1
then
i:=1;
elsif var = 2
then
i:=2;
z:='A2';
end if;
SELECT 'a'||i into a_1 from a;
end;
Edited by: user536416 on May 13, 2010 4:03 AMI prefer reference cursors over execute immediate if I must do dynamic SQL (and have learned not to do it unless necessary - among other things dynamic SQL is hard to debug and maintain).
The advantages to ref cursors are
* execute immedate will only retrieve one row, ref cursors as many as you want
* easier for me to build the query first, then execute it (though you can do this with execute immediate too) for debugging
You can buiid the query dynamcially but have to be careful to make sure the select list matches the INTO clause on the fetch statements. Although the queries in the example below are hard coded I could have done something like
v_command_c := 'select '||var1||', '||var2||' from '''||table_name||'''';
open refcur for v_command_c;To randomize your column selection use something like the above with IF logic and a randomizer, possibly the DBMS_RANDOM package or a time extraction.
Something like
SET SCAN OFF
SET SERVEROUTPUT ON
DECLARE
--define composite data types
--reference cursor type - structure
TYPE RefCursorType IS REF CURSOR;
--collection (index-by table) type - structure
TYPE TablesTableType IS TABLE OF user_tables.table_name%TYPE
INDEX BY BINARY_INTEGER;
--define ref cursors to be used in BEGIN section
UserTablesCursor RefCursorType;
UserViewCursor RefCursorType;
--define actual index-by tables to be used in BEGIN section
NamesTable TablesTableType;
ViewsTable TablesTableType;
--define internal procedures to be used in this script
PROCEDURE ListItems(RefCursor IN RefCursorType,
DataTable IN OUT TablesTableType
) IS
Counter INTEGER := 1;
TableName user_tables.table_name%TYPE;
BEGIN
FETCH RefCursor INTO DataTable(Counter);
Counter := Counter + 1;
WHILE RefCursor%FOUND LOOP
FETCH RefCursor INTO DataTable(Counter);
Counter := Counter + 1;
END LOOP;
END; --ListItems;
PROCEDURE WriteItems(DataTable IN TablesTableType) IS
BEGIN
FOR i IN 1..DataTable.count LOOP
dbms_output.put_line(DataTable(i));
END LOOP;
END; --WriteItems;
BEGIN
OPEN UserTablesCursor FOR
SELECT table_name
FROM user_tables;
ListItems(UserTablesCursor,NamesTable);
CLOSE UserTablesCursor;
dbms_output.put_line('user_tables');
dbms_output.put_line('--------------');
WriteItems(NamesTable);
--second defintion & set of calls
dbms_output.put_Line(CHR(13));
OPEN UserTablesCursor FOR
SELECT view_name
FROM user_views;
ListItems(UserTablesCursor,ViewsTable);
CLOSE UserTablesCursor;
dbms_output.put_line('user_views');
dbms_output.put_line('--------------');
WriteItems(ViewsTable);
END;
/Edited by: riedelme on May 13, 2010 5:44 AM -
Help in calling dynamic columns in anonymous blocks
my code:
DECLARE
col1 VARCHAR2(20):='city';
BEGIN
FOR i IN (select * from xbd.cus_ord where rownum < 10)
LOOP
-- I would like to call col1 dynamically here in my dbms output.
DBMS_OUTPUT.PUT_LINE (i.col1);
END LOOP;
END;
On above code I was trying to call a dynmic column. How can I do that.
I heve been tried in different way by using EXECUTE IMMEDIATE. Still it doesnt work.
Thx,
ViDECLARE
col1 VARCHAR2(30) := 'object_name';
TYPE REF_CURSOR IS REF CURSOR;
refCursor REF_CURSOR;
text VARCHAR2(4000);
BEGIN
OPEN refCursor FOR 'SELECT ' || col1 || ' FROM all_objects WHERE ROWNUM < 10';
LOOP
FETCH refCursor
INTO text;
EXIT WHEN refCursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(text);
END LOOP;
END;
/
Maybe you are looking for
-
I have had this problem multiple times. My iphone cord is connected into my usb cord and is charging but will not show up in my itunes. So i am unable to do anything with it concerning music and such. How do i fix this?
-
Hey everyone, So I am trying to get a report onto the server, and in BIDS I kept getting a login screen repeating over and over when I tried to deploy my report, so I tried to upload the file at http://<servername>/Reports This worked, but then tryin
-
Machine and OS: 2007 white plastic iMac with 20" screen and 2 GHz Intel Core Duo, running OSX 10.6.8. The problem: The screen dims itself for no known reason. It is especially noticeable when waking from sleep: for the first second or two after wakin
-
No Ranges for Org Determination
Hi Gurus, I have to configured Org Structure in CRM. There is no integration of CRM with ECC is required. Therefore i have defined simple Org Structure in CRM. Now, i want to assign specific no ranges to my Org Units w/out any specific partner number
-
Cannot find lcds261-win.exe download link
can someone send me lcds261-win.exe download link. adobe is not able to search for this key word, what a jo*e