calling oracle SP which returns ref.cursor using STP

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

Hi,
STP stage does not support type of ref cusor. This feature is on my wish list since last year. And I am still waiting....waiting....and ......
rleishman
Premium Member
Premium Member
Posts: 252
Joined: Mon Sep 19, 2005 10:28 pm
Location: Melbourne, Australia
Contact:

Post by rleishman »

Look in the Oracle PL/SQL doco for pipelined functions. You could create an interface that essentially converts the REF CURSOR into a View, then select from the VIEW in a normal OCI stage.
Ross Leishman
jagadhish
Participant
Posts: 14
Joined: Thu Jan 19, 2006 6:05 am

Post by jagadhish »

Hi,

Thanks for your information. If STP doesn't support Ref. cursor, is it possible to call that procedure using routine and get the result set?
Any help is greatly appreciated....


Thanks and regards,
Jags.
REGARDS,
JAGS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Does this really need to be in a SP? Why not convert it to a 'normal' OCI query?
-craig

"You can never have too many knives" -- Logan Nine Fingers
jagadhish
Participant
Posts: 14
Joined: Thu Jan 19, 2006 6:05 am

Post by jagadhish »

Hi,

The SP is already existing one, we cant change it. Can I use shell script to call that procedure process the result set...

please give your inputs.
REGARDS,
JAGS
rleishman
Premium Member
Premium Member
Posts: 252
Joined: Mon Sep 19, 2005 10:28 pm
Location: Melbourne, Australia
Contact:

Post by rleishman »

OK. So you have a SP like this:

Code: Select all

CREATE PROCEDURE my_proc(p1 IN NUMBER, rc OUT sys_refcursor) ...
Create a type that contains the same columns as the cursor, and a pipelined function to fetch the cursor.

Code: Select all

CREATE TYPE my_typ AS OBJECT (
  col1 VARCHAR2(20)
, col2 NUMBER
);

CREATE TYPE my_typ_ary AS TABLE OF my_typ;

Code: Select all

CREATE FUNCTION my_func (p1 IN NUMBER) 
RETURN my_typ_ary PIPELINED AS
  rc SYS_REFCURSOR;
  t my_typ;
BEGIN
  my_proc(p1, rc);
  t := my_typ();

  LOOP
    FETCH rc INTO t.col1, t.col2;
    EXIT WHEN rc%NOTFOUND;

    PIPE ROW(t);
  END LOOP;
END;
Now use a SQL to extract the data in a normal OCI stage:

Code: Select all

SELECT *
FROM CAST(TABLE(my_func(1234)) AS my_typ_ary)
Ross Leishman
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

jagadhish wrote:The SP is already existing one, we cant change it.
Just for the record, I didn't suggest you change it - I suggested you pitch it. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ratikmishra1
Charter Member
Charter Member
Posts: 42
Joined: Wed Aug 18, 2004 2:49 pm

Post by ratikmishra1 »

I use ODBC stage to read ref cursors returned from oracle stored procedures.

You should have only one output parameter for the ref cursor.
Define the columns that you expect to get from the cursor.

and you are good to go.
lstsaur
Participant
Posts: 1139
Joined: Thu Oct 21, 2004 9:59 pm

Post by lstsaur »

Hi,
That's why I said in my previous post that handling type of ref cursor feature should be built within STP stage. I hope that Ascential is reading this thread. Of course, there are some other ways to get Oralce's type of ref cursor to work, but just NOT from thier proud STP stage?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why not post a request on the Enhancements Wish List forum? Here or DeveloperNet or both.
Last edited by ray.wurlod on Sat Apr 22, 2006 1:58 am, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jagadhish
Participant
Posts: 14
Joined: Thu Jan 19, 2006 6:05 am

Post by jagadhish »

Hi rleishman

Im trying out pipelined function. but while creating the function,

CREATE FUNCTION my_func (p1 IN NUMBER)
RETURN my_typ_ary PIPELINED AS
rc SYS_REFCURSOR;
t my_typ;
BEGIN
my_proc(p1, rc);
t := my_typ();

LOOP
FETCH rc INTO t.col1, t.col2;
EXIT WHEN rc%NOTFOUND;

PIPE ROW(t);
END LOOP;
END;




for the statement t := my_typ(); I'm getting following error message,

PL/SQL: Statement ignored
PLS-00306: wrong number or types of arguments in call to
'my_typ'


If I remove that statement t := my_typ(); funtion executes without any error.. could u please tell me what is couse for this ....

thanks,
REGARDS,
JAGS
rleishman
Premium Member
Premium Member
Posts: 252
Joined: Mon Sep 19, 2005 10:28 pm
Location: Melbourne, Australia
Contact:

Post by rleishman »

If it works, go for it. I thought it would need a constructor. I still haven't unravelled all of the wonders of Oracle's object-relation features.
Ross Leishman
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Why dont you have the SP created in the Oracle instead of creating it at runtime. And then you can call the SP just simply using the STP stage.
In that stage you dont need to paste in the whole SP instead you just call.
Let the stage know the input and output params.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Or you can even call it from the OCI stage from an after SQL.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rleishman
Premium Member
Premium Member
Posts: 252
Joined: Mon Sep 19, 2005 10:28 pm
Location: Melbourne, Australia
Contact:

Post by rleishman »

I wasn't advocating putting any DDL in the DataStage job to be created at runtime. The function and type DDL statements are executed once only during setup. The only runtime SQL is the SELECT .. FROM TABLE(func(..)).

I think the OP gets this and is on the right track.
Ross Leishman
Post Reply