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 function 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 parameters, so the question should be seen in that context.
Each field assumes the data type of its corresponding column. The %ROWTYPE attribute is prefixed by a cursor name or a cursor variable name. The syntax is record cursor%ROWTYPE , where record is an identifier that is assigned to the record, and cursor is an explicitly declared cursor within the current scope.
Example# %TYPE : Used to declare a field with the same type as that of a specified table's column. %ROWTYPE: Used to declare a record with the same types as found in the specified table, view or cursor (= multiple columns).
The %ROWTYPE attribute provides a record type that represents a row in a database table. The record can store an entire row of data selected from the table or fetched from a cursor or cursor variable. Fields in a record and corresponding columns in a row have the same names and datatypes.
%TYPE provides the data type of a variable or a database column to that variable. %ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in the cursor.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With