![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Why is it not possible to pass the whole record to a function? It is, but you are not passing a record to your function. |
#3
| |||
| |||
|
|
Hi, i wonder why this doesn't work: --------------------- snip ---------------------------------------- set serveroutput on drop table tabx; / drop table taby; / create table tabx ( a number, b number ); / create table taby ( a number, b number ); / drop function func; / create function func(rec in tabx%rowtype) return number is begin return 1; end; / declare begin for i in 1..1000 loop insert into tabx values (i, i); insert into taby values (i, i); end loop; commit; select rec.a, func(rec) from tabx rec; end; / --------------------- snap ---------------------------------------- i get: select rec.a, func(rec) * ERROR at line 9: ORA-06550: line 9, column 21: PL/SQL: ORA-00904: "REC": invalid identifier ORA-06550: line 9, column 2: PL/SQL: SQL Statement ignored Why is it not possible to pass the whole record to a function? - thanks! rgds, Frank |
#4
| |||
| |||
|
|
Why is it not possible to pass the whole record to a function? It is, but you are not passing a record to your function. In your code "rec" is an alias for the table tabx and not a record. Second problem, in Pl/Sql block you cannot just use "select...". You must use cursor or "select...into". Change your code to: declare * *sRec tabx%rowtype; begin * * * * for i in 1..1000 loop * * * * * * * * insert into tabx *values (i, i); * * * * * * * * insert into taby *values (i, i); * * * * end loop; * * * * commit; * * * * select * into sRec from tabx where a=1; make sure this select fetches only one row. * * * * func( sRec); end; http://download.oracle.com/docs/cd/B...b14261/toc.htm HTH Thomas |
#5
| |||
| |||
|
|
On 12 Jan., 15:25, Thomas Olszewicki <Thom... (AT) cpas (DOT) com> wrote: Why is it not possible to pass the whole record to a function? It is, but you are not passing a record to your function. In your code "rec" is an alias for the table tabx and not a record. Second problem, in Pl/Sql block you cannot just use "select...". You must use cursor or "select...into". Change your code to: declare * *sRec tabx%rowtype; begin * * * * for i in 1..1000 loop * * * * * * * * insert into tabx *values (i, i); * * * * * * * * insert into taby *values (i, i); * * * * end loop; * * * * commit; * * * * select * into sRec from tabx where a=1; make sure this select fetches only one row. * * * * func( sRec); end; http://download.oracle.com/docs/cd/B.../b14261/fundam... HTH Thomas You decoupled the function invocation from the SQL command (first SQL, then function) I know that this works. But i want to be able to invoke the function right away in the SQL. let me re-write a bit the example: -------------------------- snip ----------------------------------------- set serveroutput on drop table tabx; / create table tabx ( * * * * a number, * * * * b number ); / drop function funcA; / create function funcA(rec in tabx.a%type) return number is begin * * * * return 1; end; / drop funcB; / create function funcB(rec in tabx%rowtype) return number is begin * * * * return 1; end; / declare * * * * type ton is table of number; * * * * a_values ton; * * * * f_values ton; begin * * * * for i in 1..1000 loop * * * * * * * * insert into tabx *values (i, i); * * * * * * * * insert into taby *values (i, i); * * * * end loop; * * * * commit; -- * * *-- this one works -- * * *select rec.a, funcA(rec.a) bulk collect into a_values, f_values from tabx rec; * * * * -- this does not work * * * * select rec.a, funcB(rec) bulk collect into a_values, f_values *from tabx rec; -- * * *-- this also does not work -- * * *select rec.a, funcB(rec.*) bulk collect into a_values, f_values from tabx rec; end; / -------------------------- snap ----------------------------------------- I need this within the SQL in order to be able to evaluate the result of function call directly in the SQL as well - e.g. to drive joining more tables properly. So is there any way to pass an entire records to a function? If not: why not? - thanks! rgds, Frank- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
On 12 Jan., 15:25, Thomas Olszewicki <Thom... (AT) cpas (DOT) com> wrote: Why is it not possible to pass the whole record to a function? It is, but you are not passing a record to your function. In your code "rec" is an alias for the table tabx and not a record. Second problem, in Pl/Sql block you cannot just use "select...". You must use cursor or "select...into". Change your code to: declare Â* Â*sRec tabx%rowtype; begin Â* Â* Â* Â* for i in 1..1000 loop Â* Â* Â* Â* Â* Â* Â* Â* insert into tabx Â*values (i, i); Â* Â* Â* Â* Â* Â* Â* Â* insert into taby Â*values (i, i); Â* Â* Â* Â* end loop; Â* Â* Â* Â* commit; Â* Â* Â* Â* select * into sRec from tabx where a=1; make sure this select fetches only one row. Â* Â* Â* Â* func( sRec); end; http://download.oracle.com/docs/cd/B...b14261/toc.htm HTH Thomas You decoupled the function invocation from the SQL command (first SQL, then function) I know that this works. But i want to be able to invoke the function right away in the SQL. let me re-write a bit the example: -------------------------- snip ----------------------------------------- set serveroutput on drop table tabx; / create table tabx ( a number, b number ); / drop function funcA; / create function funcA(rec in tabx.a%type) return number is begin return 1; end; / drop funcB; / create function funcB(rec in tabx%rowtype) return number is begin return 1; end; / declare type ton is table of number; a_values ton; f_values ton; begin for i in 1..1000 loop insert into tabx values (i, i); insert into taby values (i, i); end loop; commit; -- -- this one works -- select rec.a, funcA(rec.a) bulk collect into a_values, f_values from tabx rec; -- this does not work select rec.a, funcB(rec) bulk collect into a_values, f_values from tabx rec; -- -- this also does not work -- select rec.a, funcB(rec.*) bulk collect into a_values, f_values from tabx rec; end; / -------------------------- snap ----------------------------------------- I need this within the SQL in order to be able to evaluate the result of function call directly in the SQL as well - e.g. to drive joining more tables properly. So is there any way to pass an entire records to a function? If not: why not? - thanks! |
|
select rec.a, funcB(rec) bulk collect into a_values, f_values from tabx rec; |
#7
| |||
| |||
|
|
On 12 Jan., 15:25, Thomas Olszewicki <Thom... (AT) cpas (DOT) com> wrote: Why is it not possible to pass the whole record to a function? It is, but you are not passing a record to your function. In your code "rec" is an alias for the table tabx and not a record. Second problem, in Pl/Sql block you cannot just use "select...". You must use cursor or "select...into". Change your code to: declare Â* Â*sRec tabx%rowtype; begin Â* Â* Â* Â* for i in 1..1000 loop Â* Â* Â* Â* Â* Â* Â* Â* insert into tabx Â*values (i, i); Â* Â* Â* Â* Â* Â* Â* Â* insert into taby Â*values (i, i); Â* Â* Â* Â* end loop; Â* Â* Â* Â* commit; Â* Â* Â* Â* select * into sRec from tabx where a=1; make sure this select fetches only one row. Â* Â* Â* Â* func( sRec); end; http://download.oracle.com/docs/cd/B...b14261/toc.htm HTH Thomas You decoupled the function invocation from the SQL command (first SQL, then function) I know that this works. But i want to be able to invoke the function right away in the SQL. let me re-write a bit the example: -------------------------- snip ----------------------------------------- set serveroutput on drop table tabx; / create table tabx ( a number, b number ); / drop function funcA; / create function funcA(rec in tabx.a%type) return number is begin return 1; end; / drop funcB; / create function funcB(rec in tabx%rowtype) return number is begin return 1; end; / declare type ton is table of number; a_values ton; f_values ton; begin for i in 1..1000 loop insert into tabx values (i, i); insert into taby values (i, i); end loop; commit; -- -- this one works -- select rec.a, funcA(rec.a) bulk collect into a_values, f_values from tabx rec; -- this does not work select rec.a, funcB(rec) bulk collect into a_values, f_values from tabx rec; -- -- this also does not work -- select rec.a, funcB(rec.*) bulk collect into a_values, f_values from tabx rec; end; / -------------------------- snap ----------------------------------------- I need this within the SQL in order to be able to evaluate the result of function call directly in the SQL as well - e.g. to drive joining more tables properly. So is there any way to pass an entire records to a function? If not: why not? - thanks! I should have also pointed out that you could get around your circular |
![]() |
| Thread Tools | |
| Display Modes | |
| |