Accessing a returned SYS_REFCURSOR
Hi,
i have a problem accessing records in a weak sys_refcursor (that was returned from another function) inside a PL/SQL function. I alwys get a "PLS-00487: Invalid reference to variable 'REC2'" where rec2 is my loop record variable.
Here is a simplified test which shows the same behaviour (the problem is marked in master_report):
TYPE resType AS OBJECT (
c1 VARCHAR2(80),
c2 VARCHAR2(80),
c3 VARCHAR2(80)
TYPE resTable AS TABLE OF resType;
CREATE OR REPLACE FUNCTION REPORT_01 (uId PLS_INTEGER)
RETURN SYS_REFCURSOR
IS
st_cursor SYS_REFCURSOR;
BEGIN
-- Do various things, builds a dynamic sql query based in input parameters
OPEN st_cursor FOR 'SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id LEFT JOIN t3 ON t1.id = t3.id';
return st_cursor;
END REPORT_01;
CREATE OR REPLACE FUNCTION MASTER_REPORT (repId PLS_INTEGER)
RETURN resTable PIPELINED
IS
res resType := resType(NULL,NULL,NULL);
BEGIN
FOR rec in
( SELECT * FROM report WHERE REP_ID = repId )
LOOP
IF rec.basisreport_key = 'basisreport.einsaetzeimunternehmen' THEN
-- report_01 returns an open sys_refcursor
FOR rec2 IN report_01(rec.ben_id)
LOOP
-- PROBLEM HERE: "Invalid reference to variable 'REC2'"
res.c1 := rec2.personalnummer;
res.c2 := rec2.name;
res.c3 := rec2.type;
PIPE ROW(
END LOOP;
END IF;
END LOOP;
END MASTER_REPORT;
So my question is: How am i supposed to acces the contents of the returned ref cursor?
Thanks.
Ulrich Petri
Hello
Aha! Sorry, I forgot that for it to work you have to select the columns "as" the object type like so:
SQL> set serveroutput on
SQL> CREATE OR REPLACE TYPE resType AS OBJECT (
2 c1 VARCHAR2(80),
3 c2 VARCHAR2(80),
4 c3 VARCHAR2(80)
5 )
6 /
Type created.
SQL> DECLARE
2
3 my_cursor sys_refcursor;
4
5 res resType;
6
7 BEGIN
8
9 OPEN my_cursor FOR 'SELECT ''C1'',''C2'',''C3'' FROM DUAL';
10
11 FETCH my_cursor INTO res;
12
13 END;
14 /
DECLARE
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected UDT got CHAR
ORA-06512: at line 11
SQL> DECLARE
2
3 my_cursor sys_refcursor;
4
5 res resType;
6
7 BEGIN
8
9 OPEN my_cursor FOR 'SELECT resType(''C1'',''C2'',''C3'') FROM DUAL';
10
11 FETCH my_cursor INTO res;
12
13 DBMS_OUTPUT.put_line(res.c1);
14 DBMS_OUTPUT.put_line(res.c2);
15 DBMS_OUTPUT.put_line(res.c3);
16
17 END;
18 /
C1
C2
C3
PL/SQL procedure successfully completed.HTH
David
Similar Messages
-
Toplink JPA Calling Oracle Function Return sys_refcursor
I have a function which return sys_refcursor and I am trying to call this using JPA(1.0)
@NamedNativeQuery( name = "getEmpsByDeptId"
, query = "{ ? = call my_pck.getEmployees(:longName)}"
, resultClass = Employee.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
DAOImpl
query = getEntityManager().createNamedQuery("getEmpsByDeptId");
query.setParameter("longName", "SCOTT");
list = (List<Employee>)query.getResultList();
However when I execute, I am getting the following exception
Exception [TOPLINK-6132] (Oracle TopLink Essentials - 2.1 (Build b52-fcs (09/24/2008))):
oracle.toplink.essentials.exceptions.QueryException Exception Description:
Query argument 2 not found in list of parameters provided during query execution.
Query: ReadAllQuery(test.entity.Employee) at oracle.toplink.essentials.exceptions.QueryException.namedArgumentNotFoundInQueryParameters
I have tried using
call my_pck.getEmployees(?)}"
and
query.setParameter(1, "SCOTT");
However error remains the same and how can I resolve this issue?
I have used the same function with Hibernate using JPA2.0 and it has worked.
Thanklecaro wrote:
OK. But obviously there is some oracle object that one can call via an Access pass-through query which returns rows?Just to clarify. You could fetch data in Access from an Oracle function that returns a ref cursor using VBA editor. To use a pass-through query Oracle function should be a table function or pipelined table function:
CREATE OR REPLACE
TYPE testvalues_obj_type
AS OBJECT(
val varchar2(10),
isnum number
CREATE OR REPLACE
TYPE testvalues_tbl_type
AS TABLE OF testvalues_obj_type
CREATE OR REPLACE
FUNCTION fn_testvalues
RETURN testvalues_tbl_type
PIPELINED
IS
CURSOR testvalues_cur
IS
SELECT testvalues_obj_type(MyValue,fn_isnum(MyValue)) testvalues_obj
FROM t_values;
BEGIN
FOR v_rec IN testvalues_cur LOOP
PIPE ROW(v_rec.testvalues_obj);
END LOOP;
RETURN;
END;
/To test it in Oracle:
SELECT *
FROM TABLE(fn_testvalues)
VAL ISNUM
Merced 0
Pixie 0
452 1
SQL> Now in Access pass-trough query window enter:
SELECT *
FROM TABLE(fn_testvalues);SY. -
Unable to access data returned by EJB
Hi,
One of my EJB method(getHeaderInfo) returns string array (String[]). In the WSDL, I have following entries -
<complexType name="GetHeaderResponseType">
<sequence>
<any/>
</sequence>
</complexType>
<message name="GetResponseMessage">
<part name="header" type="tns:GetHeaderResponseType"/>
</message>
<portType>
<operation name="getHeaderInfo">
<input name="GetHeaderInfoRequest" message="tns:GetHeaderRequestMessage"/>
<output name="GetHeaderInfoResponse" message="tns:GetHeaderResponseMessage"/>
<fault name="GetHeaderInfoException" message="tns:ExceptionMessage"/>
</operation>
</portType>
<binding name="EJBBinding" type="tns:Data">
<ejb:binding/>
<format:typeMapping encoding="Java" style="Java">
<format:typeMap typeName="xsd:string" formatType="java.lang.String" />
<format:typeMap typeName="xsd:boolean" formatType="boolean" />
<format:typeMap typeName="tns:ExceptionType" formatType="java.lang.Exception"/>
<format:typeMap typeName="tns:GetHeaderResponseType" formatType="java.lang.String[]"/>
</format:typeMapping>
<operation name="getHeaderInfo">
<ejb:operation
methodName="getHeaderInfo"
parameterOrder="filepath filename" interface="remote" returnPart="header"/>
<input name="GetHeaderInfoRequest"/>
<output name="GetHeaderInfoResponse"/>
<fault name="GetHeaderInfoException"/>
</operation>
</binding>
When I execute the process I get following data in the output variable -
<header >
<header xmlns = "http://callhome.pillardata.com/" >
<string xmlns = "http://www.w3.org/2001/XMLSchema" >
1 </string>
<string xmlns = "http://www.w3.org/2001/XMLSchema" >
BrickFlashDataRecord </string>
<string xmlns = "http://www.w3.org/2001/XMLSchema" >
IDcbefc68f </string>
<string xmlns = "http://www.w3.org/2001/XMLSchema" >
A001439BGX </string>
<string xmlns = "http://www.w3.org/2001/XMLSchema" >
2005-12-14T18:00:20-08:00 </string>
</header>
</header>
However I am not able to access data using XPath. Please suggest the proper way to write the WSLD and how to access the returned data in BPEL. Please let me know if further information is required.
Thanks,Hi Justine,
I think you will have to look at the access restrictions on the Universe Folder and the Report itself, in the CMC. It would appear that your security rights did not migrate successfully.
Regards
Alan -
How to Access the Return Value of a Function
Hi,
How do I access the return value when calling an Oracle function from .NET using Oracle.DataAccess.Client? The function returns an integer of 0, 1 or 99.
Dim db_command_oracle As New OracleCommand()
db_command_oracle.Connection = db_connection_oracle
db_command_oracle.CommandType = CommandType.StoredProcedure
db_command_oracle.CommandText = "swsarsi.import_appointments"
Dim ret_value As New OracleParameter()
ret_value.OracleDbType = OracleDbType.Int32
ret_value.Direction = ParameterDirection.ReturnValue
ret_value.Size = 2
ret_value.OracleDbType = OracleDbType.Int32
db_command_oracle.Parameters.Add(ret_value)
Dim IN_student_id As New OracleParameter()
IN_student_id.OracleDbType = OracleDbType.Varchar2
IN_student_id.Direction = ParameterDirection.Input
IN_student_id.Size = 10
IN_student_id.Value = student_id
db_command_oracle.Parameters.Add(IN_student_id)
db_command_oracle.ExecuteNonQuery()
messagebox.show(ret_value) ?????Your ODP.NET code looks correct. What error are you seeing?
One thing that will definitely generate an error is that .NET message boxes require that strings be displayed. ret_value is a parameter object. You need to access its value and convert it to a string. At a minimum, you need to change that. -
Function output (Return sys_refcursor) to excel sheet
Hi,
Could pls anyone let me know how to export the output of a function returning sys_refcursor to excel sheet
with headers.
Tried with file handling but no luck.
Below is my function.
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for select * from tab;
return cv_1;
end;Small example will hlp me a lot.
Thanks in advanceunique wrote:
Hi,
Could pls anyone let me know how to export the output of a function returning sys_refcursor to excel sheet
with headers.
Tried with file handling but no luck.
Below is my function.
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for select * from tab;
return cv_1;
end;Small example will hlp me a lot.
Thanks in advance
create or replace function fn1 return sys_refcursor as
cv_1 SYS_REFCURSOR;
begin
open cv_1 for
(select 'headings for each column' from dual
union all
select to_char(all_columns) from tab);
return cv_1;
end; -
"Assign Access Control" returns error for essbase apps in shared services
Hello,
I installed and configured Oracle EPM 11.1.2 (Foundation, Essbase, Planning, Reporting&Analysis):
OS: Windows Server 2008 Sp2 (32bit)
Default Installation with default ports,
Installation of all components on the same server,
no clustering
EPM System Diagnostic says that everything is OK.
Now I want to assign filter access for an essbase database in the Shared Services.
Starting the menu item "Assign Access Control" in Shared Services returns the following error:
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
+10.4.5 404 Not Found+
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
+....+
Can anybody help ???
best regards,
NicoleHello,
here's what I found out so far:
I get the error if I start the shared services console via the URL "http://servername:port/interop/index.jsp" and then select the "assign access control" for an essbase database.
If I start the shared services console via the workspace everything works fine.
Does anybody know what to do so that it also works if I start the shared services console via URL?
best regards,
Nicole -
Access and return properties of placedItem.file
I'm trying to assign properties of placedItem.file. However, whenever I try to access placedItem.file it prints/returns "undefined is not an object".
I've used the alert command to print the object e.g. alert(placedItem.file) and it prints the file location of the image. However, when I try to assign that value to a variable ( var exampleName = placedItem.file ) it also returns the same error.
I've also tried accessing sub properties of file, like file.fullName and file.displayName. It returns the same error. If anyone has insight that would be awesome. I really just need to return the path of an image to a variable.The mystery property does not appear to be documented in the CC OMV, but it does appear in the Data Browser.
function test(){
var doc = app.activeDocument;
var p = doc.pageItems[0];
alert(p.name+". Normal Z-Order: "+p.zOrderPosition+", Absolute Z-Order: "+p.absoluteZOrderPosition);
test();
The above code used on doc screen-shot below prints out: Grp_2. Normal Z-Order: 7, Absolute Z-Order: 13
My experiment here, suggests that absolute order takes into account the child elements of all elements (to show z-order in entire document), and the 'regular' z-order is about the stacking within a container element.
Like layer.pageItems vs document.pageItems ?
Though when I first looked at this property inside one of my more cluttered real-life documents, I remember that I couldn't verify this relationship. Maybe I was tired or something. -
Accessing a return String value
Hi there, I think this is simple question, but for a newbie - brain mashed!
I'm trying to access a String value from a Class (Something) into another Class (SomethingElse); can someone direct me in the right direction?
Class Something {
public String stuff( Message msg ) {
String sb = new String();
..some operation..
return sb;
Class Something {
..Need sb value!!
Cheers for the advice!// ..Need sb value!! -- Here we go
Message myMessage = new Message(); // Does the constructor take arguments? I don't know...
String valueOfSb = mySomething.stuff(myMessage); // <--- You get sb here;) Patrick -
Querying PL/SQL function which returns SYS_REFCURSOR
Hello:
I have a PL/SQL function with return type of SYS_REFCURSOR.
In SQLPlus, I can query it either as
var c refcursor
exec :c := func(...)
print c
or
select func(...) from dual;
Running the latter in Eclipse 3.3 with oracle DTP extensions installed gives me OracleResultSetImpl object in the SQL Results view.
Can the code be a little smarter and recognize that a sql query may return "indirect" resultset?
Regards,
ErnestThis is noted; will be the interface better to handle the return values. Thanks
-
[perl] How call function/procedure that returns SYS_REFCURSOR type?
I've got some simple procedure which returns record(s):
CREATE OR REPLACE PROCEDURE "GET_SYS_DATE"
RESULTSET IN OUT SYS_REFCURSOR
IS
BEGIN
OPEN RESULTSET FOR
SELECT SYSDATE FROM DUAL;
END;
In perl i invoke it with somthing like this:
my $ret;
my $s= "BEGIN GET_SYS_DATE(:1); END;";
my $sth = $dbh->prepare($s);
$sth->bind_param_inout(1, \$ret, 0 { TYPE => XXX}); # tried to use many DBD::SQL_* types (SQL_ROW, SQL_REF, etc.)
$sth->execute(); #... but without luck
I always get:
DBD::ODBC::st execute failed: [Oracle][ODBC][Ora]ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GET_SYS_DATE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Of course if i use other datatype in SP (e.g. VARCHAR2) and bind it as SQL_VARCHAR it works well... Moreover, if i use DBD::Oracle and bind it as ORA_RSET type it also works.
Is it possible that ODBC doesn't know SYS_REFCURSOR type? Then, is there any way to call SP and retrieve cursor from perl without using DBD::Oracle?
Or, if it is possible, then how to retrieve that cursor and data stored within it? Any help?Hi,
I have not one eensy teensy bit of knowledge about PERL, other than how to spell it.
I do however, know about ref cursors, and ODBC, so maybe this will help.
ODBC has nothing for REF CURSOR built in. ODBC is made to the lowest common denoninator of databases, and a refcur is an Oracle thing. So, what that means is that you can't BIND anythign to the ref cursor, as there is no appropriate ODBC type to bind.
Does that mean you can't call a refcur via ODBC? No, it doesnt.
What happens is that Oracle's ODBC driver kinda "magically" goes out behind the scenes and describes the procedure or pacakge to determine if any of the parameters are ref cursors, and if so automatically sets up the bind for them.
Here's a complete working example using VB and ADO rather than PERL, but maybe you can port it over and get it working. Note that the proc takes two params, but we only bind one (for the IN number)
Hope it helps,
Greg
'create or replace package testrefcur as
' type mycur is ref cursor;
' procedure getemps(dno in number, ecur out mycur);
' end;
'create or replace package body testrefcur as
'procedure getemps(dno in number, ecur out mycur) is
' begin
' open ecur for select * from emp where deptno = dno;
' end;
'end;
Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
strcnn = "dsn=orcl;uid=scott;pwd=tiger"
con.Open strcnn
cmd.CommandText = "{call testrefcur.getemps(?)}"
Set cmd.ActiveConnection = con
Set param1 = cmd.CreateParameter("param1", adNumeric, adParamInput, 4)
param1.Value = 10
param1.Precision = 4
cmd.Parameters.Append param1
Set rst = cmd.Execute
While Not rst.EOF
strrslt = strrslt & rst.Fields("ename").Value & " "
rst.MoveNext
Wend
MsgBox strrslt
End Sub -
Limit user Access to Return Data in Report
Have reporst that I need to limit what is returned. The person running the report should only see the data that they own. Is this possible. Can I set an attribute based on the person who has signed on to Discoverer and use that in the select to limit the data returned.
Thanks,
DanYes, it's possible!
You can use the VPD (Virtuall Private Database) feature of the database.
Check out the following stuff:
http://www.oracle.com/oramag/oracle/99-Jul/index.html?49sec.html
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adgsec02.htm
http://www.oracle-base.com/Articles/8i/VirtualPrivateDatabases(VPD).asp -
Accessing realm returns "Forbidden" error
We host other people's Web sites. Each customer has access to their Web folder via AFP. Within their folder, we want to have a password-protected folder that has their Web log files. Coming from WebSTAR, we know about realms, so we set one up via Server Admin. The customer has browse/author permission, and our group has the same. Problem is, I keep getting a Forbidden error when I try to access the protected folder. The way Apple documents realms, it sounds like they're intertwined with WebDAV, so I enabled WebDAV, but still no go. The following is in the site's conf file:
<Directory "path-to-protected-folder">
<Limit GET HEAD OPTIONS CONNECT POST PROPFIND PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user customer-user-name
Require group our-group-name
</Limit>
AuthName "realm-name"
AuthType Basic
</Directory>
It looks good to me, as far as I understand it. Can anyone point me in the right direction to getting past "Forbidden"? Thanks.
Mac Mini Mac OS X (10.4.4)Try Camelot's suggestion, and if that doesn't do it,
take a look at error_log (/var/log/httpd/error_log)
and see what it says, and post the relevant
messages.
The appleauthmodule is active. The error log had one line related to my access attempt:
[Mon Feb 20 12:30:22 2006] [error] [client 66.241.88.36] "Directory index forbidden by rule: /Library/WebServer/Documents/Sites/chas/stats/"
I seem to remember getting this error while evaluating OS X Server a while back, and it was a file or folder permissions problem. In the path name in the error log line above, folders Sites, chas and stats all have read and write permissions for group webadmin (which contains our staff users and user Web), and no permissions for Everyone. The latter is to keep Web customers from being able to access each other's folders. With a browser, accessing Web pages works fine, but trying to access the stats folder gives the immediate Forbidden error. Do you see anything in these permissions that seems suspicious?
Also, in Terminal, run:
apachectl configtest
apachectl reported OK syntax for all config files. Thanks for your help. -
Limit access on returned Collection
Hello, is it possible to write a method to return a collection and don't allow the caller to add or remove objects from the collection, but allow the caller modify the objects in the collection.
Hello, is it possible to write a method to return a
collection and don't allow the caller to add or remove
objects from the collection, but allow the caller
modify the objects in the collection.Well there is nothing to stop someone from modifying the object in a Collection other than through that Collection itself.
Do you mean you want to allow people to replace immutable objects like Strings but not add or remove them?
The only Collections this would seem to make any sense for are Lists. YOu ca nso this pretty easily. extend AbstractList and implement the get(index) and size methods. Then implement the set(index. object) method so that it throws an exception if the index >= size.
Oh here it is:
UpdateableList extends AbstractList {
List list;
public UpdateableList(List list) {
if (list == null) throw new IllegalArgumentException();
this.list = list;
public Object get(int index) {
return list.get(index);
public int size() {
return list.size();
public Object set(int index, Object object) {
if (index >= size) throw new IndexOutOfBoundsException();
return list.set(index, object);
}Note, I'm not sure but allowing the set method may open up the add other methods, so you might need to throw UnsupportedOperationException in those methods. -
How to pass value object to BPM process and access process returned data
Hi,
I am new to Oracle BPM studio and gone through the tutorial. I did not find anywhere how to orchestrate the java components or ejb components or web services in BPM process. if any one provide sample business process orchestered with java component or ejb component or webservice, it will be great. Or atleast provide steps to do that.
Thanks and Regards
Mahesh BabuThere is a tutorial available online.. But you can always catalogue web services and JARs files into the ALBPM..
Just create a new module inside the Catalogue and then right click on it to see Catalogue Component and then select what component u want to add to ALBPM and then follows the steps of adding that component from your local machine and introspecting it..
If it is successful, then all the web-service methods or the JAR file methods would be catalogued into ALBPM..
You can put the WSDL address in the space provided for Web Services.. If password is required that too can be put..
Another way is to create a component in External Resources and then Cataloguing it... -
JDBC ResultSet and direct D/B access are returning different no. of rows
I am testing a JDBC application, which is using a DataSource definition configured in Visual Admin under JDBC Connector node.
This program gets the JDBC Connection via lookup thro' JNDIContext.
What is interesting is I am getting different no. of rows from ResultSet compared to direct execution in the Query Analyser.
SELECT DISTINCT IC.ship_to_num, IC.policy_type, IC.exp_date, IC.insurance_cert_id
FROM site_user SU
INNER JOIN user_bill_to UB ON SU.user_id = UB.user_id
INNER JOIN insurance_cert IC ON UB.ship_to_num = IC.ship_to_num
WHERE (DATEDIFF(dd, GETDATE(), IC.exp_date) <= 14)
AND (DATEDIFF(dd, GETDATE(), IC.exp_date) > 5)
AND IC.breaking_14_day_alert_date IS NULL
AND (SU.customer_id = 'dealer') AND (SU.is_owner = '1')
(3 in Qu.Analyser Vs. 0 from JDBC)
Or
SELECT * FROM message_target
(405 in Qu.Analyser Vs. 380 from JDBC)
I compared the JDBC program code results Vs. "DB Initialisation" tab result in Visual Admin tool Vs. Direct 'Query Analyser' of SQL Server results.
The programmatic JDBC results are equal to "DB Initialisation" tab results !
What is wrong here ?
Any help is greately appreciated.
Thanks,
Prasad NutalapatiHi Prasad,
I have never experienced this problem, but after taking a quick look at the javadoc for some JDBC classes, I found something that may help.
Try looking into the <i>setMaxRows</i> method on the <i>Statement</i> class. The URL below will take you to the complete javadoc for this class, however, here is the part that I believe relates to your problem:
"...If the limit is exceeded, the excess rows are silently dropped."
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html
If you are not setting this limit explicitly in your code, the JDBC driver implementation may be using some default value.
Setting this value to zero means that there is no limit, so you may want to try that.
Kind regards,
Mike
Maybe you are looking for
-
I have created a links list and added that webpart to a page in office 365 for sharepoint. When the user clicks on a links it needs to be opened in new tab how to impletement. I tried with javascript content editor webpart but it is removing the sc
-
Differences: Outlooksoft 4.x Vs. SAP BPC 7.0 MS
Hello, I need urgently the following information: - What were the specifications of version 4 of OutlookSoft? - What are the improvements and differences involved in SAP BPC 7.0 MS compared to OutlookSoft 4 in all possible areas (security, architectu
-
After upgrading my iPhone 5s to iOS 8.0.2 my "Clash Of Clans" (Game) Works week and slow, it takes a long time to load maps, sending messages and etc... does any body have same problem ? Or the problem is from my device ?!
-
I used to do this with no problem. When I try to export to iDVD I get the following error "The movie could not be sent to iDVD, because of an unknown error. Please make sure that iDVD is properly installed, that your disk has write permission, and th
-
Communicating with COM port.
Hi Experts, There is a electronic weighing machine and has a COM port ( communication port). Can we connect to the COM port through ABAP? I need to read the weight of the measured component to a table control directly from the weighing machine. Tha