views:

2501

answers:

3

I have an oracle function which has an in parameter which is of rowtype of a table, from a select statement i need to pass the current row to this fucntion so that it does some processing and returns a value. Is there a pseudo variable that can be used within the context of a select statement something equivalent to a old and new in trigger.

I would like to do something like

select *,function1(rowtype) from table1

I want to avoid passing multiple paramaters, so the question should be seen in that context.

A: 

Why not just pass the id of the row in and make the function work on that?


EDIT: You might be able to construct an OBJECT / TYPE on the fly and pass that to a function. Then you'll only need to query for the data once. Let me know if you need an example.


cagcowboy
in that case i need to fetch the row information again
Dinesh Manne
A: 

You can do this:

DECLARE
    foo table1%ROWTYPE;
BEGIN
     function1(foo);
END;
Colin Pickard
this needs to be a single select statement, if i go through PL/SQL then i do have many options
Dinesh Manne
+2  A: 

You can't do this with %ROWTYPE. %ROWTYPE is actually a PL/SQL record type, which is not a legal type in SQL, so you can't use it in a SELECT. You should create an object type which has the same columns as the table, change to function to expect that object type instead of %ROWTYPE, and then you can write something like this:

SELECT function(table1_typ(column1, column2, column3))
  FROM table1 t1

Drawbacks: You still have to type all the columns in the SELECT, and if you change the table, you will need to change the object type and the SELECT too.

Gabor Kecskemeti
well i actually was looking for this option since i wanted avoid passing multiple columnns to stored procedure, but if i still need to pass all the columns, i think i am better off passing them to SP then to connvert to a type and then send it.
Dinesh Manne