Return data from Oracle for Crystal [message #470299] |
Mon, 09 August 2010 09:05 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Hi, I have problems in Oracle returning data from a stored procedure. In MS SQL it's quite simple.
i.e.
CREATE OR REPLACE PACKAGE globalpkg
AS
TYPE RCT1 IS REF CURSOR;
TRANCOUNT INTEGER := 0;
IDENTITY INTEGER;
END;
/
next the stored procedure:
CREATE OR REPLACE PROCEDURE mytest
(
RCT1 OUT GLOBALPKG.RCT1
)
AS
BEGIN
OPEN RCT1 FOR
SELECT *
FROM EMPLOYEE;
END;
Next trying to run the Stored procedure:
VARIABLE resultSet REFCURSOR
EXEC mytest (:resultSet);
Result always returns this error:
REFCURSOR - Unrecognized type.
I have tried using sample on the internet, but all returns the same error, what am I missing
Thanks in advance
Michael
|
|
|
|
|
Re: Return data from Oracle for Crystal [message #470305 is a reply to message #470299] |
Mon, 09 August 2010 09:14 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Hi, thanks for a quick reply
CREATE OR REPLACE PACKAGE globalpkg
AS
TYPE RCT1 IS REF CURSOR;
TRANCOUNT INTEGER := 0;
IDENTITY INTEGER;
END;
/
CREATE OR REPLACE PROCEDURE mytest
(
RCT1 OUT GLOBALPKG.RCT1
)
AS
BEGIN
OPEN RCT1 FOR
SELECT *
FROM EMPLOYEE;
END;
/
VARIABLE resultSet REFCURSOR;
EXEC mytest (:resultSet);
="Line",="Pos",="Text"
1,,"Create package, executed in 0 sec."
10,,"Create procedure, executed in 0.015 sec."
22,,REFCURSOR - Unrecognized type.
,,Total execution time 0.015 sec.
|
|
|
|
Re: Return data from Oracle for Crystal [message #470307 is a reply to message #470306] |
Mon, 09 August 2010 09:21 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Using SQL TOOLS (1.4.2), when I try to use the Stored Procedure in Business Objects 3.1 universe designer I get this error:
Execption: DBD, ORA-06550: line1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYTEST'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
State: N/A
|
|
|
|
|
Re: Return data from Oracle for Crystal [message #470311 is a reply to message #470309] |
Mon, 09 August 2010 09:24 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Hi BlackSwan,
This should be it
CREATE OR REPLACE PACKAGE globalpkg
AS
TYPE RCT1 IS REF CURSOR;
TRANCOUNT INTEGER := 0;
IDENTITY INTEGER;
END;
/
CREATE OR REPLACE PROCEDURE mytest
(
RCT1 OUT GLOBALPKG.RCT1
)
AS
BEGIN
OPEN RCT1 FOR
SELECT *
FROM EMPLOYEE;
END;
/
--Running the sp
VARIABLE resultSet REFCURSOR;
EXEC mytest (:resultSet);
Result:
="Line",="Pos",="Text"
1,,"Create package, executed in 0 sec."
10,,"Create procedure, executed in 0.015 sec."
22,,REFCURSOR - Unrecognized type.
,,Total execution time 0.015 sec.
|
|
|
|
|
|
|
|
|
|
Re: Return data from Oracle for Crystal [message #470324 is a reply to message #470299] |
Mon, 09 August 2010 10:03 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
If if create it outside the sp then i can get it to work, but I would like to have it inside, i.e.
PROMPT CREATE OR REPLACE PROCEDURE p
CREATE OR REPLACE procedure p2 (p_cur in out sys_refcursor)
is
begin
CREATE GLOBAL TEMPORARY TABLE my_temp_table2 (name1 VARCHAR(255), name2 VARCHAR(255));
INSERT INTO my_temp_table2
select Name1, Name2 from EXEMPLOYEE where rownum<=3
open p_cur for select * from my_temp_table2;
end;
/
Results in
Line Pos Text
1 PROMPT CREATE OR REPLACE PROCEDURE p
2 Create procedure, executed in 0.016 sec.
6 5 PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
Total execution time 0.032 sec.
|
|
|
|
Re: Return data from Oracle for Crystal [message #470328 is a reply to message #470325] |
Mon, 09 August 2010 10:12 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Any chance that you can provide me with a sample "solving" this:
PROMPT CREATE OR REPLACE PROCEDURE p
CREATE OR REPLACE procedure p2 (p_cur in out sys_refcursor)
is
begin
CREATE GLOBAL TEMPORARY TABLE my_temp_table2 (name1 VARCHAR(255), name2 VARCHAR(255));
INSERT INTO my_temp_table2
select Name1, Name2 from EXEMPLOYEE where rownum<=3;
open p_cur for select * from my_temp_table2;
end;
/
|
|
|
|
|
Re: Return data from Oracle for Crystal [message #470334 is a reply to message #470331] |
Mon, 09 August 2010 10:21 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
A Global Temporary Table in Oracle is created ONCE, not every time a procedure runs.
So in your case it would be :
CREATE GLOBAL TEMPORARY TABLE my_temp_table2 (name1 VARCHAR(255), name2 VARCHAR(255));
CREATE OR REPLACE procedure p2 (p_cur in out sys_refcursor)
is
begin
INSERT INTO my_temp_table2
select Name1, Name2 from EXEMPLOYEE where rownum<=3;
open p_cur for select * from my_temp_table2;
end;
/
Every database session can see the Global Temporary Table, but the contents is session-specific, that is the session sees only it's own data.
|
|
|
Re: Return data from Oracle for Crystal [message #470335 is a reply to message #470334] |
Mon, 09 August 2010 10:26 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
One further thing.
One way to preserve the "multiple selects into temporary tables that are then used in another select" from SQL Server in Oracle would be to use the WITH clause, for example:
WITH my_temp_table1 AS (SELECT 10 c1,20 c2 FROM dual),
my_temp_table2 AS (SELECT 10 c3,30 c4 FROM dual)
SELECT *
FROM my_temp_table1
join my_temp_table2 ON c3=c1
|
|
|
Re: Return data from Oracle for Crystal [message #470337 is a reply to message #470299] |
Mon, 09 August 2010 10:33 |
Michael Gaarde
Messages: 29 Registered: August 2010
|
Junior Member |
|
|
Thanks Thomas
I tried creating the temp table out side the sp, but when I use it in Business Objects I get
"Exception: DBD, ORA-08103: object no longer exists, State: N/A"
which kind of makes sense as the temp table was created in another session ?
Could the solution be to have a permanent table using i.e. sys_guid as a unique identifier ?
|
|
|
Re: Return data from Oracle for Crystal [message #470338 is a reply to message #470324] |
Mon, 09 August 2010 10:36 |
cookiemonster
Messages: 13962 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You'd need to use execute immediate to create the table in the procedure but I really wouldn't.
If you really need a temp table (and I doubt you do) then create it seperately and just insert/update/delete it in your procedure.
Or better yet don't use one at all.
The reasons why they get used in mssql do not apply to oracle.
EDIT: added some extra words since my reply no longer made sense due to additional replies.
[Updated on: Mon, 09 August 2010 10:38] Report message to a moderator
|
|
|
Re: Return data from Oracle for Crystal [message #470339 is a reply to message #470337] |
Mon, 09 August 2010 10:37 |
cookiemonster
Messages: 13962 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Michael Gaarde wrote on Mon, 09 August 2010 16:33Thanks Thomas
I tried creating the temp table out side the sp, but when I use it in Business Objects I get
"Exception: DBD, ORA-08103: object no longer exists, State: N/A"
which kind of makes sense as the temp table was created in another session ?
It doesn't actually. Global Temporary tables are permanent objects. It's only the data in them that is temporary.
|
|
|
|
|
Re: Return data from Oracle for Crystal [message #470343 is a reply to message #470341] |
Mon, 09 August 2010 10:41 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
Quote:
...
so with the given time in mind
...
thousand+ lines of codes with calls to webservices etc.
If there are "webservices etc..." also, then it might not be possible in the in the "given time in mind", since webservices etc.. also work completely different in Oracle.
|
|
|
|
Re: Return data from Oracle for Crystal [message #470346 is a reply to message #470345] |
Mon, 09 August 2010 10:51 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
Then you have an error in your code somewhere. It works that way:
First session to create the objects:
SQL*Plus: Release 9.2.0.8.0 - Production on Mon Aug 9 17:48:23 2010
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE GLOBAL TEMPORARY TABLE my_temp_table2 (name VARCHAR(255));
Table created.
SQL>
SQL> CREATE OR REPLACE procedure p2 (p_cur in out sys_refcursor)
2 is
3 begin
4
5 INSERT INTO my_temp_table2
6 select 'foo' FROM dual;
7
8 open p_cur for select * from my_temp_table2;
9 end;
10 /
Procedure created.
SQL>
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64
bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
New Session that calls the procedure:
SQL*Plus: Release 9.2.0.8.0 - Production on Mon Aug 9 17:48:49 2010
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> VARIABLE resultSet REFCURSOR
SQL> EXEC p2 (:resultSet);
PL/SQL procedure successfully completed.
SQL> print resultset
NAME
--------------------------------------------------------------------------------
foo
SQL>
|
|
|
|
|