View content of REF CURSOR
Is there any way in Raptor to view the content of a REF CURSOR being passed OUT from a stored procedure?
In SQL PLUS, I'll do this:
SET LINESIZE 1000;
SET PAGESIZE 1000;
VAR X REFCURSOR;
BEGIN
MY_USP(:X);
END;
PRINT X;
Is there a Raptor equivalent?
Actually, I didn't just vote for the request, I'm the only one who did ;-P
Some bug in the APEX stuff that still says I'm MATT MATT instead of the updated MRM (Mútua ReddisMATT).
Also seriously, I have no problems as to the order of things getting implemented (that's why you've got management for).
I understand that a feature with only two requests is low prio, especially if it's a tough one.
The only thing I don't like are veto's. If you don't like to implement a feature, you can mark it as low prio, waiting for comunity votes, etc. (you know it can stay in such states forever). Rejecting something is really not a nice thing to do, but hey, what can we do about it...
Regards,
K.
Similar Messages
-
Printing/viewing results of Ref Cursor
I have a stored procedure which returns a ref cursor. When I am in toad in the SQL window and I enter the following....what do I need to do such that I can see the output of the ref cursor?
DECLARE
O_ROWS PRG_OPS.Ops_Ui_Queries.t_cursor;
BEGIN
-- O_ROWS := NULL; Modify the code to initialize this parameter
PRG_OPS.Ops_Ui_Queries.QRY_PROD_DATA ( 1, 136, O_ROWS );
COMMIT;
END;If you just want to test soemthing in SQL*Plus this would work
SQL> var rc refcursor
SQL> exec RG_OPS.Ops_Ui_Queries.QRY_PROD_DATA ( 1, 136, :rc)
SQL> print rcCheers, APC -
Create view With Ref cursor data
Hi friends,
I want to create view as follows.
Example:
Create or replace v_name
select job,sal, <funcation>
from emp;
Note:- Function not having out parameter.
Function returning ref cursor values datatype.
Requirement:-
I want to create view even function returing ref cursor datatype.
Please advise how to create view.
Regards,
Kishoreuser7284612 wrote:
Hi friends,
I want to create view as follows.
Example:
Create or replace v_name
select job,sal, <funcation>
from emp;
Note:- Function not having out parameter.
Function returning ref cursor values datatype.
Requirement:-
I want to create view even function returing ref cursor datatype.
Please advise how to create view.You perhaps are misunderstanding what a ref cursor is. It does not contain data like a table, so cannot be treated as one.
Take a read of this:
PL/SQL 101 : Understanding Ref Cursors -
26.4 Basing an entity Object on a PL/SQL Package API - Ref Cursor, no View
I am hoping that I could get some help in the details of a problem. I am trying to follow the directions in the Oracle Application Development Framework Developer's Guide for Forms/4GL Developers, Section 26.4 - Basing an Entity Object on a PL/SQL Package API.
There is example code in the downloadable AdvancedEntityExamples - EntityWrappingPL/SQLPackage
The question is, how will the implementation change if the entity is based entirely on PL/SQL - simply stated - no view is available, just ref cursors and insert,update,delete procedures.
In the example code, there are two procedures, lock_product and select_product. This is where things get more complicated. I can create a function to return a single record ref cursor, instead of the list of OUT variables defined in both functions (select_product and lock_product). It makes sense that I just return one cursor and get all of the columns from that instead of lots of OUT variables.
So what's stopping me you may ask... There is one difference between select_product and select_lock. Select_lock has a select that includes "FOR UPDATE NOWAIT". I don't have that as an option when creating my ref cursor. I am not sure what the impact of "FOR UPDATE NOWAIT" is? Can I ignore it?
In the problem I am working with, (getting data from Oracle Portal 10.1.4) I return the following:
function getRefCursor return ref_cursor is
v_tab wwsbr_all_items_object_type := wwsbr_all_items_object_type();
p_recordset wwsbr_types.cursor_type;
l_results wwsrc_api.items_result_array_type;
begin
wwctx_api.set_context(<username>,<password>);
l_results := wwsrc_api.item_search(.. parameters..);
<snip>
... Loop through the objects and populate v_tab
<snip>
open p_recordset for
select * from table(cast(v_tab as wwsbr_all_items_object_type));
return p_recordset;
end getRefCursor;
With this sample, it would be easy to return a single row by passing the masterid as a parameter.
So I am still left with, how should the implementation of callLockProcedureAndCheckForRowInconsistency() and callSelectProcedure() be changed in order to use a ref cursor instead of a view? The user guide was missing that extra section <bg>.
What would be REALLY helpful, is an example, say 26.4A that demonstrates creating an entity object from a ref cursor and procedures from PL/SQL only without a view.
Thank you, KenThe lock procedure is expected to obtain a row-level lock on the row, given its key.
Depending on the setting of jbo.locking.mode, the entity object's lock() method will be invoked either as soon as the first persistent attribute is successfully modified by the user (in the case of jbo.locking.mode=pessimistic), or it will be called during commit processing just before the row is updated in the database (with jbo.locking.mode=optimistic).
Usually 2-tier Swing applications use pessimistic mode, while web applications use optimistic mode.
The FOR UPDATE NOWAIT is the Oracle clause that can be appened to a SELECT statement to acquire a row-level lock on the selected rows. The NOWAIT modifier means that rather than hanging, waiting for a row locked by another user to free up, it will raise an exception if any of the rows being selected-and-locked are not available to lock.
If you're not able to work the FOR UPDATE NOWAIT into the syntax of the ref cursor, perhaps you can initially perform the lock using a different cursor inside the stored procedure, then return your ref cursor. -
How can I see the contents in a Ref Cursor
I have this code:
CREATE OR REPLACE PACKAGE APOD_LOG.APOD_C3_LOG_API_PKG
AUTHID CURRENT_USER
AS
type rc is ref cursor;
PROCEDURE Fetch_Log_Spec
in_LOCAL_IP_VALUE IN BINARY_INTEGER,
out_RESULT_SET OUT rc
END APOD_C3_LOG_API_PKG;
CREATE OR REPLACE PACKAGE BODY APOD_LOG.APOD_C3_LOG_API_PKG
AS
PROCEDURE Fetch_Log_Spec
in_LOCAL_IP_VALUE IN BINARY_INTEGER,
out_RESULT_SET OUT rc
IS
BEGIN
DBMS_APPLICATION_INFO.set_module(module_name => 'APOD_LOG.API_PKG',action_name => 'Fetch_Log_Spec');
DBMS_APPLICATION_INFO.set_client_info(client_info => 'Calling with in_LOCAL_IP_VALUE = ' ||to_char(in_LOCAL_IP_VALUE));
open out_RESULT_SET for
select
in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
10002 as PORT,
APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.100.1''') as MULTICAST_IP_VALUE
from
dual
union
select
in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
10002 as PORT,
APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.200.1''') as MULTICAST_IP_VALUE
from
dual
union
select
in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
10002 as PORT,
APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.100.123''') as MULTICAST_IP_VALUE
from
dual
union
select
in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
10002 as PORT,
APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.200.123''') as MULTICAST_IP_VALUE
from
dual;
DBMS_APPLICATION_INFO.set_client_info(client_info => 'Called Fetch_Log_Spec '||to_char(SQL%ROWCOUNT)||' row(s) returned with in_LOCAL_IP_VALUE = '||to_char(in_LOCAL_IP_VALUE) );
END Fetch_Log_Spec;
END APOD_C3_LOG_API_PKG;
And I am trying to test it like this:
DECLARE
IN_LOCAL_IP_VALUE BINARY_INTEGER;
OUT_RESULT_SET APOD_LOG.APOD_C3_LOG_API_PKG.rc;
BEGIN
IN_LOCAL_IP_VALUE := 23374048;
-- OUT_RESULT_SET := NULL; How do I see this
APOD_LOG.APOD_C3_LOG_API_PKG.FETCH_LOG_SPEC ( IN_LOCAL_IP_VALUE, OUT_RESULT_SET );
END;
How can I see the dataset returnd by the OUT_RESULT_SET in SQLPlus or Quest ScriptRunner?A ref cursor doesn't really contain rows but you can use them to reference a SQL statement that fetches the rows.
Re: returning resultset from procedure...or pkg -
Selecting the contents of a table(collection) into a strong REF Cursor
I'm trying to roll some data into a table collection and return it as a strong named cursor.
I have not been able to do this successfully yet.
I have tried casting the table and I couldn't get that to work either.
I have included the whole procedure but here is the line I am getting errors on:
SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
Any help on this would be great.
P.S. - As this is being picked up by BizTalk I can't return a table.
Thanks,
Todd M
PROCEDURE create_customer (
i_interface_hdr IN BizTalk_TestCustomer.interface_hdr_rec,
i_customer_rec IN BizTalk_TestCustomer.customer_rec,
i_address_cur IN BizTalk_TestCustomer.CUR_Addresses,
i_contact_cur IN BizTalk_TestCustomer.CUR_Contact,
o_interface_status OUT varchar2,
o_response_data_cur OUT BizTalk_TestCustomer.CUR_CreateCustResponse)
IS
l_response_rec create_cust_response_rec;
response_data_tbl create_cust_response_tbl;
BEGIN
FOR i IN 1 .. 10
LOOP
l_response_rec.ERROR_TYPE := 'Pre-Validation Error';
l_response_rec.ERROR_CODE := 'DUMMY-' || i;
l_response_rec.error_message := 'Test Error Message-' || i;
response_data_tbl (i) := l_response_rec;
END LOOP;
SELECT * bulk collect into o_response_data_cur from table (response_data_tbl);
o_interface_status := 'FAILURE';
END create_customer;
END BizTalk_TestCustomer;
Here is the important Spec info:
TYPE create_cust_response_rec
IS
RECORD (
orig_system_party_ref varchar2 (240),
orig_system_cust_acct_ref varchar2 (240),
orig_system_site_ref varchar2 (240),
oracle_party_id number,
oracle_customer_id number,
oracle_site_id number,
ERROR_TYPE strar_cust_intf_err.ERROR_TYPE%TYPE,
ERROR_CODE strar_cust_intf_err.ERROR_CODE%TYPE,
error_message strar_cust_intf_err.error_message%TYPE
TYPE CUR_Addresses IS REF CURSOR RETURN BizTalk_TestCustomer.address_rec;
TYPE CUR_Contact IS REF CURSOR RETURN BizTalk_TestCustomer.contact_rec;
TYPE CUR_CreateCustResponse IS REF CURSOR RETURN BizTalk_TestCustomer.create_cust_response_rec;
TYPE create_cust_response_tbl
IS
TABLE OF create_cust_response_rec
INDEX BY binary_integer;I think this is one of the most complicated one to develop and execute perfectly. ;)
Here is one such case ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.55
satyaki>
satyaki>
satyaki>create or replace type d_obj as object
2 (
3 buff varchar2(310)
4 );
5 /
Type created.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>create or replace type d_rec as table of d_obj;
2 /
Type created.
Elapsed: 00:00:01.14
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>create or replace function pipe_buff(e_sal in number)
2 return d_rec
3 pipelined
4 is
5 cursor c1
6 is
7 select d_obj(
8 ename||' Joined On '||to_char(hiredate,'DD-MON-YYYY hh24:mi:ss')
9 ) str
10 from emp
11 where sal > e_sal;
12
13 r1 c1%rowtype;
14 begin
15 for r1 in c1
16 loop
17 pipe row(r1.str);
18 end loop;
19 return;
20 end;
21 /
Function created.
Elapsed: 00:00:01.69
satyaki>
satyaki>
satyaki>
satyaki>create or replace procedure gen_cur_pipe(
2 s_sal in number,
3 rc in out sys_refcursor
4 )
5 is
6 str1 varchar2(500);
7 begin
8 str1 := 'select *
9 from table(cast(pipe_buff('||s_sal||') as d_rec))';
10
11 open rc for str1;
12 exception
13 when others then
14 dbms_output.put_line(sqlerrm);
15 end;
16 /
Procedure created.
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>
satyaki>create table test_dual
2 (
3 dummy varchar2(310)
4 );
Table created.
Elapsed: 00:00:00.10
satyaki>
satyaki>
satyaki>
satyaki>declare
2 rec_x test_dual%rowtype;
3 w sys_refcursor;
4 begin
5 dbms_output.enable(1000000);
6 gen_cur_pipe(&num,w);
7 loop
8 fetch w into rec_x;
9 exit when w%notfound;
10 dbms_output.put_line('Employee Special Deatils: '||rec_x.dummy);
11 end loop;
12 close w;
13 exception
14 when others then
15 dbms_output.put_line(sqlerrm);
16 end;
17 /
Enter value for num: 1000
old 6: gen_cur_pipe(&num,w);
new 6: gen_cur_pipe(1000,w);
Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
Employee Special Deatils: WARD Joined On 22-FEB-1981 00:00:00
Employee Special Deatils: JONES Joined On 02-APR-1981 00:00:00
Employee Special Deatils: MARTIN Joined On 28-SEP-1981 00:00:00
Employee Special Deatils: BLAKE Joined On 01-MAY-1981 00:00:00
Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
Employee Special Deatils: SCOTT Joined On 19-APR-1987 00:00:00
Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
Employee Special Deatils: TURNER Joined On 08-SEP-1981 00:00:00
Employee Special Deatils: ADAMS Joined On 23-MAY-1987 00:00:00
Employee Special Deatils: FORD Joined On 03-DEC-1981 00:00:00
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.30
satyaki>
satyaki>
satyaki>/
Enter value for num: 4000
old 6: gen_cur_pipe(&num,w);
new 6: gen_cur_pipe(4000,w);
Employee Special Deatils: SATYAKI Joined On 02-NOV-2008 12:07:30
Employee Special Deatils: SOURAV Joined On 14-SEP-2008 00:07:21
Employee Special Deatils: CLARK Joined On 09-JUN-1981 00:00:00
Employee Special Deatils: KING Joined On 17-NOV-1981 00:00:00
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.13
satyaki>I'm not so sure about the performance.
Regards.
Satyaki De. -
Ref Cursor over Implicit and explicit cursors
Hi,
In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
[http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
I am bit confused by this, can any one help me to understand this?
ThanksSeshuGiri wrote:
In my company when writing PL/SQL procedure, everyone uses "Ref Cursor",
But the article below, says Implicit is best , then Explicit and finally Ref Cursor..
[http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]
I am bit confused by this, can any one help me to understand this?There is performance and there is performance...
To explain. There is only a single type of cursor in Oracle - that is the cursor that is parsed and compiled by the SQL engine and stored in the database's shared pool. The "+client+" is then given a handle (called a SQL Statement Handle in many APIs) that it can use to reference that cursor in the SQL engine.
The performance of this cursor is not determined by the client. It is determined by the execution plan and how much executing that cursor cost ito server resources.
The client can be Java, Visual Basic, .Net - or a PL/SQL program. This client language (a client of SQL), has its own structures in dealing with that cursor handle received from the SQL engine.
It can hide it from the developer all together - so that he/she does not even see that there is a statement handle. This is what implicit cursors are in PL/SQL.
It can allow the developer to manually define the cursor structure - this is what explicit cursors, ref cursors, and DBMS_SQL cursors are in PL/SQL.
Each of these client cursor structures provides the programmer with a different set of features to deal with SQL cursor. Explicit cursor constructs in PL/SQL do not allow for the use of dynamic SQL. Ref cursors and DBMS_SQL cursors do. Ref cursors do not allow the programmer to determine, at run-time, the structure of the SQL projection of the cursor. DBMS_SQL cursors do.
Only ref cursors can be created in PL/SQL and then be handed over to another client (e.g. Java/VB) for processing. Etc.
So each of the client structures/interfaces provides you with a different feature set for SQL cursors.
Choosing implicit cursors for example does not make the SQL cursor go faster. The SQL engine does not know and does not care, what client construct you are using to deal with the SQL cursor handle it gave you. It does not matter. It does not impact its SQL cursor performance.
But on the client side, it can matter - as your code in dealing with that SQL cursor determines how fast your interaction with that SQL cursor is. How many context switches you make. How effectively you use and re-use the SQL (e.g. hard parsing vs soft parsing vs re-using the same cursor handle). Etc.
Is there any single client cursor construct that is better? No.
That is an ignorant view. The client language provides a toolbox, where each tool has a specific application. The knowledgeable developer will use the right tool for the job. The idiot developer will select one tool and use it as The Hammer to "solve" all the problems. -
[Solved] 27.8.4 How to Create a VO on a REF CURSOR - Missing first row
Searching the forum I found: BC4J - Get one less row from view object.
Dive into BC4J related --REF CURSOR (Resultset)
The first message did not have any answers, and the second had a follow up question - still no answers though - and I thought I would try a different title.
(This is off topic, but it would be a great help if the search results also displayed the number of replys in the thread. That way, I wouldn't have to view the messages that don't have responses.)
(This will be deployed on a server that has the ADF for JDeveloper 10.1.2 installed, so using that version of JDeveloper to develop the app.)
Okay, back to the problem ==>
I created a VO from a ref cursor, using the manual as a guide. When I run a page that displays a read only table of the view object, I am missing the first row. (Always the first row!) I don't have any order set, and if I call the ref cursor in a Java program for testing, I see all rows and the count is correct.
One other point, when I call the page, I get the following validation error:
Validation Error
You must correct the following error(s) before proceeding:
* JBO-29000: Unexpected exception caught: java.lang.ClassCastException, msg=null
* null
I still see the table, it is just missing the first row of data.
In my form I have first, previous set, next set , and last
navigation buttons. If I press last then first, the error goes away. I still don't see the missing row though.
Any guidance would be appreciated! I can post my code, but it is pretty much the same code in the AdvancedViewObjectExamples.zip in the ViewObjectOnRefCursor example. I just substituted my two package calls (getRefCursor and getRefCursorCount).
Thanks, KenWent back to a backup copy of the source. Fixed the error. Now I'm back to just not being able to see the first row of data.
Additional Note: I had removed fields in the display. Once I truncated the ps_txn table in the schema defined by the model, the data would display (Still without the first record.)
Are there any examples that are more in depth than the few pages in the developer guide?
Here is the code for my VOImpl class:
package newslinearchive.model.datamodel;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import oracle.jbo.InvalidParamException;
import oracle.jbo.JboException;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.QueryCollection;
import oracle.jbo.server.SQLBuilder;
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;
// --- File generated by Oracle ADF Business Components Design Time.
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
public class SearchRefCursorImpl extends ViewObjectImpl {
* This is the default constructor (do not remove)
public SearchRefCursorImpl() {
* Overridden framework method.
* Executed when the framework needs to issue the database query for
* the query collection based on this view object. One view object
* can produce many related result sets, each potentially the result
* of different bind variable values. If the rowset in query is involved
* in a framework-coordinated master/detail viewlink, then the params array
* will contain one or more framework-supplied bind parameters. If there
* are any user-supplied bind parameter values, they will PRECEED the
* framework-supplied bind variable values in the params array, and the
* number of user parameters will be indicated by the value of the
* numUserParams argument.
protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
storeNewResultSet(qc,retrieveRefCursor(qc,params));
super.executeQueryForCollection(qc, params, numUserParams);
* Overridden framework method.
* Wipe out all traces of a built-in query for this VO
protected void create() {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
* Overridden framework method.
* The role of this method is to "fetch", populate, and return a single row
* from the datasource by calling createNewRowForCollection() and populating
* its attributes using populateAttributeForRow().
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
* We ignore the JDBC ResultSet passed by the framework (null anyway) and
* use the resultset that we've stored in the query-collection-private
* user data storage
rs = getResultSet(qc);
* Create a new row to populate
ViewRowImpl r = createNewRowForCollection(qc);
try {
* Populate new row by attribute slot number for current row in Result Set
// populateAttributeForRow(r,0, rs.getLong(1));
// populateAttributeForRow(r,1, rs.getString(2));
// populateAttributeForRow(r,2, rs.getString(3));
// MASTERID NOT NULL NUMBER
populateAttributeForRow(r,0, rs.getBigDecimal(1));
//ID NOT NULL NUMBER
populateAttributeForRow(r,1, rs.getBigDecimal(2));
// CAID NOT NULL NUMBER
populateAttributeForRow(r,2, rs.getBigDecimal(3));
// LANGUAGE NOT NULL VARCHAR2(30)
populateAttributeForRow(r,3, rs.getString(4));
// IS_CURRENT_VERSION NOT NULL NUMBER(1)
populateAttributeForRow(r,4, rs.getBigDecimal(5));
// FOLDER_ID NOT NULL NUMBER
populateAttributeForRow(r,5, rs.getBigDecimal(6));
// FOLDER_REGION_ID NOT NULL NUMBER
populateAttributeForRow(r,6, rs.getBigDecimal(7));
// NAME NOT NULL VARCHAR2(256)
populateAttributeForRow(r,7, rs.getString(8));
// DISPLAY_NAME VARCHAR2(256)
populateAttributeForRow(r,8, rs.getString(9));
// ITEMTYPE NOT NULL VARCHAR2(30)
populateAttributeForRow(r,9, rs.getString(10));
// SUBTYPE VARCHAR2(40)
populateAttributeForRow(r,10, rs.getString(11));
// SUBTYPE_CAID NUMBER
populateAttributeForRow(r,11, rs.getBigDecimal(12));
// PARENT_ITEM_ID NUMBER
populateAttributeForRow(r,12, rs.getBigDecimal(13));
// CATEGORY_ID NUMBER
populateAttributeForRow(r,13, rs.getBigDecimal(14));
// CATEGORY_CAID NUMBER
populateAttributeForRow(r,14, rs.getBigDecimal(15));
// AUTHOR VARCHAR2(50)
populateAttributeForRow(r,15, rs.getString(16));
// DESCRIPTION VARCHAR2(2000)
populateAttributeForRow(r,16, rs.getString(17));
// PUBLISH_DATE NOT NULL DATE
populateAttributeForRow(r,17, rs.getDate(18));
// EXPIREMODE VARCHAR2(90)
populateAttributeForRow(r,18, rs.getString(19));
// EXPIRENUMBER NUMBER
populateAttributeForRow(r,19, rs.getBigDecimal(20));
// EXPIREDATE DATE
populateAttributeForRow(r,20, rs.getDate(21));
// IMAGE VARCHAR2(350)
populateAttributeForRow(r,21, rs.getString(22));
// KEYWORDS VARCHAR2(2000)
populateAttributeForRow(r,22, rs.getString(23));
// URL VARCHAR2(4000)
populateAttributeForRow(r,23, rs.getString(24));
// FILENAME VARCHAR2(350)
populateAttributeForRow(r,24, rs.getString(25));
// TEXT CLOB()
populateAttributeForRow(r,25, rs.getClob(26));
// FOLDER_LINK_ID NUMBER
populateAttributeForRow(r,26, rs.getBigDecimal(27));
// FOLDER_LINK_CAID NUMBER
populateAttributeForRow(r,27, rs.getBigDecimal(28));
// ACTIVE NOT NULL NUMBER(1)
populateAttributeForRow(r,28, rs.getBigDecimal(29));
// CAN_BE_CHECKEDOUT NUMBER(1)
populateAttributeForRow(r,29, rs.getBigDecimal(30));
// IS_ITEM_CHECKEDOUT NUMBER(1)
populateAttributeForRow(r,30, rs.getBigDecimal(31));
// CHECKER_USERNAME VARCHAR2(256)
populateAttributeForRow(r,31, rs.getString(32));
// CHECKOUT_DATE DATE
populateAttributeForRow(r,32, rs.getDate(33));
// FULLSCREEN NOT NULL NUMBER(1)
populateAttributeForRow(r,33, rs.getBigDecimal(34));
// INPLACE NOT NULL NUMBER(1)
populateAttributeForRow(r,34, rs.getBigDecimal(35));
// CREATEDATE NOT NULL DATE
populateAttributeForRow(r,35, rs.getDate(36));
// CREATOR NOT NULL VARCHAR2(256)
populateAttributeForRow(r,36, rs.getString(37));
// UPDATEDATE DATE
populateAttributeForRow(r,37, rs.getDate(38));
// UPDATOR VARCHAR2(256)
populateAttributeForRow(r,38, rs.getString(39));
// SECURITY VARCHAR2(25)
populateAttributeForRow(r,39, rs.getString(40));
// VISIBLE NOT NULL NUMBER(1)
populateAttributeForRow(r,40, rs.getBigDecimal(41));
// SEQUENCE NOT NULL NUMBER
populateAttributeForRow(r,41, rs.getBigDecimal(42));
// CATEGORY_SEQUENCE NOT NULL NUMBER
populateAttributeForRow(r,42, rs.getBigDecimal(43));
// AUTHOR_SEQUENCE NOT NULL NUMBER
populateAttributeForRow(r,43, rs.getBigDecimal(44));
// CREATE_DATE_SEQUENCE NOT NULL NUMBER
populateAttributeForRow(r,44, rs.getBigDecimal(45));
// ITEMTYPE_SEQUENCE NOT NULL NUMBER
populateAttributeForRow(r,45, rs.getBigDecimal(46));
catch (SQLException s) {
throw new JboException(s);
return r;
* Overridden framework method.
* Return true if the datasource has at least one more record to fetch.
protected boolean hasNextForCollection(Object qc) {
ResultSet rs = getResultSet(qc);
boolean nextOne = false;
try {
nextOne = rs.next();
* When were at the end of the result set, mark the query collection
* as "FetchComplete".
if (!nextOne) {
setFetchCompleteForCollection(qc, true);
* Close the result set, we're done with it
rs.close();
catch (SQLException s) {
throw new JboException(s);
return nextOne;
* Overridden framework method.
* The framework gives us a chance to clean up any resources related
* to the datasource when a query collection is done being used.
protected void releaseUserDataForCollection(Object qc, Object rs) {
* Ignore the ResultSet passed in since we've created our own.
* Fetch the ResultSet from the User-Data context instead
ResultSet userDataRS = getResultSet(qc);
if (userDataRS != null) {
try {
userDataRS.close();
catch (SQLException s) {
/* Ignore */
super.releaseUserDataForCollection(qc, rs);
* Overridden framework method
* Return the number of rows that would be returned by executing
* the query implied by the datasource. This gives the developer a
* chance to perform a fast count of the rows that would be retrieved
* if all rows were fetched from the database. In the default implementation
* the framework will perform a SELECT COUNT(*) FROM (...) wrapper query
* to let the database return the count. This count might only be an estimate
* depending on how resource-intensive it would be to actually count the rows.
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
Long result = (Long)callStoredFunction(NUMBER,
"PORTAL.SEARCH_REFCURSOR.getRefCursorCount",
viewRowSet.getParameters(true));
return result.longValue();
// ------------- PRIVATE METHODS ----------------
* Return a JDBC ResultSet representing the REF CURSOR return
* value from our stored package function.
* new Object[]{getNamedBindParamValue("Email",params)}
private ResultSet retrieveRefCursor(Object qc, Object[] params) {
ResultSet rs = (ResultSet)callStoredFunction(OracleTypes.CURSOR,
"PORTAL.SEARCH_REFCURSOR.getRefCursor",
null);
return rs ;
private Object getNamedBindParamValue(String varName, Object[] params) {
Object result = null;
if (getBindingStyle() == SQLBuilder.BINDING_STYLE_ORACLE_NAME) {
if (params != null) {
for (Object param : params) {
Object[] nameValue = (Object[])param;
String name = (String)nameValue[0];
if (name.equals(varName)) {
return (String)nameValue[1];
throw new JboException("No bind variable named '"+varName+"'");
* Store a new result set in the query-collection-private user-data context
private void storeNewResultSet(Object qc, ResultSet rs) {
ResultSet existingRs = getResultSet(qc);
// If this query collection is getting reused, close out any previous rowset
if (existingRs != null) {
try {existingRs.close();} catch (SQLException s) {}
setUserDataForCollection(qc,rs);
hasNextForCollection(qc); // Prime the pump with the first row.
* Retrieve the result set wrapper from the query-collection user-data
private ResultSet getResultSet(Object qc) {
return (ResultSet)getUserDataForCollection(qc);
* Return either null or a new oracle.jbo.domain.Date
private static Date nullOrNewDate(Timestamp t) {
return t != null ? new Date(t) : null;
* Return either null or a new oracle.jbo.domain.Number
private static Number nullOrNewNumber(BigDecimal b) {
try {
return b != null ? new Number(b) : null;
catch (SQLException s) { }
return null;
//----------------[ Begin Helper Code ]------------------------------
public static int NUMBER = Types.NUMERIC;
public static int DATE = Types.DATE;
public static int VARCHAR2 = Types.VARCHAR;
public static int CLOB = Types.CLOB;
* Simplifies calling a stored function with bind variables
* You can use the NUMBER, DATE, and VARCHAR2 constants in this
* class to indicate the function return type for these three common types,
* otherwise use one of the JDBC types in the java.sql.Types class.
* NOTE: If you want to invoke a stored procedure without any bind variables
* ==== then you can just use the basic getDBTransaction().executeCommand()
* @param sqlReturnType JDBC datatype constant of function return value
* @param stmt stored function statement
* @param bindVars Object array of parameters
* @return function return value as an Object
protected Object callStoredFunction(int sqlReturnType, String stmt,
Object[] bindVars) {
CallableStatement st = null;
try {
st = getDBTransaction().createCallableStatement("begin ? := " + stmt +
"; end;", 0);
st.registerOutParameter(1, sqlReturnType);
if (bindVars != null) {
for (int z = 0; z < bindVars.length; z++) {
st.setObject(z + 2, bindVars[z]);
st.executeUpdate();
return st.getObject(1);
catch (SQLException e) {
throw new JboException(e);
finally {
if (st != null) {
try {
st.close();
catch (SQLException e) {}
/**Gets the bind variable value for Email
public String getEmail() {
return (String)getNamedWhereClauseParam("Email");
/**Sets <code>value</code> for bind variable Email
public void setEmail(String value) {
setNamedWhereClauseParam("Email", value);
/**getEstimatedRowCount - overridden for custom java data source support.
public long getEstimatedRowCount() {
long value = super.getEstimatedRowCount();
return value;
Thanks, Ken -
Help on CAST function, defining TYPE TABLE and using a REF cursor
Hi,
I have written a procedure (lookup) inside a package (lookup_pkg) as shown below.
Procedure has an output variable of type PL/SQL TABLE which is defined in the package.
I want to write a wrapper procedure lookupref to the procedure lookup to return a ref cursor.
CREATE OR REPLACE PACKAGE lookup_pkg AS
TYPE t_lookup_refcur IS REF CURSOR;
CURSOR c_lookup IS
Select columns1,2,3,....100
FROM A, B, C, D, E
WHERE ROWNUM < 1;
TYPE t_lookup IS TABLE OF c_lookup%ROWTYPE;
Procedure lookup(id Number, o_lookup OUT t_lookup);
End lookup_pkg;
CREATE OR REPLACE PACKAGE BODY lookup_pkg As
Procedure lookup(id Number, o_lookup OUT t_lookup) IS
BEGIN
END lookup;
Procedure lookupref(id Number, o_lookupref OUT t_lookup_refcur) IS
o_lookup t_lookup;
BEGIN
lookup(id, o_lookup t_lookup);
OPEN t_lookup_refcur FOR
SELECT *
FROM TABLE(CAST(o_lookup AS t_lookup));
Exception
End lookupref;
END lookup_pkg;
When I compile this procedure, I am getting invalid datatype Oracle error and
cursor points the datatype t_lookup in the CAST function.
1. Can anyone tell me what is wrong in this. Can I convert a PL/SQL collection (pl/sql table in this case) to PL/SQL datatype table or does it need to be a SQL datatype only (which is created as a type in database).
Also, to resolve this error, I have created a SQL type and table type instead of PL/SQL table in the package as shown below.
create or replace type t_lookuprec as object
(Select columns1,2,3,....100
FROM A, B, C, D, E
WHERE ROWNUM < 1);
create or replace type t_lookup_tab AS table of t_lookuprec;
CREATE OR REPLACE PACKAGE BODY lookup_pkg As
Procedure lookup(id Number, o_lookup OUT t_lookup) IS
BEGIN
END lookup;
Procedure lookupref(id Number, o_lookupref OUT t_lookup_refcur) IS
o_lookup t_lookup;
BEGIN
lookup(id, o_lookup t_lookup);
OPEN t_lookup_refcur FOR
SELECT *
FROM TABLE(CAST(o_lookup AS t_lookup_tab));
Exception
End lookupref;
END lookup_pkg;
When I compile this package, I am getting "PL/SQL: ORA-22800: invalid user-defined type" Oracle error and
points the datatype t_lookup_tab in the CAST function.
2. Can anyone tell me what is wrong. Can I create a type with a select statement and create a table type using type created earlier?
I have checked the all_types view and found that
value for Incomplete column for these two types are YES.
3. What does that mean?
Any suggestions and help is appreciated.
Thanks
Srinivascreate or replace type t_lookuprec as object
(Select columns1,2,3,....100
FROM A, B, C, D, E
WHERE ROWNUM < 1);You are correct that you need to use CREATE TYPE to use the type in SQL.
However unless I am mistaken you appear to have invented your own syntax for CREATE TYPE, suggest you refer to Oracle documentation. -
Using ref cursor in where clause
I have a stored procedure (package procedure) that returns a ref cursor as a parameter. This procedure performs a query and returns the cursor. The procedure calls another stored procedure within the package. This second procedure also returns a ref cursor. I want to do my query on the results of the cursor returned by the second procedure. Hopefully the example below is okay.. "I had to change names to protect the blah blah...."
For example:
TYPE out_cursor IS REF CURSOR;
TYPE IDTable IS TABLE OF table1.ID%TYPE;
PROCEDURE A
v_ID IN NUMBER,
v_Param2 IN NUMBER,
v_FromClause IN VARCHAR2, -- ignore for now
v_WhereClause IN VARCHAR2, -- ignore for now
v_retval OUT NUMBER,
the_cursor OUT out_cursor
IS
v_SQLString VARCHAR2(2048);
v_cursor1 out_cursor;
v_tabIDs IDTable;
BEGIN
v_SQLString := '';
packageA.procedureA(v_ID, v_retval, v_cursor1);
-- this does not work
-- I get ORA-00942: table or view does not exist
v_SQLString := 'select distinct * from v_cursor1';
-- I found this on the message board but
-- it did not compile.
-- local collection types not allowed in SQL statements
FETCH v_cTSFiles BULK COLLECT INTO v_tabIDs;
v_SQLString := 'select distinct * from table1 WHERE table1.ID in (select * from table(v_tabIDs))';
OPEN the_cursor FOR v_SQLString;
END;You can use that second technique but as the error message says, "local collection types not allowed in SQL statements". You need to create a schema type instead.
[sql]
create or replace type ttab_number is table of number
create or replace procedure p is
tab_id ttab_number;
refcur sys_refcursor;
begin
open refcur for
select user_id
from all_users;
fetch refcur bulk collect into tab_id;
close refcur;
for rec in (
select *
from all_users
where user_id in (
select *
from table(cast(tab_id as ttab_number)))
) loop
dbms_output.put_line(rec.username);
end loop;
end;
[sql] -
DB proc - do you need to create a table to pass a ref cursor record type?
I want to pass a limited selection of columns from a large table through a DB procedure using a REF CURSOR, returning a table rowtype:
CREATE OR REPLACE package XXVDF_XPOS_DS021_ITEMS AS
TYPE XXVDF_XPOS_DS021_ITEM_ARRAY
IS REF CURSOR
return XXVDF_XPOS_DS021_ITEM_TABLE%ROWTYPE;
Do I need to create this dummy table?
I can't get a TYPE to work, where the type is an OBJECT with the desired columns in it.
So a dummy empty table will sit in the database...
Is there another way?
thanks!You can use RECORD type declaration:
SQL> declare
2 type rec_type is record (
3 ename emp.ename%type,
4 sal emp.sal%type
5 );
6 type rc is ref cursor return rec_type;
7 rc1 rc;
8 rec1 rec_type;
9 begin
10 open rc1 for select ename, sal from emp;
11 loop
12 fetch rc1 into rec1;
13 exit when rc1%notfound;
14 dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
15 end loop;
16 close rc1;
17 end;
18 /
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100
JAMES 950
FORD 3000
MILLER 1300or use, for example, VIEW to declare rowtype:
SQL> create view dummy_view as select ename, sal from emp;
View created.
SQL> declare
2 type rc is ref cursor return dummy_view%rowtype;
3 rc1 rc;
4 rec1 dummy_view%rowtype;
5 begin
6 open rc1 for select ename, sal from emp;
7 loop
8 fetch rc1 into rec1;
9 exit when rc1%notfound;
10 dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
11 end loop;
12 close rc1;
13 end;
14 /
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100
JAMES 950
FORD 3000
MILLER 1300 Rgds. -
VC 7.0 Oracle stored procedures resultset with ref cursor
Can VC (we are on NW7 SP13) handle Oracle's datatype ref cursor - which is the standard solution in Oracle to return result sets - as the return value of a stored procedure?
When testing a data service in the VC story board based upon a simple Oracle function like:
create or replace package pkg_dev
is
type t_cursor is ref cursor;
end;
create or replace function vc_stub return pkg_dev.t_cursor
as
l_cursor pkg_dev.t_cursor;
begin
open l_cursor for select ename from emp;
return l_cursor;
end;
(just as example - I know that could be easily retrieved using the BI JDBC connector framework and accessing tables / views)
I am always running in the "portal request failed ( Could not execute Stored Procedure)" error - so I am not able to use the "add fields" function to bind the output.
The defaulttrace contains entries like:
Text: com.sap.portal.vc.HTMLBRunTime
[EXCEPTION]
com.sapportals.connector.execution.ExecutionException: Could not execute stored procedure
Caused by: java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
We deployed Oracle's own jdbc-driver for Oracle 10g. Using that driver and a portal jdbc connector framework entry the stored procedures of the Oracle database user mapped to the portal user are discovered and available in the "Find Data Services" section.We deployed the drivers as described in the HowTo Papers (e.g.Hwo to Configure UD Connect on the J2EE Server for JDBC Access to External Databases). When deploying the drivers you assign a freely definable name for the set of Oracle's jar-files (eg. oracle_10) as library name. Having deployed the drivers in that way only System Definitions via BI JDBC connector framework were working. With a little help from SAP Support (call lasted more than 2 months till a very capable member of the support team made things working in a very short time) we got the portal jdbc connection with Oracle's jar-files working:
Here are instructions how to add reference:
1. Connect to the j2ee using telnet, e.g in the cmd window type:
telnet <host> <port> + 8, enter uid and pwd of j2ee admin.
2. jump 0
3. add deploy
4. change_ref -m com.sapportals.connectors.database <your lib name> <your lib name = oracle_10>
Trying to manually add this reference in visual admin connector container for JDBCFactory failed - reference could be added and saved, but then disappeared (at least in NW7 with SP12). Adding the reference as described above solved the problem. -
XSQL ERROR with bind-params in ref-cursor-function
Hi Steve
I always get the error
ORA-01006 bind variable does not exist
when using a bind variable in a <xsql:ref-cursor-function> action element.
when I replace the bind variable with a @ - parameter substitution, all works fine.
My configuration:
XSQL 1.0.4.1 on Win200Pro ,Apache + Jserv + DB from ORA 8.1.7 installation
My Source
<xsql:ref-cursor-function
dbconn="ekat"
eblike="%"
list="a0"
bind-params="eblike"
include-schema="no"
null-indicator="no"
id-attribute=""
fetch-size="500"
>
{@dbconn}o.ekatkategcv.open_cv_ebh ('{@list}', :1)
</xsql:ref-cursor-function>
( dbconn selects my schema, not changed often, which contains package ekatkategcv with
function open_cv_ebh returning a cursor)
Any fix would be appreciated to avoid reparsing on each call.
BTW, is it right, that a ref-cursor funtion is reparsed whenever the content of
a parameter used with @ changes?
Best regards
H.Buschmann ([email protected])
nullI have tried it using ? instead of :1, this method works fine.
I haven't tried the name method (:bindvar) yet.
Until now, I only used xsl:query and xsql:ref-cursor-function, so I didn't check
the other action handlers with bind variables like :1
null -
Unit Test Validation for Output Ref Cursor Not Working
Here is the problem:
I have a stored procedure as follows:
CREATE OR REPLACE
PROCEDURE usp_GetEmployee(
p_employeeId IN NUMBER,
cv_employee OUT Sys_RefCursor )
AS
BEGIN
OPEN cv_employee FOR SELECT * FROM employees WHERE employee_id=p_employeeid;
END usp_GetEmployee;
For this, I am implementing a unit test.
* In the "Select Parameters" step, I am unchecking the "Test Result" check box for the cursor OUT variable.
* In the "Specify Validations" step, I am choosing "Boolean Function" and putting the following PL/SQL code:
DECLARE
emp_rec {cv_employee$}%rowtype;
BEGIN
FETCH {cv_employee$} INTO emp_rec;
IF {cv_employee$}%FOUND THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
RETURN TRUE;
END;
But, when I try to execute this Test, I get the following error:
Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@4f0617> to REF CURSOR.
If I run in the debug mode, I get the following content in a dialog box:
The following procedure was run.
Execution Call
BEGIN
"ARCADMIN"."USP_GETEMPLOYEE"(P_EMPLOYEEID=>:1,
CV_EMPLOYEE=>:2);
END;
Bind variables used
:1 NUMBER IN 1001
:2 REF CURSOR OUT (null)
Execution Results
ERROR
CV_EMPLOYEE : Expected: [Any value because apply check was cleared], Received: [EMPLOYEE_ID COMMISSION_PCT SALARY
1001 0.2 8400
Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@31dba0> to REF CURSOR.
Please suggest how to handle this issue.
Thanks,
Rahul979635 wrote:
But, when I try to execute this Test, I get the following error:
Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@4f0617> to REF CURSOR.
If I run in the debug mode, I get the following content in a dialog box:
The following procedure was run.
Execution Call
BEGIN
"ARCADMIN"."USP_GETEMPLOYEE"(P_EMPLOYEEID=>:1,
CV_EMPLOYEE=>:2);
END;
Bind variables used
:1 NUMBER IN 1001
:2 REF CURSOR OUT (null)
Try explicity declaring the ref cursor instead of using a bind variable, something like (untested)
begin
foo sys_refcurosr;
begin
test_procedure(foo);
end;Alternately, in SQL*PLUS use the DEFINE command to ste a named bind variable to type REFCURSOR and use the named bind variable in your test
Edited by: riedelme on Jan 23, 2013 7:10 AM -
How to accumlate resultsets in ref cursor
Hello
I have 3 cursor which query on different tables and return the same columns. I need to accumulate the result set of 3 cursors into a single ref cursor. Is this possible. If so how.
regards,
Ravi NaralaIt's possible, but it's not recommended. Do you have any control of the situation (can you just write 1 query)?
If you have absolutely no option, you can user record types (you will need a SQL type created), BULK COLLECT the contents of cursor1, cursor2 and cursor3 into that, and then return a REF CURSOR that is
SELECT * FROM TABLE(SQL_TYPE);
Here's an example:
create type my_number_type as table of number;
DECLARE
c1 sys_refcursor;
c2 sys_refcursor;
c3 sys_refcursor;
final_cursor sys_refcursor;
array_1 my_number_type;
array_2 my_number_type;
array_3 my_number_type;
final_array my_number_type;
BEGIN
open c1 for select 1 from dual;
fetch c1 bulk collect into array_1;
close c1;
open c2 for select 8 from dual;
fetch c2 bulk collect into array_2;
close c2;
open c3 for select 6 from dual;
fetch c3 bulk collect into array_3;
close c3;
select *
bulk collect into final_array
from
select * from table(cast(array_1 as my_number_type))
UNION ALL
select * from table(cast(array_2 as my_number_type))
UNION ALL
select * from table(cast(array_3 as my_number_type))
open final_cursor for select * from table(cast(final_array as my_number_type));
END;
[pre]
Message was edited by:
Tubby
Maybe you are looking for
-
Need help in SQL query to get only distinct records
Hi all. I am new to oracle SQL and i want to write a query to get only distinct values from 2 tables. for example i hade 2 tables table1(employee_id,employee_no,grade) and another table2 with same structure. for example data in table1 is Employeeid e
-
Trying to understand different movie files
Fairly new to working with movies and movie files on my Macbook. In the finder under all movies, I have several different file types from converting VHS tapes, downloads and quick movies taken with a digital camera. I have mp4, avi, eyetv, mov and dv
-
Since yesterday, when I click to read my email I get a blank window instead of the usual window with the email itself. The same is happening with windows where data should be entered, like those virtual keyboards for online banking login, or windows
-
I was trying to clean up my computer yesterday by deleting some files, mainly clearing the cache and deleting large files that i knew what they were. I turned off my computer for the night, and now today when i turned on my computer I can no longer
-
Are the new 27" iMacs showing up in the Apple Stores yet?
Impoosible to call a store ask someone if they have any available for purchase. I am just looking for a plain stock unit but I would like to spend the money this year so ordering doesn't look like an option.