STORED PROCEDURE/REF CURSOR: How to output entire buffer
I wrote a Stored Procedure wherein I use a Cursor to extract multiple
rows and columns. I then write them into the buffer
(dmbs_output.put_line). But when I try to capture the entire result
into an OUT variable, I only get the last buffered line.
So how do I output the entire buffer- all rows and columns? In other words (maybe), how do I use dbms_output.get_lines() to assign value to an OUT variable?
Alternatively, using REF CURSOR as OUT variable, I added the following to "CREATE OR REPLACE PROCEDURE ... ()":
cursor_out_test OUT cursor_test
But when I tried:
DEFINE CURSOR TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
...or...
DECLARE TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
I still got syntax errors.
In one line, what I am trying to do is break the result array at the database level rather than at the application level.
Cheers, Bill
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#LNPLS00605
I did the following:
OPEN CURSOR x
LOOP
FETCH CURSOR x INTO col1, col2
(EXIT WHEN...)
variable_line := col1 || col2
END LOOP
CLOSE CURSOR
But after closing this cursor, variable_line contains only the last buffered line. I want all the looped lines (without using associative arrays, nested tables etc). So I guess I am just looking for some way to append data lines- adding chr(10) doesn't work either.
Cheers, Bill
Similar Messages
-
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?
-
Stored procedure - ref cursor - no rows
Hello,
I am stumped. Hopefully another pair of eyes will see what mine cannot. I am calling a stored procedure that accepts a single output parameter [the proc has been dumbed down to limit variables of my problem] that is a ref cursor. When I make the call I get now data. I have used both adapter and datareaders. If I call the proc from another proc I can loop through the results. I am including the code of my c# function and the stored proc.
The version number of my Oracle.DataAccess.dll is 10.1.0.303.
** Stored Proc ***********************
TYPE refcursor is ref cursor ;
procedure P_CUSTOMER_INFO_GET_SLIM( thecur out refcursor )
is
begin
open thecur for
select *
from customer_info
where rownum < 21;
end P_CUSTOMER_INFO_GET_SLIM;
** C# Func ***************************
private DataSet _FetchCustomerData2(string CustNbr, string ShipToSuffix)
string sc = "PKG_CUSTOMER_CONTACT.P_CUSTOMER_INFO_GET_SLIM";
OracleConnection con = new OracleConnection(_Database.GetConnection().ConnectionString);
OracleCommand cmd = new OracleCommand(sc, con);
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
// must pass strings with data
if (CustNbr.Length==0 || ShipToSuffix.Length==0)
return null;
try
// we are calling a stored proc so set it
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("thecur", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
da.Fill(ds, "Customer"); // no data ?????????????????
// Close and Dispose OracleConnection object
con.Close();
con.Dispose();
return ds;Hey all,
I ended up declaring a variable in the proc as refcursor and opening it. Then I assigned the out parameter ref cursor to the variable. That took care of it. See below.
Thanks,
Mike
procedure P_CUSTOMER_INFO_GET(
CustomerNumber in varchar2
,ShipToSuffix in varchar2
,thecur out refcursor
is
-- variable declarations
mycur refcursor;
begin
open mycur for
select CORP_CODE
,CUST_NUMBER
,CUST_SHIP_TO_SFFX
,CUST_BILL_TO_SUFF
,CUST_AR_OFF_CODE
,CUST_NAME
,CUST_SHIP_BILL_IND
,CUST_SHIP_VIA_CODE
,CUST_CLASS_CODE
,CUST_TYPE_CODE
,CUST_PRICE_CODE
,DISC_MKUP_CODE
,TRADE_DISC_CODE
,CUST_N_D_ACCT_NO
,CUST_PRY_PRICE_AGR
,CUST_ADDR_1
,CUST_ADDR_2
,CUST_ADDR_3
,CUST_CITY
,CUST_STATE
,CUST_ZIP
,CUST_COUNTRY_CODE
,CUST_FAX_NO
,CUST_FAX_NO_EXP
,CUST_PHONE_NO
,CUST_PHONE_NO_EXP
,CUST_CRDT_LIM_CODE
,CUST_CREDIT_STATUS
,CUST_CRED_CARD_NO
,CUST_CC_EXP_DATE
,CUST_DUNNING_FLAG
,CUST_ID
,CUST_SP_FILE_IND
,CUST_ST_TAX_CODE
,LAST_MAINT_DATE
from customer_info
where CUST_NUMBER = CustomerNumber
and CUST_SHIP_TO_SFFX = ShipToSuffix;
-- send the cursor back
thecur := mycur; -
Got my REF CURSOR, how to output?
I started with this code:
Re: find first record in the tree
and get the dbms_output I'm looking for. What I don't understand is how to get the output into the refcursor OUT. I've read about FETCH INTO variables, but how does that get to the REF?
There is an Oracle Form calling this procedure, if that makes any difference.Here an example of an stored procedure with REF CURSOR output
CREATE OR REPLACE PROCEDURE Test_Proc
(pIPI_EmpId IN PLS_INTEGER,
pORC_RefCur OUT SYS_REFCURSOR)
IS
BEGIN
OPEN pORC_RefCur FOR
SELECT Employee_Name
FROM Employee
WHERE Employee_Id = pIPI_EmpId;
END Test_Proc;
Calling the procedure from Oracle Form
DECLARE
vRC_RefCur SYS_REFCURSOR;
vT_Employee Employee.Employee_Name%TYPE;
BEGIN
Test_Proc(Form.Block.Employee_Id, vRC_RefCur);
LOOP
FETCH vRC_RefCur INTO vT_Employee;
EXIT WHEN vRC_RefCur%NOTFOUND;
Form.Block.Employee_Name := vT_Employee;
END LOOP;
END; -
Forms Data-Block based on stored procedures - REF CURSOR feature NOT FUNCTIONING
This topic is related to another topic in this forum titled "FORMS HOW TO SET QUERY SOURCE ARGUMENTS??" I posted my message there as well. I am posting as a NEW TOPIC so that it catches the attention of Oracle Support.
I built a data form based on a stored procedure and REF CURSOR IN OUT parameter.
My procedure takes a IN parameter to fill in the criteria for the OPEN <cursor_variable> select ... where ... statement.
In the Value setting of the Query source Arguments , I set the VALUE to ":BLOCK_NAME.ITEM_NAME" at design time to supply the input value to the procedure. this works to the extent of making available the form item value to the stored procedure parameter. I verified this by doing an insert into some debug table , of the incoming parameter value inside my stored procedure.
The cursor gets opened properly into the REF cursor variable. I verified this by fetching a record into a local variable and inserting the value into a debug table again in the stored procedure.
(I took care to close and re-open the REF cursor variable again - so that the front-end can continue to fetch it from the first record. )
***** PROBLEM **************
But the front end forms runtime is giving me a FRM-40301 - query returned no records even though the REF cursor is returned properly opened.
Did anybody else face the same problem ??
Please post what you found.
Thanks,
Shankaran
nullThis topic is discussed at length in another thread "How Set Value For Query DataSource Arguments?"
But I am posting the findings here as well.
THIS TOPIC IS CLOSED.
My Bad. The problem Cause : I did not include all columns in the
cursor rowtype in the Data-block. In the wizard for the data block , I selected ONLY the columns that I needed. But I was doing a Select * from <my_table> in my open cursor <Cursor-Variable> .... The <Cursor Variable>
itself was declared <my_table>%rowtype
FIX : The Data Block structure (columns included as items) should match the cursor record Structure. One may or may not
display all the columns in the LAYOUT though.
But I don't understand why it gives such a misleading message like FRM-40301 Query retrieved no records. Oracle Team fix it.
Hope this helps people who face the same problem.
Thanks, -
Oracle OLE DB Provider / Stored Procedure REF CURSOR errror
Post Author: robfurrball
CA Forum: Data Connectivity and SQL
All,I'm out of ideas on this and would appreciate any suggestions.I'm trying to use Crystal XI to connect to an Oracle 9i database using the Oracle OLE DB Provider (required to use this provider by a 3rd party program that fires off the report).If I connect using the Microsoft OLE DB Provider for Oracle, the report will return data. When connecting with the Oracle OLE DB Provider, I get the following:Database Connector Error: 'ADO Error Code: 0x80040e14
Source: OraOLEDB
Description: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_MOMGLOBCSHBAL_TEST'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Native Error: 6550 [Database Vendor Code: 6550 ]' -
The procedure's only parameter is an IN OUT SYS_REFCURSOR, and the Oracle OLE DB Provider is version 9.2.0.7.0 Thanks,RobPost Author: robfurrball
CA Forum: Data Connectivity and SQL
Summary: After going
back and forth with Business Objects support they ruled that it was an issue
with the provider itself, recommended I contact Oracle for resolution, and
closed the case before I could comment back to them. I was unable to send this response to their
support team, so I'm posting it here in hopes that I can save others time/money
in the future.
My Response -
I appreciate your input and would have liked to comment further on the case management system before you closed the case. I'm a little surprised and disappointed that you recommend I contact Oracle directly about this issue.I would imagine that a company as large as Business Objects would have much better results dealing with Oracle to resolve an issue compared to an individual.Also, since you are able to connect to other objects (such as a table) in Crystal Reports using that provider, I would expect that you would want customers to be able to connect to stored procedures using it as well. Otherwise, it would seem appropriate to either alert customers of this defect through documentation, public message boards, and forums.Using Crystal to pull data from stored procedures in other databases and data providers made me think that was a viable option for this project. Since it was not documented as a limitation of Crystal and the provider, it has cost my organization a great deal of time and money trying to troubleshoot an issue I would have expected to be caught in Crystal Reports' internal quality assurance testing.------ This is the final note I received on my support case: -
Please note that the statement used to execute a procedure within ODBC/OLE DB is different from the native 'Oracle Server' statement.In ODBC or OLE DB, the call is '{CALL "SCHEMANAME"."TEST_PROCEDURE"(3)}' , when using native 'Oracle Server' the call is 'BEGIN "SCHEMANAME"."TEST_PROCEDURE"(:TEST_CURSOR, 1); END ;'In ODBC or OLE DB, the cursor is still used however it is not listed within the SQL Statement as in the Native connection. This is the behavior from Crystal Reports 9 forward that the cursor is not shown through ODBC/OLE DB.In addition to that as the issue is only with the Oracle OLE DB provider and I would suggest you to contact Oracle about this issue, since the issue occurs outside of Crystal Reports when using QTADO with a standard call, so it is not an issue between Crystal Reports and Oracle.The issue is only with Oracle OLE DB provider as the same Oracle stored procedure call works within QTADO with the MS Oracle OLE DB provider.As the issue is with the OLE DB Provider and not with Crystal Reports, we may not be able to proceed further. Hence, I am closing this case from Case Management System. -
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 -
Stored procedure with cursor as output param
It's the first time for me to test a stored procedure with a cursor as output parameter. I executed the following:
SQL> VARIABLE user_cur REFCURSOR; VARIABLE ret_code VARCHAR2; exec TEST_API.SEARCH_USER( :ret_code, '', '', 'john', '', :user_cur); print ret_code;print user_cur;
I got the following error:
Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
VARCHAR2 (n CHAR) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR ] ]
May I know what's the problem?
The purpose of the stored procedure is to search for user with the name "john".
The stored procudure input/output params declaration is as follows:
PROCEDURE SEARCH_USER
RETURN_CODE OUT VARCHAR2,
USER_ID_IN IN VARCHAR2,
POSITION_IN IN VARCHAR2,
USERNAME_IN IN VARCHAR2,
STATUS_IN IN VARCHAR2,
USER_CUR_OUT OUT REFCURSOR
Edited by: user7383310 on Oct 19, 2008 9:05 PM
Edited by: user7383310 on Oct 19, 2008 9:05 PMfor the usage of refcursors in pl/sql refer here..
http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10807/06_ora.htm#sthref808
You can code like..
SQL> create or replace procedure p1(id number,csr out sys_refcursor) is
2 begin
3 open csr for select ename from emp where deptno = id;
4 end;
5 /
Procedure created.
SQL> var csr1 refcursor
SQL> var n number
SQL> exec :n := 30;
PL/SQL procedure successfully completed.
SQL> exec p1(:n,:csr1);
PL/SQL procedure successfully completed.
SQL> print csr1
ENAME
ALLEN
WARD
MARTIN
BLAKE
TURNER
JAMES
6 rows selected. -
How to use a parameter passed to stored procedure in cursor?
I am rather new to Oracle stored procedures and I'm sure that
this is rather simple. Could someone tell me how to do the
following: I would like to pass the variable status into my
stored procedure and then use it in the where clause when
defining my cursor. I have the stored procedure working 100%
other than this small detail.
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like '&status'
END;
Thank youI am rather new to Oracle stored procedures and I'm sure that
this is rather simple. Could someone tell me how to do the
following: I would like to pass the variable status into my
stored procedure and then use it in the where clause when
defining my cursor. I have the stored procedure working 100%
other than this small detail.
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like '&status'
END;
Thank you You can do something like this
CREATE OR REPLACE PROCEDURE p_report_starwood_exhibita2(hno
VARCHAR2, cid INTEGER, kperiod INTEGER, status VARCHAR2, user
VARCHAR2) IS
BEGIN
DECLARE
CURSOR bid_cursor (p_status varchar2) IS
SELECT bm.hotelid
FROM dbo.bidmaster bm
WHERE bm.channelid = cid
and bm.contractperiod = kperiod
and bm.bidstatus like p_status
END;
and then in the BEGIN section do
open bid_cursor(status)
This should work.
Regards
Manoj -
Ref Cursor - How to append records into ref cursor?
Hi,
Is it possible to append ref cursor?
Iam having a procedure which accepts 1 string as input
parameter. That string will have list of ID delimited by comma.
I want to extract & match every ID with some tables.
My problem is for first ID i would get 10 records
and for 2nd ID i 'l get other 20 records. But while returning
i need to send the same(10 + 20 records) as ref cursor(OUT parameter).
But in below given code i could send only last 20 records. first
10 records are not append/updated into ref cursor.
How to append 2nd 20 records with 1st 10 records? so that i can
send all the 30 records.
Here goes my code...
CREATE OR REPLACE PROCEDURE getCRMGroupsAndRollups_PRC
in_groupId IN VARCHAR2,
out_getCRMGroups OUT TYPES.DATASET
IS
v_temp VARCHAR2(500) := in_groupId ||',';
v_temp_split VARCHAR2(500);
v_pos1 NUMBER := 0;
v_pos2 NUMBER := 1;
v_pos3 NUMBER := 0;
v_extract_char VARCHAR(1) := NULL;
v_comma_cnt NUMBER := 0;
BEGIN
-- check in for null input parameters
IF ( in_groupId IS NOT NULL ) THEN
-- loop to count no of in_groupId
FOR j IN 1..LENGTH(v_temp)
LOOP
v_extract_char := SUBSTR(v_temp,j,1);
IF (v_extract_char = ',') THEN
v_comma_cnt := v_comma_cnt + 1;
END IF;
END LOOP;
-- loop to extract in_group Id
FOR i IN 1..v_comma_cnt
LOOP
v_pos1 := instr(v_temp,',',(v_pos1 + 1));
v_pos3 := ((v_pos1-1) - v_pos2 )+ 1;
v_temp_split := SUBSTR(v_temp,v_pos2,v_pos3);
v_pos2 := v_pos1 + 1;
-- query to return dataset filled BY list of all the current
-- CRM groups and the associated rollup groups
OPEN out_getCRMGroups FOR
SELECT
DISTINCT
gcs.crm_st_id_cd,
gcs.lgcy_roll_up_grp_num,
gcs.lgcy_roll_up_grp_name,
gcs.grp_xwalk_complt_dt,
gcs.crm_grp_num,
gcs.facets_gnat_id,
gcs.crm_grp_name
FROM
grp_convsn_stat gcs
--lgcy_xref_elem lxe
WHERE
( gcs.mbrshp_convsn_aprvl_dt = NULL )
OR ( gcs.mbrshp_convsn_aprvl_dt < (SYSDATE - 7 ) )
AND ( gcs.facets_grp_stat_actv_ind = 'Y' )
AND ( gcs.lgcy_roll_up_grp_num = v_temp_split );
END LOOP;
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('INTERNAL ERROR');
END getCRMGroupsAndRollups_PRC;
in this v_temp_split will have extracted id & iam opening
ref cursor for each & every ID extracted from list.
2) How to handle no_data_found exception for this ref cursor?
Please help me....
-thiyagarajan.http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
Message was edited by:
Kamal Kishore -
Error when stored procedure returns cursor in pro c
Hi
I was trying to make work the stuff explained at
[m-2537153]
It executes a stored procedure from pro c that returns a cursor.
But when i compllie at pro c I get following error. My procedure name is TEST.
If i change the output parameter to a int value. It compiles ok.
PLS-S-00306, wrong number or types of arguments in call to 'TEST'
Error at line 34, column 5 in file E:\C\Test\tt.pc
TEST(:test_cursor);
+....1+
PLS-S-00000, Statement ignored
Semantic error at line 33, column 1, file E:\C\Test\tt.pc:
BEGIN
+1+
PCC-S-02346, PL/SQL found semantic errors
Can any one point out what could be the error?
I am working from oracle 8i client. which connects to oracle 9.0.1.
OS is win 2000 sp4This is my code
int main(int argc, char** argv)
+{+
EXEC SQL BEGIN DECLARE SECTION;
char user[]="scott";
char pwd[]="tiger";
char server[]="testdb";
char msg_buf[51|http://forums.oracle.com/forums/]+="";+
int intarg1;
int intId;
char strName[]="";
SQL_CURSOR tcr;
EXEC SQL END DECLARE SECTION;
+/* Register sql_error() as the error handler. */+
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error\n");
EXEC SQL CONNECT :user IDENTIFIED BY :pwd USING :server;
Printf("Connected to %s successfully",server);
EXEC SQL ALLOCATE :tcr;
EXEC SQL EXECUTE
BEGIN
TEST(:tcr);
END;
END-EXEC;
Procedure name is TEST and it like
CREATE OR REPLACE PROCEDURE TEST (crsdata out sys_refcursor)
as
BEGIN
open crsdata for select id,name from newtab;
END; -
Stored procedure: nested cursor problem
Hey folks,
i am really having a hard time trying to figure out how nested cursors work.
What i want to do:
-> Do one select statement and process the yielded rows with one cursor
-> Do another select statement depending on the first cursor
The code is quite simple, the beginning of the stored procedure is:
create or replace
PROCEDURE extractEntireMD IS
CURSOR curTemplateUnitId IS
SELECT
tu.externalident,
tu.templateunitid
FROM
templateunit tu
WHERE
tu.templateunitid = 100007;
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
SELECT
tpt.parttypeid
FROM
templateparttype tpt
WHERE
tpt.templateunitid = templateUnitID;
From what i have read, this seems to be right.
No i want to use this code like this:
BEGIN
FOR valInCurTemplateUnitId IN curTemplateUnitId LOOP
DBMS_OUTPUT.PUT_LINE('ExtIdent: ' || valInCurTemplateUnitId.externalident);
DBMS_OUTPUT.PUT_LINE('templateunitid: ' || valInCurTemplateUnitId.templateunitid);
FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid) LOOP
DBMS_OUTPUT.PUT_LINE('PartTypeId: ' || valIncurPartTypeId.parttypeid);
END LOOP;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No such data ');
END;
The problem:
I seem to be doing something wrong, because Oracle does not heed the argument which i give to the second cursor from the first cursor:
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
which i call via:
FOR valIncurPartTypeId IN curPartTypeId(valInCurTemplateUnitId.templateunitid)
Instead, oracle prints out __all__ templateunitids.
If I modify the second cursor with a constant argument like this:
CURSOR curPartTypeId(templateUnitID IN varchar2) IS
SELECT DISTINCT
tpt.parttypeid
FROM
templateparttype tpt
WHERE
tpt.templateunitid = 100007;
The result is correct. So it seems like oracle simply disregards the parameter i am giving him for the second cursor.
What am i doing wrong?> i am really having a hard time trying to figure out how nested cursors work.
Good. I trust that this will result in the realisation that it is an idiotic thing to emulate the features of the SQL engine in PL/SQL. Only a fool thinks the he/she can outprogram and outsmart the SQL engine, and do things like nested loop joins better and faster in PL/SQL.
Use SQL for the purpose it was designed. Use PL/SQL for the purpose it was designed.
Joining of data? That is prime function and feature of SQL. Not PL/SQL. -
JCA Error while calling Stored Procedure containing cursors in BPEL/OSB
Hi,
I created JCA DBAdapter in Jdeveloper for calling remote stored procedure which contains cursors as OUT parameters.
I'm getting below exception when i try to call the database via BPEL/OSB.the same remote procedure call is working on Invoking with WLI .
Kindly sugggest !!!
The invocation resulted in an error: I*nvoke JCA outbound service failed with connection error, exception: com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/ServiceBus/BusinessServices/IsdnSiebelConn [ IsdnSiebelConn_ptt::IsdnSiebelConn(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'IsdnSiebelConn' failed due to: Get object error.*
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
*; nested exception is:*
BINDING.JCA-11810
Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
Check to ensure that the parameter has been correctly registered as a valid IN/OUT or OUT parameter of the API. This exception is considered retriable, likely due to a communication failure. To classify it as non-retriable instead add property nonRetriableErrorCodes with value "0" to your deployment descriptor (i.e. weblogic-ra.xml). To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff. All properties are integers.
com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/ServiceBus/BusinessServices/IsdnSiebelConn [ IsdnSiebelConn_ptt::IsdnSiebelConn(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'IsdnSiebelConn' failed due to: Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
; nested exception is:
BINDING.JCA-11810
Get object error.
Error retrieving the value of a parameter R_NON_CNF_ATTR_CURSOR.
An error occurred when retrieving the value of parameter R_NON_CNF_ATTR_CURSOR after invoking the SIEBEL.ISDN_OBT_INS_DET.OBTAINASSETDETAILS API. Cause: java.sql.SQLException: Cursor is closed.
Check to ensure that the parameter has been correctly registered as a valid IN/OUT or OUT parameter of the API. This exception is considered retriable, likely due to a communication failure. To classify it as non-retriable instead add property nonRetriableErrorCodes with value "0" to your deployment descriptor (i.e. weblogic-ra.xml). To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff. All properties are integers.
at com.bea.wli.sb.transports.jca.binding.JCATransportOutboundOperationBindingServiceImpl.invoke(JCATransportOutboundOperationBindingServiceImpl.java:153)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.sendRequestResponse(JCATransportEndpoint.java:209)
at com.bea.wli.sb.transports.jca.JCATransportEndpoint.send(JCATransportEndpoint.java:170)
at com.bea.wli.sb.transports.jca.JCATransportProvider.sendMessageAsync(JCATransportProvider.java:571)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.wli.sb.transports.Util$1.invoke(Util.java:83)
at $Proxy127.sendMessageAsync(Unknown Source)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageAsync(LoadBalanceFailoverListener.java:148)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToServiceAsync(LoadBalanceFailoverListener.java:603)
at com.bea.wli.sb.transports.LoadBalanceFailoverListener.sendMessageToService(LoadBalanceFailoverListener.java:538)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageToService(TransportManagerImpl.java:558)
at com.bea.wli.sb.transports.TransportManagerImpl.sendMessageAsync(TransportManagerImpl.java:426)
at com.bea.wli.sb.test.service.ServiceMessageSender.send0(ServiceMessageSender.java:377)
at com.bea.wli.sb.test.service.ServiceMessageSender.access$000(ServiceMessageSender.java:76)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:134)
at com.bea.wli.sb.test.service.ServiceMessageSender$1.run(ServiceMessageSender.java:132)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at com.bea.wli.sb.security.WLSSecurityContextService.runAs(WLSSecurityContextService.java:55)
at com.bea.wli.sb.test.service.ServiceMessageSender.send(ServiceMessageSender.java:137)
at com.bea.wli.sb.test.service.ServiceProcessor.invoke(ServiceProcessor.java:454)
at com.bea.wli.sb.test.TestServiceImpl.invoke(TestServiceImpl.java:172)
at com.bea.wli.sb.test.client.ejb.TestServiceEJBBean.invoke(TestServiceEJBBean.java:167)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl.invoke(TestService_sqr59p_EOImpl.java:353)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:174)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:345)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at com.bea.wli.sb.test.client.ejb.TestService_sqr59p_EOImpl_1033_WLStub.invoke(Unknown Source)
at com.bea.alsb.console.test.TestServiceClient.invoke(TestServiceClient.java:174)
at com.bea.alsb.console.test.actions.DefaultRequestAction.invoke(DefaultRequestAction.java:117)
at com.bea.alsb.console.test.actions.DefaultRequestAction.execute(DefaultRequestAction.java:70)
at com.bea.alsb.console.test.actions.ServiceRequestAction.execute(ServiceRequestAction.java:143)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.access$201(PageFlowRequestProcessor.java:97)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor$ActionRunner.execute(PageFlowRequestProcessor.java:2044)
at org.apache.beehive.netui.pageflow.interceptor.action.internal.ActionInterceptors.wrapAction(ActionInterceptors.java:91)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processActionPerform(PageFlowRequestProcessor.java:2116)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.processActionPerform(SBConsoleRequestProcessor.java:91)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.processInternal(PageFlowRequestProcessor.java:556)
at org.apache.beehive.netui.pageflow.PageFlowRequestProcessor.process(PageFlowRequestProcessor.java:853)
at com.bea.alsb.console.common.base.SBConsoleRequestProcessor.process(SBConsoleRequestProcessor.java:191)
at org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.process(AutoRegisterActionServlet.java:631)
at org.apache.beehive.netui.pageflow.PageFlowActionServlet.process(PageFlowActionServlet.java:158)
at com.bea.console.internal.ConsoleActionServlet.process(ConsoleActionServlet.java:256)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at com.bea.console.internal.ConsoleActionServlet.doGet(ConsoleActionServlet.java:133)
at com.bea.alsb.console.common.base.SBConsoleActionServlet.doGet(SBConsoleActionServlet.java:49)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1199)
at org.apache.beehive.netui.pageflow.PageFlowUtils.strutsLookup(PageFlowUtils.java:1129)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.executeAction(ScopedContentCommonSupport.java:687)
at com.bea.portlet.adapter.scopedcontent.ScopedContentCommonSupport.processActionInternal(ScopedContentCommonSupport.java:142)
at com.bea.portlet.adapter.scopedcontent.StrutsStubImpl.processAction(StrutsStubImpl.java:76)
at com.bea.portlet.adapter.NetuiActionHandler.raiseScopedAction(NetuiActionHandler.java:111)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:181)
at com.bea.netuix.servlets.controls.content.NetuiContent.raiseScopedAction(NetuiContent.java:167)
at com.bea.netuix.servlets.controls.content.NetuiContent.handlePostbackData(NetuiContent.java:225)
at com.bea.netuix.nf.ControlLifecycle$2.visit(ControlLifecycle.java:180)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:324)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walkRecursive(ControlTreeWalker.java:334)
at com.bea.netuix.nf.ControlTreeWalker.walk(ControlTreeWalker.java:130)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:395)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:361)
at com.bea.netuix.nf.Lifecycle.processLifecycles(Lifecycle.java:352)
at com.bea.netuix.nf.Lifecycle.runInbound(Lifecycle.java:184)
at com.bea.netuix.nf.Lifecycle.run(Lifecycle.java:159)
at com.bea.netuix.servlets.manager.UIServlet.runLifecycle(UIServlet.java:388)
at com.bea.netuix.servlets.manager.UIServlet.doPost(UIServlet.java:258)
at com.bea.netuix.servlets.manager.UIServlet.service(UIServlet.java:199)
at com.bea.netuix.servlets.manager.SingleFileServlet.service(SingleFileServlet.java:251)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.AsyncInitServlet.service(AsyncInitServlet.java:130)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)You need to open all the cursors in the PLSQL ie., cursors should be initialized in your PLSQL package. JCA DB Adapter tries to open the cursor without checking whether its there or not..If you cant change the PLSQL package, raise a SR with Oracle for a patch.This would be considered as Enhancement Request.
Regards
Sesha -
Stored procedure with cursor as out parameter
Can any one help me by showing how to write a procedure with cursor as out parameter and caputuring it in java using jdbc.
Thanks in advance,
shravan bharadwajI know that in the SQLJ distribution (which is also downloadable) there is an example in the demo directory called RefCursDemo that shows the SQL code and how to call it - albeit from SQLJ and not JDBC. There may also be a demo in the JDBC distribution, though I am not sure about that.
-
Ref Cursor - how to access through parameter name
Hi,
I'm using the below table and sample data. The below script named 'Script1' works well, my concern is values for the first and second parameters need to be used for the thrid and fourth one as well.
When I try with 'Script2' it gives "ORA-01008: not all variables bound ORA-06512: at line 17" error. I know Paramterized cursor can handle this effecively, since it is a dynamic SQL, I need to use from a parameter table, I don't have any control over the number of parameteters, parameter name, type and other things. So, I cannot go for parameterized cursor.
As of now, for my requirement, Script1 works fine, is there any way to make Script2 to work as well, I need to pass paramters by name, not by position, please give your suggestions, thank you.
CREATE TABLE T1
F1 NUMBER(5),
F2 VARCHAR2(100),
F3 DATE
Insert into T1
(F1, F2, F3)
Values
(1, 'One', TO_DATE('08/02/2012 07:43:34', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T1
(F1, F2, F3)
Values
(2, 'Two', TO_DATE('08/02/2012 08:15:24', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T1
(F1, F2, F3)
Values
(3, 'Three', TO_DATE('08/02/2012 08:16:34', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
Script1:
declare
TYPE t_ref_cursor IS REF CURSOR;
v_cursor t_ref_cursor;
v_query_str varchar2(3000);
v_f1 number(5);
v_f2 varchar2(100);
v_f3 date;
begin
v_query_str := 'SELECT f1, f2, f3 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss'') union ';
v_query_str := v_query_str || 'select 1, ''c1'', sysdate from dual where not exists (select 1 from t1 where f1 = :p3 and f3 = to_date(:p4, ''DD-MON-YYYY hh24:mi:ss''))';
--dbms_output.put_line(v_query_str);
open v_cursor for v_query_str using 1, '02-AUG-2012 07:43:34', 1, '02-AUG-2012 07:43:34';
loop
fetch v_cursor into v_f1, v_f2, v_f3;
exit when v_cursor%notfound;
dbms_output.put_line(v_f1 || ' ' || v_f2 || '' || v_f3);
end loop;
dbms_output.put_line('rowcount ' || v_cursor%rowcount);
close v_cursor;
end;
Script2:
declare
TYPE t_ref_cursor IS REF CURSOR;
v_cursor t_ref_cursor;
v_query_str varchar2(3000);
v_f1 number(5);
v_f2 varchar2(100);
v_f3 date;
begin
v_query_str := 'SELECT f1, f2, f3 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss'') union ';
v_query_str := v_query_str || 'select 1, ''c1'', sysdate from dual where not exists (select 1 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss''))';
--dbms_output.put_line(v_query_str);
open v_cursor for v_query_str using 1, '02-AUG-2012 07:43:34';
loop
fetch v_cursor into v_f1, v_f2, v_f3;
exit when v_cursor%notfound;
dbms_output.put_line(v_f1 || ' ' || v_f2 || '' || v_f3);
end loop;
dbms_output.put_line('rowcount ' || v_cursor%rowcount);
close v_cursor;
end;
/This link shall answer your Question. PL/SQL Dynamic SQL.
If it had been an Anonymous Block, your code would work through.
Please see demonstration below:
create or replace procedure emp_data (dep_id number, sal number, emp_id number)
is
l_cnt number;
begin
select count(*)
into l_cnt
from hr.employees
where department_id = dep_id
and salary >= sal
and employee_id > emp_id;
dbms_output.put_line('Count :: ' || l_cnt);
end;
declare
l_cnt number;
begin
execute immediate 'begin emp_data(:1, :2, :2); end;' using 20, 100;
end;
anonymous block completed
Count :: 2
--Trying the Similar example as in your OP.
--Execute the same Select statement as in emp_Data with Bind Variables;
declare
l_cnt number;
begin
--execute immediate 'begin emp_data(:1, :2, :2); end;' using 20, 100;
execute immediate 'select count(*)
from hr.employees
where department_id = :1
and salary >= :2
and employee_id > :2' into l_cnt using 20, 100;
dbms_output.put_line('Count :: ' || l_cnt);
end;
Results in error :- ORA-01008: not all variables bound
Maybe you are looking for
-
Did you know this was up on FB?
Did you know this was up on FB? https://www.facebook.com/events/1590846764481403/1593647247534688
-
Re: Impressão de Nota Fiscal - PLD - Lista de variáveis disponíveis
Franklin, Boa Tarde!! Você sabe qual é o campo do banco de dados ou a variavel que está a descrição do CFOP?? Eu uso a 1354, mas se é colocado mais de um produto vai repetindo a descrição. Já adianto que o campo está no cabeçalho e vai aparecendo a d
-
Pen Drive is not detected from my Solaris OS
Hello, from my Solaris 10 OS my pen drive is undetected .Please help how to detect my pen drive . The configuration of my system : 1) Solaris 10 Q) The OS is installed using VirtualBox , Host machine is Windows 7 ? Q) My pen drive is working with oth
-
Manage SCUP published updates under WSUS and SCCM.
After completion of SCUP environment, I published Adobe Flash player update successfully. Some where in blogs it was mentioned that published updates are under 'software library' but under SCCM2007 SP2 I am able to see 'software update' and there are
-
Partner number in Business Data Toolset
hi all, I´m using the Business Data Toolset to do some maintanance on customer own fields by saving the Business Partner. Actually I wrote a function module and put it into the event DSAVB. How is it possible to read the actual Business Partner numbe