Sort data in ref cursor
Hello,
I would like to know if the following is possible:
I'm getting data from different sources in a ref cursor. Is it possible to sort this ref cursor on a specific column in the ref cursor? If so, how?
Thanks
Karuna
My problem is ...
I take the ref cursor, and have added some more data in there, based on a few conditions from different tables. So my ref cursor actually has more relevant data as compared to its source. I now need to find a way to sort that info. Is there a way around this?
Thanks
Karuna
Similar Messages
-
Wanted to fetch data from ref cursor to nested pl/sql table getting an erro
create or replace type "DEPT12" as object(dno number(2),dname varchar2(30),loc varchar2(50));
create or replace type dept_tab as table of "DEPT12"
create or replace type "LOC12" as object(locno number,loc_name varchar2(100))
create or replace type loc_tab as table of "LOC12"
create or replace type dept_loc_rec1 as object (dept_dt dept_tab,eno number,loc_dt loc_tab);
create type dept_loc_tb as table of dept_loc_rec1
create table dept_loc_tb_bk1(dept_dt dept_tab,eno number,loc_dt loc_tab)
NESTED TABLE dept_dt
STORE AS dept_tab12,
NESTED TABLE loc_dt
STORE AS loc_tab12
insert into dept_loc_tb_bk1 values(dept_tab(dept12(3,'ABD','LOC')
,dept12(4,'ABD','LOC')
,dept12(5,'ABD','LOC')),3,loc_tab(loc12(21,'AAB'),
loc12(22,'AAB'),
loc12(23,'AAB')));
when I am trying to fetch data from ref cursor to pl/sql table which i am getting an error ora-06504: pl/sql : Return types of result set variables or query do not match.
I have created a nested table of same as the nested pl/sql object table dept_loc_tb and i have declared the lv_dept_loc_tb of same dept_loc_tb but getting an above error when trying to fetch into that variable.
Please any one who can solve my problem.
declare
type cr is ref cursor;
cr_obj cr;
lv_dept_loc_tb dept_loc_tb;
begin
open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
fetch cr_obj bulk collect into lv_dept_loc_tb;
close cr_obj;
end;Your query selects 3 separate columns therefore requires 3 collections of corresponding types. You want to treat those 3 columns as an object of DEPT_LOC_REC1 type:
SQL> declare
2 type cr is ref cursor;
3 cr_obj cr;
4
5 lv_dept_loc_tb dept_loc_tb;
6
7 begin
8 open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
9 fetch cr_obj bulk collect into lv_dept_loc_tb;
10 close cr_obj;
11 end;
12 /
declare
ERROR at line 1:
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
ORA-06512: at line 9
SQL> declare
2 type cr is ref cursor;
3 cr_obj cr;
4
5 lv_dept_loc_tb dept_loc_tb;
6
7 begin
8 open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1;
9 fetch cr_obj bulk collect into lv_dept_loc_tb;
10 close cr_obj;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> SY.
P.S. Discover sys_refcursor. -
Using CRUD procedures to update data and ref cursors to return data
Hi:
I am currently evaluating Apex 3.x to replace an existing app that uses lots of procedures to update and return data.
1. Is it possible to return data from a function that returns a cursor (or from a procedure that has an input/output ref cursor parameter for that matter) ? Example: Let's say I have the following function in a package:
function get_data return sys_refcursor
is
l_cursor sys_refcursor;
begin
open l_cursor for select sysdate as field from sys.dual;
return l_cursor;
end;
Can I add a page with a table that is populated based on this function? Based on my research it is not possible, but I want an APEX expert to confirm it
2. The old application uses CRUD procedures to update date, that is for each table there are 3 procedures, insert update and delete. Question: is it possible to channel all the update, inserts and deletes through these procedures? Furthermore, in lots of cases I use sequences to populate the primary keys, and the new value is returned as output parameter. Can I retrieve the output value and use it maybe in the next page I am branching to?
In the samples that I've seen the same form is used for insert and update. How do I distinguish between the two modes?
3. Can you please point me to some samples that show how to do 1 & 2. The standard samples that I've seen use the automatic row processing.
4. Could you please recommend some good books about Apex or HTML db? I found the documentation unintuitive. It is hard to picture quickly how things tie together by reading this documention. I wish the documentation was more task oriented and presented 'how to...' implement generic patterns used in web apps.
Thank you in advanceHi guys
Check out the last 2 posts in this thread for ideas on how to implement 1.
Report on user data from LDAP
Varad -
I've got a procedure in PL/SQL that returns data to a .NET program using a ref cursor. If I run the procedure, all the data shows correctly. However, when I run it from .NET, it drops two records entirely (they are blank) and another one has "SYSTEM.WINDOWS.FORMS.TEXTBOX, TEXT" before the data prints. I'm passing the date as part of a string, using to_char to convert it.
The two lines that are missing are address lines (street address is one and city/state/zip is the other). The person's name (which is the first line) shows up fine. The street address starts with a number.
I'm passing all the fields as varchar2s.
On the .NET side, here's my code to populate the dataset:
Dim da As OracleDataAdapter = New OracleDataAdapter(cmd)
Dim ds As DataSet = New DataSet
Try
da.Fill(ds, "Bill")
When I look at the resulting data, the address lines are blank and the field with the date is showing the "SYSTEM" shown above.
Anyone have any ideas? This is driving me crazy.
-JoeAs a followup, I think the "SYSTEM.WINDOWS.FORMS.TEXTBOX, TEXT" problem has to do with how the parameter is passed. I'm asking the user to enter a date and then pass it as a varchar2. The parameter in my procedure is a varchar2 also. It is passed correctly and comes back correctly, but it puts the "SYSTEM.WINDOWS.FORMS.TEXTBOX, TEXT" before it prints the date. If I hard code the date in my PL/SQL procedure, it passes perfectly and prints perfectly. So it must be coming from .NET to Oracle. I've tried converting it to a date and then back to text, but with the same result.
-
Hello,
I would like to know if the following is possible:
I'm getting data from different sources in a ref cursor. Is it possible to sort this ref cursor on a specific column in the ref cursor? If so, how?
Thanks
KarunaNote that this is a duplicate post of this thread
sort data in ref cursor
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Sorting the results returned by a Ref cursor
Hi All,
I have a scenario where i am asked to sort results returned by a ref cursor.
I have to pass the column to be sorted as the Input parameter to a stored procedure. I tried using 'order by sorting_parameter' in the ref cursor's select query, but it is not sorting the results. It is not throwing any error even.
Please help.
Many Thanks...Hi
i came across the below reply for a thread with the similar query as above.
<<
Justin Cave
Posts: 10,696
From: Michigan, USA
Registered: 10/11/99
Re: sort data in ref cursor
Posted: Feb 3, 2005 10:30 AM in response to: [email protected] Reply
No. You could sort the data in the SQL statement from which the REF CURSOR was created, but once you have a REF CURSOR, you cannot do anything but fetch from it.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
>>
So, the results from a ref cursor cant be sorted?? There is no way out?
Kindly advise. -
How to update data returned using REF CURSOR
Hi all,
I am trying to update updated data in a gridview but the update button seem to do nothing as i retrieve data using REF CURSOR.
Let me describe the architecture of my application first. I'm trying to implement best practice whenever possible. I am following the data access tutorial published in www.asp.net , the only difference is that i have an Oracle (10g) database. So I split my application into three layers, data access, business logic, and presentation layer. I'm also writing all queries in an Oracle package.
So I have my Oracle packages that perform CRUD operations. Then I have an xsd file that define dataTable based on the package procedure. My business logic layer then calls functions defined in the xsd file. And finally a detailsView control that uses an ObjectDataSource to call business logic functions.
In a nutshell, I am just trying to update records retrieved using REF CURSOR. Your help is very much appreciated. Please let me know if further details are required. Cheers,In the DataSet (xsd) where your DataTable is defined, you just need to add additional methods to the TableAdapter to handle insert, update and delete, either with SQL or by mapping to stored procedures.
Alternatively in code, create an OracleDataAdapter and supply its InsertCommand, UpdateCommand and DeleteCommand.
David -
Hi,
Is there any way to execute stored procedure via hyperion using ODBC and get back ref cursor data.
I tried to call a stored procedure that have a ref cursor out parameter but it gives me error.
My stored procedure code is below.
wrong number or types of arguments to in call to 'HYP_CURSOR'
create or replace package hyp_ref_cusrsor is
type t_cusror is ref cursor;
end;
create or replace procedure hyp_cursor(ret1 out hyp_ref_cusrsor.t_cusror) is
begin
open ret1 for select * from hyp_tmp1 m;
end;
Hyperion version is 9.3.1
Oracle version is 10.0.2
RegardsGeorge wrote:
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? No.
{thread:id=886365}
Re: OPEN cursor for large query
A ref cursor is a pointer to a compiled SQL statement, it has no rows so there is no limit to the number of rows that you can use it to fetch, just like there is no limit to the number of rows a select can return.
I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume 750,000 rows returned via a ref cursor. This is very confusing, it it hangs how do you know it returns 750,000 rows? -
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume > 750,000 rows returned via a ref cursor.
The database procedure works fine when the number of rows is less than 2,000.
Has anyone had this problem before?
Many Thanks,
GeorgieGeorge wrote:
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? No.
{thread:id=886365}
Re: OPEN cursor for large query
A ref cursor is a pointer to a compiled SQL statement, it has no rows so there is no limit to the number of rows that you can use it to fetch, just like there is no limit to the number of rows a select can return.
I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume 750,000 rows returned via a ref cursor. This is very confusing, it it hangs how do you know it returns 750,000 rows? -
Problem with XSU when trying to execute pl/sql package returning ref cursor
Hi,
I'm exploring xsu with 8i database.
I tried running sample program which I took from oracle
documentation. Here is the details of these.
------create package returning ref cursor---
CREATE OR REPLACE package testRef is
Type empRef IS REF CURSOR;
function testRefCur return empRef;
End;
CREATE OR REPLACE package body testRef is
function testRefCur RETURN empREF is
a empREF;
begin
OPEN a FOR select * from emp;
return a;
end;
end;
---------package successfully created-----
Now I use java program to generate xml data from ref cursor
------------java program ----------
import org.w3c.dom.*;
import oracle.xml.parser.v2.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.query.OracleXMLQuery;
import java.io.*;
public class REFCURt
public static void main(String[] argv)
throws SQLException
String str = null;
Connection conn = getConnection("scott","tiger"); //
create connection
// Create a ResultSet object by calling the PL/SQL function
CallableStatement stmt =
conn.prepareCall("begin ? := testRef.testRefCur();
end;");
stmt.registerOutParameter(1,OracleTypes.CURSOR); // set
the define type
stmt.execute(); // Execute the statement.
ResultSet rset = (ResultSet)stmt.getObject(1); // Get the
ResultSet
OracleXMLQuery qry = new OracleXMLQuery(conn,rset); //
prepare Query class
try
qry.setRaiseNoRowsException(true);
qry.setRaiseException(true);
qry.keepCursorState(true); // set options (keep the
cursor alive..
System.out.println("..before printing...");
while ((str = qry.getXMLString())!= null)
System.out.println(str);
catch(oracle.xml.sql.OracleXMLSQLNoRowsException ex)
System.out.println(" END OF OUTPUT ");
qry.close(); // close the query..!
// qry.close(); // close the query..!
// Note since we supplied the statement and resultset,
closing the
// OracleXMLquery instance will not close these. We would
need to
// explicitly close this ourselves..!
stmt.close();
conn.close();
// Get the connection given the user name and password..!
private static Connection getConnection(String user, String
passwd)
throws SQLException
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@xxxx:1521:yyyy",user,passwd);
return conn;
when I ran the program after successful compilation,I got the
following error
==========
Exception in thread "main" oracle.xml.sql.OracleXMLSQLException:
1
at oracle.xml.sql.core.OracleXMLConvert.getXML(Compiled
Code)
at oracle.xml.sql.query.OracleXMLQuery.getXMLString
(OracleXMLQuery.java:263)
at oracle.xml.sql.query.OracleXMLQuery.getXMLString
(OracleXMLQuery.java:217)
at oracle.xml.sql.query.OracleXMLQuery.getXMLString
(OracleXMLQuery.java:194)
at REFCURt.main(Compiled Code)
============================
Can anybody tell me why I'm getting this error.Am I missing any
settings?
thanksWe are using 8.1.7 Oracle db with latest xdk loaded.
am I missing any settings? -
Is BC4J a viabl option for database with stored procedure (ref cursor) API?
I'm about to begin a Web application development project. As foundation, we have a (Oracle) database of certain complexity that have a data access API developed with PL/SQL packages.
This API is designed to get data through stored procedures/functions that return REF CURSOR.
Personally I have been investigating about Oracle ADF/JSF, and a number of others J2EE technologies, and at this moment I am doubting if ADF BC are a viable option to my development team.
I think this because I have noticed that one of the great drawback in ADF BC is the lack of simplicity to get data through stored procedures/functions that returns REF CURSORS.
I have been looking for documentation and the only thing that I have found are two examples:
1.- One that really do not work (fails in get data from ref cursor): ADF BC StoredProcedure Sample application.
2.- And other published by Steve Muench in
http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html. This sample works fine.
But, the problem with the approach of this last article is the amount (and complexity) of the code necessary to make so basic and recurrent operation as is "obtain data through a stored procedure (ref cursor)".
Below it is the code that I have constructed to call a function that returns a ref cursor (based on steve's article).
If this is the only way to make this (historically so basic and simple) task, then it is obvious that BC is not a viable technology to my (or I am in a mistake?), since we have about 50 stored procedures/functions to access the underlying data; that stored procedures/functions are key to development of the new application (and, still more, currently are used to anothers apps ).
By all this, I would like consult to Oracle's people:
1.- I really must reject BC as technology to implement this project ?
2.- It is possible to access stored procedures in a simpler way using BC?
3.- If the answer to 2 is NOT: in near future, the BC team has plans to give more support to the simple access to stored procedures?
4.- If the answer to 3 is NOT: what another technology you recommend to construct my data access/business tier and still be able to using the others characteristics of ADF?
Thank you very much for your guidelines.
Regards, RL.
** And the code!!!
** ### I am forced to do this for each call to a procedure???? ###
package myrefcursor.model;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jbo.JboException;
import oracle.jbo.domain.NullValue;
import oracle.jbo.domain.Number;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.jdbc.driver.OracleTypes;
public class TraePolizasViewImpl extends ViewObjectImpl {
private static final String SQL = "begin ? := PKG_PRUEBA.trae_polizas(?);end;";
private static final String COUNTSQL = "begin ? := PKG_PRUEBA.count_trae_polizas(?);end;";
public TraePolizasViewImpl() {
protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
BigDecimal rut_contratante = null;
Object[] theUserParam = null;
System.out.println(params);
System.out.println(params[0]);
if (params != null)
theUserParam = (Object[]) params[0];
//if (theUserParam != null && theUserParam.length > 0 )
if (! (theUserParam[1] instanceof NullValue) )
rut_contratante = (BigDecimal)theUserParam[1];
storeNewResultSet(qc ,retrieveRefCursor(qc, rut_contratante));
super.executeQueryForCollection(qc, params, numUserParams);
protected void create() {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
rs = getResultSet(qc);
ViewRowImpl r = createNewRowForCollection(qc);
try {
populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
populateAttributeForRow(r,1, rs.getString(2));
catch (SQLException s) {
throw new JboException(s);
return r;
protected boolean hasNextForCollection(Object qc) {
ResultSet rs = getResultSet(qc);
boolean nextOne = false;
try {
nextOne = rs.next();
if (!nextOne) {
setFetchCompleteForCollection(qc, true);
rs.close();
catch (SQLException s) {
throw new JboException(s);
return nextOne;
protected void releaseUserDataForCollection(Object qc, Object rs) {
ResultSet userDataRS = getResultSet(qc);
if (userDataRS != null) {
try { userDataRS.close(); }
catch (SQLException s) { ; }
super.releaseUserDataForCollection(qc, rs);
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
return viewRowSet.getRowCount();
private ResultSet retrieveRefCursor(Object qc, BigDecimal rut_contratante) {
CallableStatement st = null;
try {
st = getDBTransaction().createCallableStatement(SQL, DBTransaction.DEFAULT);
st.registerOutParameter(1,OracleTypes.CURSOR);
if (rut_contratante == null)
st.setNull(2, Types.NUMERIC);
else
st.setBigDecimal(2, rut_contratante);
st.execute();
ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
rs.setFetchSize(getFetchSize());
return rs ;
catch (SQLException s) {
throw new JboException(s);
finally {try {st.close();} catch (SQLException s) {;}}
private void storeNewResultSet(Object qc, ResultSet rs) {
ResultSet existingRs = getResultSet(qc);
if (existingRs != null) {
try {existingRs.close();} catch (SQLException s) {;}
setUserDataForCollection(qc,rs);
hasNextForCollection(qc); // Prime the pump with the first row.
private ResultSet getResultSet(Object qc) {
return (ResultSet)getUserDataForCollection(qc);
private static Number nullOrNewNumber(BigDecimal b) {
try {
return b != null ? new Number(b) : null;
catch (SQLException s) { ; }
return null;
public BigDecimal getprutcontratante() {
return (BigDecimal)getNamedWhereClauseParam("prutcontratante");
public void setprutcontratante(BigDecimal value) {
setNamedWhereClauseParam("prutcontratante", value);
}no?
-
I have following package specification ,
create or replace
PACKAGE "DATA_LKUP"
IS
TYPE BILL_POL IS RECORD
(v1 NUMBER,
V2 NUMBER,
V3 VARCHAR2(30))
TYPE R_POL_RC IS REF CURSOR
RETURN BILL_POL;
PROCEDURE P_GET_BEN_POL(V_ref_coursor IN OUT R_POL_RC,
N_KEY1_IN NUMBER,
N_KEY2_DT_IN NUMBER,
N_VAR OUT NUMBER);
END;
I have to write one general script to test procedures like P_GET_BEN_POL,
which has ref coursor as OUT parameter. I can write SQL script in following way.
DECLARE
T1 NUMBER;
T2 IS REF CURSOR;
BEGIN
DATA_LKUP.P_GET_BEN_POL(t2,1,2,t1);
dbms_output.put_line('Data 1 ==>>'||t1);
END;
But how do I test output variable T2, How do I print it? or is there any way to know structure of t2 so that I can print data of
ref cursor in following foramt?
Data:
col1 col2 col3 col4
as if I don't know package specification code.
I want to design such sql test scripts in general way, to test above procedures.You can build upon this example:
SQL> create or replace procedure test_refcur(rc OUT sys_refcursor) is
2 begin
3 open rc for select * from scott.emp ;
4 end ;
5 /
show errors
variable rc refcursor
exec test_refcur(:rc) ;
print rc
Procedure created.
SQL> No errors.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL>
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> -
REF Cursor to be called via Reports 6i to display data
Hello Sir/Madam,
I'm new to REF Cursor, so I would appriciate your help..
My requirements are to display records higher then nine records for a given facilityID from the REGSTATVLVS table sorted by vlv_nbr (field)
So far, I have Icreated a package and when I execute this package it is prompting
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'LSTVLV_REFCUR'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Note: I can display the data using "rownum", but that is not allowing me to sort it by valve#..
Sorry for redundancy for redency
CREATE OR REPLACE package GFS_ADMIN.vlvlst is
type v_cursor is REF CURSOR return REGSTATVLVS%rowtype;
PROCEDURE lstvlv_refcur(vlvno OUT v_cursor);
end;
CREATE OR REPLACE package body vlvlst is
PROCEDURE lstvlv_refcur(vlvno OUT v_cursor) IS
vlv_num varchar2(1000);
cursor vlv_cur is
select vlv_nbr
from REGSTATVLVS r
where r.fclty_seq_nbr = 83
order by vlv_nbr;
vlv_rcd vlv_cur%rowtype;
begin
if not vlv_cur%isopen then
open vlv_cur;
end if;
<<i_loop>> for i in 1..40 loop
fetch vlv_cur into vlv_rcd;
EXIT WHEN vlv_cur%NOTFOUND;
if ( i <= 9 ) then
vlv_num := vlv_rcd.vlv_nbr;
dbms_output.put_line(vlv_num);
-- dbms_output.put_line(vlv_rcd.vlv_nbr);
end if;
end loop;
end;
end;
variable v1 varchar2(6);
set serveroutput on
set autoprint on
execute vlvlst.lstvlv_refcur(:v1);
Regards,
VaniHello InoL,
REF Cursor is working better if it is a Navigator, Toad or SQLPlus.. but it is prompting all sort of errors when it is used within Reports 6i.. Here is what i was trying to achieve..
The purpose of "REF Cursor" is to retrieve multiple parameter values .. ( at least that is what GOOGLE results were about REF Cursor )..
At the same time, a function does not return more then one value and I'm not sure if Reports will allow to use a stored procedure. So, I started to use REF Cursor
"lstvlv_refcur(vlvno OUT v_cursor )" I'm trying to retrieve as I mentioned 9 valve records to one report and remaining valve records to 2nd report, which I'm calling it via SRW reports built-in package..
Here is the latest and greatest code on my REF Cursor..
1) created "global temporary table" one time..
2) within Reports added this package ( as a program unit )
package vlvlst_chk is
type vlvlst_rcd is RECORD
( fctly_seq_nbr number,
vlv_nbr varchar2(6));
type vlvno_refcur is REF CURSOR return vlvlst_rcd;
end;
3) then added a function called QR_1RefCurDS ( as a program unit )
function QR_1RefCurDS return vlvlst_chk.vlvno_refcur is
hld_vlvlst vlvlst_chk.vlvno_refcur;
fctno INTEGER;
vno varchar2(6);
begin
delete from fct_vlv_hold;
commit;
delete from fct_vlv_hold2;
commit;
open hld_vlvlst for
select r.fclty_seq_nbr,r.vlv_nbr
from REGSTATVLVS r
where r.fclty_seq_nbr = :p_2
order by vlv_nbr;
for i in 1..40 loop
fetch hld_vlvlst into fctno, vno;
exit when hld_vlvlst%notfound;
if i <= 9 then
insert into fct_vlv_hold
values(fctno, vno);
commit;
-- return hld_vlvlst;
elsif (i>9 and i<= 40) then
insert into fct_vlv_hold2
values(fctno, vno);
commit;
-- return hld_vlvlst;
else
return hld_vlvlst;
end if;
end loop;
close hld_vlvlst;
return hld_vlvlst;
end;
Here: prompts "REP-0065/REP-0200" error, but writes records to temp tables..
Question is why is it prompting this error?
Edited by: user11141511 on Jan 24, 2012 1:25 PM
Edited by: user11141511 on Jan 24, 2012 1:27 PM -
How to fetch NO DATA FOUND exception in Ref Cursor.
In my procedure ref cursor is out parameter with returns dataset. in my proceudre
its like...
OPEN pPymtCur FOR
select.....
when I call this procedure from report to get dataset it causes NO DATA FOUND exception.
How to fetch this exception in my oracle procedure so I can get some other data.
Any Idea to do this?
Edited by: Meghna on 17-Jun-2009 22:28Mass25 wrote:
Correct me if I am wrong.
So if I do something as follows in my stored proc, I do not have to check for NO_DATA_FOUND?
OPEN my_CuRSR FOR
SELECT DISTINCT blah blah blahmy_cursr is what I am returning as OUT param in my SP.Correct. At the point you open the cursor, oracle has not attempted any 'fetch' against the data so it won't know if there is any data or no data. that only occurs when a fetch is attempted.
Take a read of this:
[PL/SQL 101 : Understanding Ref Cursors|http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0] -
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;
}
Maybe you are looking for
-
Time Machine worked- with caveats- but worked
Ok, TIme Machine rocks! I screwed with some applications, I tried to make the dock and desktop my own and F'd things up. What I was trying to do was to create stacks in doc. I wanted stacks for apple apps, stacks for business apps, stack for art, and
-
JTable in JScrollPane auto resize refresh problem
Hello, I have a JTable in a JScrollPane. Number of rows is changing. I'm using the following to auto-resize JScrollPane. public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.height -= getVi
-
How to wait until all components painted?
Hi - I have searched for hours for an answer to this and have yet to find something so any help is much appreciated! Ive posted some code below to simulate the problem im facing. This is a simple frame which has a couple of custom jPanels embedded wi
-
I've a very important document which I can't open anymore: You need a newer version of Numbers to open this spreadsheet.
-
Wir nutzen Querverweise ("als Textvariable") in Text-Seitenverweisen (also z. Bsp. "siehe Seite...") um sicherzustellen, dass die Seitenzahl im Text sich ändert, sofern (im/in Dokument/en [also auch dokumentübergreifend]) Seiten eingefügt oder gelösc