Populate a REF CURSOR from regular cursor...
Hi all,
I apologize if the answer to this is somewhere...I've been looking on the web for sometime and can't find an answer to the following problem. I have a Significant Events database that contains network based issues and problems. As problems are detected on the network an SE is issued and published. As the SE records are updated, NEW records are entered into the table and "linked" back to the original. Each update results in a new row. Thus, an SE with two updates would have a total of 3 lines. When the SE gets closed (set the column CLOSED to SYSDATE), only the "original" SE is closed, any updates are left open...aka, the CLOSED column is left null.
That said, I need a way to get the original and/or latest updated SE rows from the table. Thus, I am trying to use a PL/SQL package. The PL/SQL "must" return a REF CURSOR as the results are being passed to a client process.
My initial approach was within a PL/SQL procedure, I have an SQL statement that returns the SE originals. Once in that cursor I need to do the following:
- Attempt to fetch any linked SE rows.
- if no rows then
- add the original to the REF CURSOR.
- else
- find latest SE update
- add latest SE update to REF CURSOR.
- end if
My Question is : How do I manually "add" a row to a REF CURSOR?
If this is not possible, is there a way to populate a REF CURSOR from maybe another construct like:
TYPE ian_se_record is RECORD (
se_id number
,linked_se_id number
,submitted date
,updated date
,closed date
,segroup varchar2(150)
,incident_start_time varchar2(150)
,business_units_affected varchar2(150)
,officenum varchar2(1500)
,sedetails varchar2(4000)
TYPE ian_se_table is table of ian_se_record index by binary_integer;
With the above construct I could:
- Fill ian_se_table with the process described above.
- And finally select off ian_se_table into the REF CURSOR?
Any help would be greatly appreciated,
adym
Hi michaels,
I've put your solution in place, but can't seem to get it to run. The two types were moved out of the package and into real types as you said. Here's the function, for brevity, I've remove some of the less important code:
function ian_se_fetch return sys_refcursor
is
p_csr_events sys_refcursor;
cursor csr_items is
select
se_id
...removed for brevity...
/* END : csr_items */
ian_se_row ian_se_record;
ian_se_tbl ian_se_table;
l_lng_index number;
l_lng_linked number;
l_lng_id number;
begin
* OPEN : Open the main cursor of originals...
for the_item in csr_items loop
* CHECK : Check for any updates to the original...
l_lng_linked := 0;
select count(*)
into l_lng_linked
from sig_se_t src
where src.linked_se_id = the_item.se_id;
l_lng_id := 0; /* reset the se-id */
/* SE original...no linked records yet. */
if ( l_lng_linked = 0 ) then
l_lng_id := the_item.se_id;
/* SE updates...one or more updates are present. */
else
begin
select
se_id
into l_lng_id
from sig_se_t src
where src.linked_se_id = the_item.se_id
and rownum = 1
order by updated desc; /* latest update */
exception
when too_many_rows then
l_lng_id := the_item.se_id;
when others then
l_lng_id := 0;
end;
end if;
if ( l_lng_id != 0 ) then
select
se_id
,linked_se_id
,submitted
,updated
,closed
,segroup
,incident_start_time
,business_units_affected
,officenum || decode( nvl(impact,'1')
,'1',''
,decode(impact
,'NA', ''
,':' || impact
) impact
,sedetails
into ian_se_row.se_id
,ian_se_row.linked_se_id
,ian_se_row.submitted
,ian_se_row.updated
,ian_se_row.closed
,ian_se_row.segroup
,ian_se_row.incident_start_time
,ian_se_row.business_units_affected
,ian_se_row.officenum
,ian_se_row.sedetails
from sig_se_t src
where src.se_id = l_lng_id;
l_lng_index := nvl(ian_se_tbl.last,0)+1;
ian_se_tbl(l_lng_index).se_id := ian_se_row.se_id;
ian_se_tbl(l_lng_index).linked_se_id := ian_se_row.linked_se_id;
ian_se_tbl(l_lng_index).submitted := ian_se_row.submitted;
ian_se_tbl(l_lng_index).updated := ian_se_row.updated;
ian_se_tbl(l_lng_index).closed := ian_se_row.closed;
ian_se_tbl(l_lng_index).segroup := ian_se_row.segroup;
ian_se_tbl(l_lng_index).incident_start_time := ian_se_row.incident_start_time;
ian_se_tbl(l_lng_index).business_units_affected := ian_se_row.business_units_affected;
ian_se_tbl(l_lng_index).officenum := ian_se_row.officenum;
ian_se_tbl(l_lng_index).sedetails := ian_se_row.sedetails;
end if;
end loop;
* REF CURSOR : Open the ref cursor on the dataset...
if ( nvl(ian_se_tbl.last,0) = 0 ) then
p_csr_events := null;
else
open p_csr_events for
select *
from table (cast ( ian_se_tbl as ian_se_table ));
end if;
return p_csr_events;
end;Here's the test. I keep getting the same error ORA-06530:
SQL> variable v refcursor;
SQL> exec :v:=pkg_ian.ian_se_fetch;
BEGIN :v:=pkg_ian.ian_se_fetch; END;
ERROR at line 1:
ORA-06530: Reference to uninitialized composite
ORA-06512: at "N0002501.PKG_IAN", line 131
ORA-06512: at line 1
SQL> print v
ERROR:
ORA-24338: statement handle not executedOther things I tried:
- The ian_se_fetch() function was a procedure using an in out parameter...same error.
- Wrote a small anonymous block and tried to LOOP/FETCH. Same ORA-06530 error.
P.S. Line 131 of pkg_ian is the SELECT ... INTO ian_se_row.se_id, ...
Any help would be greatly appreciated,
tia,
adym
Message was edited by:
alink
Similar Messages
-
Function call returned in ref cursor
We have a ref cursor that calls a function in a package. When ODP.NET reads the cursor, it can't see what the function is returning. OO4O works fine, and if I take the sql that populates the ref cursor and put it into a temporary table, then select from that temporary table to return the ref cursor to ODP, it works fine. Anyone else seen this issue? Any help would be appreciated. Thanks.
Eric Schrauth
[email protected]Did you set the parameter direction to be ParameterDirection.Input when you created the parameter? Post your code.
-
I have a stored procedure that returns a weak REF CURSOR as an out parameter. I want to access the rows that are returned, in an OCI application. I want a sample OCI program that does this. The PL/SQL code is as follows
PACKAGE TEST_PACKAGE AS
TYPE RCT IS REF CURSOR;
END;
PROCEDURE TEST_PROCEDURE (R OUT TEST_PACKAGE.RCT)
AS
BEGIN
OPEN r FOR
SELECT * FROM XXX;
END;
THANKS.Hello,
I used in my application regular connections, I created
CallableStatement with these connections, later I got one cursor with:
mr = ((OracleCallableStatement)cstmt).getCursor(1)
where mr is ResultSet and cstmt is CallableStatement.
But, when I use the Commerce PoolConnection I get serialConnection
and it creates serialCallableStatement and the command:
mr = ((OracleCallableStatement)cstmt).getCursor(1)
get the next exception:
java.lang.ClassCastException:
weblogic.jdbc20.rmi.SerialCallableStatement at......
Are you working with Bea ConnectionPool
or regular Connections?
Thank you.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Matt Sivertson ([email protected]):
I'm having a very strange problem with some JDBC code. Basically, there is a StoredProcedure in the DB that we call through JDBC. One of the out parameters is a REF CURSOR. My user does not have select access to the table, but the stored procedure does. When I try and get the ResultSet corresponding to that RefCursor using the OracleCallableStatement.getCursor() method, and exception gets thrown saying it cannot find the table. We checked on the database, and it is actually performing a new select statement as My user, rather than as the StoredProcedure. If we open up the permissions on the table, everything works fine, but this defeats the whole purpose of what the DBA wants.
BTW, this same Stored Procedure works when fine when accesed through PL/SQL or SQL+. Only JDBC seems to have a problem with it. Any help is greatly appreciated.
Matt Sivertson
[email protected]<HR></BLOCKQUOTE>
null -
What is the better approach to populate Ref cursor into ADF business Component
HI All,
I have a requirement where I get the search results by joining more than 10 tables for my search criteria.
What is the best approach to populate into ADF BCs.
I have to go with Stored Procedure approach where I input the search Criteria and get the cursor back from the same.
If I populate VO programmatically then the filtering at column level is a challenge.
Anyone Please help me. Thanks in Advance.
Thanks,
Balaji Mucheli.The number of tables to be joined for a VO's query shouldn't matter - if the query is valid and fixed.
Are you saying that you have logic to decide which tables to join to create the correct query? I admit that would be a difficult thing to do, other than with a programmatic VO. However, there are two possible solutions for doing this without a programmatic VO.
Instead of your procedure returning a REF CURSOR, you can create an object type (CREATE TYPE) and a nested table of that type. Then you have a function that returns an instance of the nested table. The query in the VO is SELECT my_column... FROM TABLE(CAST my_table_function(:bind_variable) AS my_table_type). You may have trouble getting the VO to accept this query as valid SQL, but it IS valid and it DOES work.
Create a VO to be the master VO - it should have all the attributes that you intend to use, but the query can be anything, even a SELECT from DUAL. Then create other VOs that subclass the master VO - one for each major variation of the query. When you use the VO, use the data control for the master VO to create your pages, but change the pageDef to make the VO name a variable (with expression language). Then you can set that variable to the correct child VO for the query that needs to execute. -
How to get values from a ref cursor in a procedure
I have a procedure that returns a cursor type of values, but I cannot get the values.
I got error when on how to define the output cursor. Could someone please look at the code and tell me how to correct it?
Thanks in advance.
******************************8
--This is the package
CREATE OR REPLACE PACKAGE Test_SECURITY2 as
type T_RoleTest is ref cursor;
Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest);
end;
CREATE OR REPLACE PACKAGE BODY Test_SECURITY2 as
Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest) as
begin
open p_cur for
select PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME
from preorder.PREO_Role, preorder.PREO_User_Role
where PREO_Role.Role_id = PREO_User_Role.Role_id
and PREO_User_Role.user_id = userid;
end;
end;
--This is the testing code. I got error here
SQL> set serveroutput on;
SQL> execute dbms_output.enable;
PL/SQL procedure successfully completed.
SQL> declare
2 type T_RoleTest is ref cursor;
3 V_UserRole is ref cursor; --how to define the output cursor
4 v_userId number := 42;
5 V_Role_Id number;
6 v_Role_name varchar2(20);
7 begin
8 Test_SECURITY2.P_GetUserRole(v_userId, V_UserRole);
9
10 open V_UserRole;
11 loop
12 fetch V_UserRole into V_Role_Id, v_Role_name;
13
14 EXIT WHEN V_UserRole%NOTFOUND;
15 dbms_output.put_line('RoleID'||v_Role_ID);
16 dbms_output.put_line('Rolename'||v_Role_name);
17
18 end loop;
19
20 end;
21 /
V_UserRole is ref cursor;
ERROR at line 3:
ORA-06550: line 3, column 13:
PLS-00103: Encountered the symbol "IS" when expecting one of the following:
constant exception <an identifier>declare
type T_RoleTest is ref cursor;
v_UserRole T_RoleTest;or just:
declare
v_UserRole Test_Security2.T_RoleTest;And, if you are on 9i or later, you can just use the built-in sys_refcursor type. -
How to descrbe a ref cursor from a PL/SQL prog?
Hi,
here is a sample of the my problem
let suppose a table country :
create table country(country_code VARCHAR2(3), country_name VARCHAR2(50));
then a package containing different procedures among them, this one :
PL/SQL prog
create or replace package country_pkg as
type rec1 is ref cursor return country%rowtype;
Procedure get_all_countries(rec in out rec1);
blablabla ...
END country_pkg;
in the package body, i have the following code :
create or replace package body country_pkg as
procedure get_all_countries(rec IN OUT rec1) is
begin
if not rec%open then
open rec for select * from country order by country_name;
end if;
exception
when NO_DATA_FOUND then
close rec;
end get_all_countries;
blablabla....
end;
Then in the C program
(*proc)->request->command = "begin get_all_countries(:rec); end;"
checkerr(&connect, \
OCIStmtPrepare(connect->stmthp,\
connect->errhp,\
(*proc)->request->command,\
strlen((*proc)->request->command),\
OCI_NTV_SYNTAX, OCI_DEFAULT));
checkerr(&connect, \
OCIHandleAlloc((dvoid*)(connect->envhp),\
(dvoid**) &((*proc)->stmthp), OCI_HTYPE_STMT,
(size_t) 0,\
(dvoid**) 0));
bndhp = (OCIBind**) g_malloc0((*proc)->argnum*sizeof(OCIBind*));
for(i = 0; i < (*proc)->argnum; i++)
switch ((*proc)->desc->type)
case 102:
checkerr(&connect,
OCIBindByPos(connect->stmthp, &bndhp[j],
connect->errhp,
i+1,&((*proc)->stmthp), (sb4) 0,
SQLT_REF, (dvoid*) 0, (ub2*) 0, (ub2*) 0,
(ub4) 0,
(ub4*) 0, (ub4) OCI_DEFAULT));
default:
some code ....
checkerr(&connect, \
OCIStmtExecute(connect->svchp, connect->stmthp,\
connect->errhp, 1, (ub4) 0, (OCISnapshot*) 0,\
(OCISnapshot*) 0, OCI_DEFAULT));
parm_status = OCIParamGet(connect->stmthp, OCI_HTYPE_STMT,connect->errhp, (dvoid**)&arg, 0);
while(parm_status == OCI_SUCCESS)
OCIAttrGet((dvoid*) arg, OCI_DTYPE_PARAM,
(dvoid*)type,0, (ub4) OCI_ATTR_NUM_PARAMS,
connect->errhp);
counter++;
parm_status = OCIParamGet(connect->stmthp,
OCII_HTYPE_STMT,connect->errhp,
(dvoid**)&arg, counter);
This piece of code doesn't work as 'arg' is always NULL
and OCIParamGet retruns OCI_SUCCESS.
I'm certainly missing something but I don't see what. Could anyone help me to get that piece of code working?
regards,
Raphaelunfortunately, not yet!
I dropped the matter for now, I'll come back on it later.
On your side, let me know if you find something interesting on that topic by posting a message here. -
How to retrieve data from a REF CURSOR using OCI 8.0?
I found an example in Oracle docs (shown below) that discusses how to bind a REF CURSOR for later data retrieval, but it does not explain actually how to do the later data retrieval.
I hope someone can explain it to me. Thanks
The OCI provides the ability to bind and define PL/SQL REF CURSORs and nested tables. An application can use a statement handle to bind and define these types of variables. As an example, consider this PL/SQL block:
static const text plsql_block = (text )
"begin \
OPEN :cursor1 FOR SELECT empno, ename, job, mgr, sal, deptno \
FROM emp_rc WHERE job=:job ORDER BY empno; \
OPEN :cursor2 FOR SELECT * FROM dept_rc ORDER BY deptno; \
end;";
An application would allocate a statement handle for binding, by calling OCIHandleAlloc(), and then bind the :cursor1 placeholder to the statement handle, as in the following code, where :cursor1 is bound to stm2p. Note that the handle allocation code is not included here.
err = OCIStmtPrepare (stm1p, errhp, (text *) nst_tab, strlen(nst_tab),
OCI_NTV_SYNTAX, OCI_DEFAULT);
err = OCIBindByName (stm1p, (OCIBind **) bndp, errhp,
(text *)":cursor1", (sb4)strlen((char *)":cursor1"),
(dvoid *)&stm2p, (sb4) 0, SQLT_RSET, (dvoid *)0,
(ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT);
In this code, stm1p is the statement handle for the PL/SQL block, while stm2p is the statement handle which is bound as a REF CURSOR for later data retrieval. A value of SQLT_RSET is passed for the dty parameter.( sorry, i forgot the Link where i get this html fiLes, so i just copy-paste here )
( maybe it can heLp you a bit. -- it's heLp me, for sure )
And the following is thanks to Brett Rosen :
I noticed that you didn't have an OCI entry
on http://osi.oracle.com/~tkyte/ResultSets/index.html .
Here is OCI code to do this (Oracle 81) if you want to include it on
that page.
Some error checking and cleanup has been removed, but the below should
work. (once dbname has been replaced appropriately)
Brett
int main(int argc, char* argv[])
OCIError* pOciError;
char* pConnectChar = "dbname";
char* pUsernameChar = "scott";
char* pPasswordChar = "tiger";
int answer;
OCIStmt* pOciStatement;
char* sqlCharArray = "BEGIN :success := sp_ListEmp; END;";
int id;
char ename[40];
OCIEnv* g_pOciEnvironment = NULL;
OCIServer* g_pOciServer = NULL;
OCISession* g_pOciSession = NULL;
OCISvcCtx* g_pOciServiceContext = NULL;
sb2* pIndicator=0;
sb2* pIndicator2=0;
sb2* pIndicator3=0;
OCIDefine* pOciDefine;
OCIDefine* pOciDefine2;
OCIBind* pBind;
OCIStmt* cursor;
answer = OCIInitialize(OCI_THREADED, NULL, NULL, NULL, NULL);
answer = OCIEnvInit(&g_pOciEnvironment, OCI_DEFAULT, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciSession, OCI_HTYPE_SESSION, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServer, OCI_HTYPE_SERVER, 0, NULL);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
answer = OCIServerAttach(g_pOciServer, pOciError, (unsigned char *)pConnectChar, strlen(pConnectChar),
OCI_DEFAULT);
answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pUsernameChar, strlen(pUsernameChar),
OCI_ATTR_USERNAME, pOciError);
answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pPasswordChar, strlen(pPasswordChar),
OCI_ATTR_PASSWORD, pOciError);
answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciServer, 0, OCI_ATTR_SERVER, pOciError);
answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciSession, 0, OCI_ATTR_SESSION, pOciError);
answer = OCISessionBegin(g_pOciServiceContext, pOciError, g_pOciSession, OCI_CRED_RDBMS, OCI_DEFAULT);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&pOciStatement), OCI_HTYPE_STMT, 0, NULL);
answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray, strlen(sqlCharArray),
OCI_NTV_SYNTAX, OCI_DEFAULT);
answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&cursor), OCI_HTYPE_STMT, 0, NULL);
answer = OCIBindByPos(pOciStatement,&pBind, pOciError, 1, &cursor, 0,SQLT_RSET,
pIndicator2, 0,NULL, 0,0,OCI_DEFAULT);
answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
OCI_COMMIT_ON_SUCCESS);
answer = OCIDefineByPos(cursor,&pOciDefine, pOciError,2,&id,sizeof(int),
SQLT_INT,pIndicator, 0, 0,OCI_DEFAULT);
answer = OCIDefineByPos(cursor,&pOciDefine2, pOciError,1,ename,40,
SQLT_STR,pIndicator3, 0, 0,OCI_DEFAULT);
if (answer == 0)
while ((answer = OCIStmtFetch(cursor,pOciError, 1,OCI_FETCH_NEXT,OCI_DEFAULT)) == 0)
printf("fetched id %d and name %s\n",id,ename);
answer = OCIHandleFree(pOciError, OCI_HTYPE_ERROR);
return 0;
} -
How to get an UPDATABLE REF CURSOR from the STORED PROCEDURE
using C# with
ORACLE OLE DB version: 9.0.0.1
ADO version: 2.7
I returns a REF CURSOR from a stored procedure seems like:
type TCursor is ref cursor;
procedure test_out_cursor(p_Dummy in varchar, p_Cur out TCursor) is
begin
open p_Cur for select * from DUAL;
end;
I create an ADO Command object and set
cmd.Properties["IRowsetChange"].Value = true;
cmd.Properties["Updatability"].Value = 7;
cmd.Properties["PLSQLRSet"].Value = 1;
cmd.CommandText = "{CALL OXSYS.TEST.TEST_OUT_CURSOR(?)}";
and I use a Recordset object to open it:
rs.Open(cmd, Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockBatchOptimistic,
(int) ADODB.CommandTypeEnum.adCmdText +
(int) ADODB.ExecuteOptionEnum.adOptionUnspecified);
The rs can be opened but can NOT be updated!
I saved the recordset into a XML file and there's no
rs:baseschema/rs:basetable/rs:basecolumn
attributes for "s:AttributeType" element.
Any one have idea about this?
thanks very muchIt is not possible through ADO/OLEDB.
Try ODP.NET currently in Beta, it is possible to update DataSet created with refcursors. You need to specify your custom SQL or SP to send update/insert/delete.
As I remember there is a sample with ODP.NET Beta 1 just doing this. -
How to populate table name dynamically to a ref cursor
Hi,
I came accross with a requirement that in ref cursor how can i pass the table name
for ex
open ref_cur for select * from emp;Like that i've some 100 tables , instead of typing each and every time the table name
that should be dynamically changed
Like below
open ref_cur for select * from &tbl_nm;How can i do that??
Thank youI assume you are using SQL*Plus:
SQL> variable ref_cur refcursor;
SQL> begin
2 open :ref_cur for select * from &tbl_nm;
3 end;
4 /
Enter value for tbl_nm: emp
old 2: open :ref_cur for select * from &tbl_nm;
new 2: open :ref_cur for select * from emp;
PL/SQL procedure successfully completed.
SQL> print ref_cur
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 12/17/1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 02/20/1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 02/22/1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 04/02/1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 09/28/1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 05/01/1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 06/09/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 04/19/1987 00:00:00 3000 20
7839 KING PRESIDENT 11/17/1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 09/08/1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 05/23/1987 00:00:00 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 12/03/1981 00:00:00 950 30
7902 FORD ANALYST 7566 12/03/1981 00:00:00 3000 20
7934 MILLER CLERK 7782 01/23/1982 00:00:00 1300 10
14 rows selected.
SQL> begin
2 open :ref_cur for select * from &tbl_nm;
3 end;
4 /
Enter value for tbl_nm: dept
old 2: open :ref_cur for select * from &tbl_nm;
new 2: open :ref_cur for select * from dept;
PL/SQL procedure successfully completed.
SQL> print ref_cur
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> SY. -
Reports 3.0, Ref Cursor from stored procedure
I have a problem trying to use Ref Cursor as datasource (i.e.
Ref Cursor Query) in Reports 3.0
I have created a stored package with a function which returns
Ref Cursor.
That function just opens the cursor and returns it to the
calling module.
Reports recognizes returned cursor - it creates a group for that
query, with all columns, than I built
a layout model - everything is OK on that stage.
During the execution of that report (from previewer or using
Reports Runtime) I got an error message like that:
REP-0065 Virtual Memory System Error
REP-0200 Cannot allocate enough memory cavaa22
Error's description does not correspond the reality :) - there
is enough virtual & physical memory according to
Task Manager information.
So, that does not work when this package is stored one.
When I create the package on the client side - in Reports -
everything works just fine.
Cursor is opened with a very simple query, selecting records
from the very simple table having only one record.
There is no code written which closes that cursor or fetches the
records.
Client platform: WinNT 4.0 SP3
Oracle Reports: 3.0.5.8.0
Oracle Server: Oracle8 8.0.5.0.0 (and I tried also on Oracle7
7.3.4.3.0)
Thanx.
nullSara,
GTT (Global Temporary Tables) in Oracle work a different way compared to SQL Server and Informix. There you can create temporary tables on the fly and drop them on the fly.
Here you should (note, you don't have to, but, best practice says that you should) create the table using the syntax...
create global temporary table.....
Once you create it, even though it looks like persistent table, it's not. It will have it's own individual data PER SESSION . You have two types of GTTs:
ON COMMIT PRESERVE ROWS and ON COMMIT DELETE ROWS (they work in slightly different way).
Look up GTTs here:
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm#sthref2213
HTH,
Rahul -
How to get value from First Row in an REF CURSOR
I have a REF CURSOR defind like:
open out_RESULT_SET for
select
EVENT_UID,
EVENT_DATE,
EVENT_ITEM
from
EVENT
order by
EVENT_DATE ASC;
I want to also set the value of a variable v_FIRST_EVENT_DATE to the value in the EVENT_DATE column of the first row.
I know I could do a:
select
min(EVENT_DATE)
into
v_FIRST_EVENT_DATE
from
EVENT;
But I would rather just use the REF CURSOR (I think).
Thanks for the help.How would I get v_FIRST_EVENT_DATE set to the date of the first event in the REF CURSOR out_RESULT_SET?Normal fetch into associated local variables should suffice.
Something along those lines:
declare
v_first_event_date event.event_date%type;
v_event_uid event.event_uid%type;
v_event_date event.event_date%type;
v_event_item event.event_item%type;
begin
open out_result_set for
select min (event_date) over () first_event_date, event_uid,
event_date, event_item
from event
order by event_date asc;
loop
fetch out_result_set
into v_first_event_date, v_event_uid, v_event_date, v_event_item;
exit when out_result_set%notfound;
do_something;
end loop;
close out_result_set;
end;
/ -
Calling stored proc from java using ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc �
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is �
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Calling stored proc from java to return ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc ?
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is ?
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Getting data stored in ref cursor ( got from store proc in oracle) to excel sheet)
Hey, I am trying to Get data stored in ref cursor ( got from store proc in oracle) to excel sheet in a virtual folder using ssis.
I am getting errors and cant do it. If anyone can help meHi Nabin000,
The Oracle stored procedure doesn't work with SSIS source adapters such as OLE DB Source because the data provider doesn't provide metadata for the source adapter. To achieve your goal, you can use a Script Component as source to call
the Oracle stored procedure by using System.Data.OracleClient OracleDataReader, and get the rows and add them to the pipeline buffer. For more information, please see:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d0b3a1b-8792-469c-b0d1-f2fbb9e9ff20/dump-oracle-ref-cursor-into-ms-sql-staging-table-using-ssis
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/executing-an-oracle-stored-procedure-from-ssis?forum=sqlintegrationservices
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(VS.90).aspx
Regards,
Mike Yin
TechNet Community Support -
REF CURSOR problem .. function call from select
Hello,
I am still on the search for a way to call a function from with in a select statement.
I've done it in SQL*Plus like this and it works.
SELECT name, f_format(name) FROM user WHERE id = 12;
This returns first the unformatted (raw) version of the stored value for name and then the formmtted version of the stored value of name.
Since multiple names will be returned I need to user a REF CURSOR (cursor variable). The above select statement does not work from within the OPEN . .FOR clause necessary for a REF CURSOR.
What can I do instead? My goal is to return multiple records of formatted names.
nullI have declared the reference cursor as a weak one. Thank you for clarifying that though. I was wondering if it made a difference. Here is a simple package that shows you what I am trying to do. I will include the errors at the bottom. Please have a look and let me know what you think is wrong.
/*--------- PL/SQL ------------*/
CREATE OR REPLACE PACKAGE test_refcur AS
PROCEDURE decrypt (
i_string IN VARCHAR2
,o_string OUT VARCHAR2
TYPE PwdCurTyp IS REF CURSOR;
PROCEDURE get_pwd_info (
i_user_id IN NUMBER
,io_pwd_cv IN OUT PwdCurTyp
END test_refcur;
CREATE OR REPLACE PACKAGE BODY test_refcur AS
FUNCTION f_decrypt (
i_string IN VARCHAR2
) RETURN VARCHAR2 IS
l_string VARCHAR2(64);
l_string_dec VARCHAR2(32);
BEGIN
l_string := i_string;
dbms_obfuscation_toolkit.DESDecrypt(
input_string => l_string
,key_string =>'12345678'
,decrypted_string=> l_string_dec );
RETURN l_string_dec;
END f_decrypt;
PROCEDURE decrypt (
i_string IN VARCHAR2
,o_string OUT VARCHAR2
) IS
BEGIN
o_string := f_decrypt(i_string);
END decrypt;
PROCEDURE get_pwd_info (
i_user_id IN NUMBER
,io_pwd_cv IN OUT PwdCurTyp
) IS
BEGIN
OPEN io_pwd_cv FOR
SELECT
label
,f_decrypt(user_name_text) AS dec_user_name
,f_decrypt(text) AS dec_pwd
FROM
code_pwd
WHERE
id = i_user_id;
END get_pwd_info;
END test_refcur;
/*--------- SQL*Plus -----------*/
Warning: Package Body created with compilation errors.
SHOW ERRORSErrors for PACKAGE BODY TEST_REFCUR:
LINE/COL ERROR
28/13 PL/SQL: SQL Statement ignored
30/18 PLS-00231: function 'F_DECRYPT' may not be used in SQL
Then I made the SELECT statement dynamic.
OPEN io_pwd_cv FOR
'SELECT label, f_decrypt(user_name_text) AS dec_user_name, f_decrypt(text) AS dec_pwd FROM code_pwd WHERE id = i_user_id';
It compiled fine.
Package body created.
So then I tried to do the following. .
SET AUTOPRINT ON
SET SERVEROUTPUT ON
VARIABLE cv REFCURSOR
EXECUTE test_refcur.get_pwd_info(18, :cv)begin test_refcur.get_pwd_info(18, :cv); end;
ERROR at line 1:
ORA-00904: invalid column name
ORA-06512: at "K.TEST_REFCUR", line 27
ORA-06512: at line 1
If I change the SELECT statement to the following, this is what I get. .
OPEN io_pwd_cv FOR
SELECT label
-- ,f_decrypt(user_name_text) AS dec_user_name
-- ,f_decrypt(text) AS dec_pwd
FROM code_pwd
WHERE id = i_user_id;
SET AUTOPRINT ON
SET SERVEROUTPUT ON
VARIABLE cv REFCURSOR
EXECUTE test_refcur.get_pwd_info(18, :cv)PL/SQL procedure successfully completed.
LABEL
Development Server
That tells me that at least something is working. How can I get everything else to work?
Maybe you are looking for
-
How to check data sent by XI in the SAP system?
Hi All, I have a File to Proxy scenario. I have generated and activated the proxy. The scenario got executed successfully. Now, how can I check the data being sent by XI in the SAP system? Kindly help. Thanks, Karthik
-
Exception while creating remote source in SDA
Hi I am trying to create a remote data source in hana studio using following script CREATE REMOTE SOURCE hivedb ADAPTER "odbc" CONFIGURATION 'DSN=REMOTEHDB' WITH CREDENTIAL TYPE 'PASSWORD' USING 'user=SYSTEM;password=Cloud123' and following exception
-
The audo files do not play from websites instead ask for download. This has occured from the time I have updated Firefox 4 to Firefox 5. Why? And how can i play audio files from websites?
-
System form oMatrix.LoadFromDataSource()
Hi all , Am try to load some 100 rows to the purchase credit memo matrix so i use this code below frmPCM.Freeze(True) oMatrix.FlushToDataSource() ========> error message (Item - The item is not a user-defined item [66000-8]) ===== ====== oDBDSDetail
-
Hi all. I'm a newbie in JSF tecnology and there's one thing that confuses me: What's the difference in between Sun RI and MyFaces? As I've understood while studying the subject, these are just two different implementations of the JSF specification. I