Is it possible to use an object as the parameter of a UDF in Oracle/SQL?
up vote
0
down vote
favorite
Is there a way to use an object as an input parameter of a UDF ? As I am trying bellow:
CREATE OR REPLACE TYPE fv_group as object(
fv NUMBER,
group_number INTEGER
);
/
CREATE OR REPLACE TYPE fv_group_array IS VARRAY(100) OF fv_group;
CREATE OR REPLACE PROCEDURE insert_groupby(FV NUMBER, fv_and_group IN OUT fv_group_array) IS
g fv_group;
BEGIN
IF fv < 15 THEN
g := fv_group(fv,1);
ELSE
g := fv_group(fv,2);
END IF;
fv_and_group.extend(1);
fv_and_group(fv_and_group.last) := g;
END;
/
declare
obj fv_group_array := fv_group_array();
begin
select insert_groupby(c.fv,obj)
from cophir c;
end;
/
When I execute the code above I get the error
PL/SQL: ORA-00904.
PS .. Table cophir:
SQL> desc cophir
Nome Tipo
FV NUMBER(38)
ID NUMBER(38)
oracle stored-procedures plsql oracle12c
add a comment |
up vote
0
down vote
favorite
Is there a way to use an object as an input parameter of a UDF ? As I am trying bellow:
CREATE OR REPLACE TYPE fv_group as object(
fv NUMBER,
group_number INTEGER
);
/
CREATE OR REPLACE TYPE fv_group_array IS VARRAY(100) OF fv_group;
CREATE OR REPLACE PROCEDURE insert_groupby(FV NUMBER, fv_and_group IN OUT fv_group_array) IS
g fv_group;
BEGIN
IF fv < 15 THEN
g := fv_group(fv,1);
ELSE
g := fv_group(fv,2);
END IF;
fv_and_group.extend(1);
fv_and_group(fv_and_group.last) := g;
END;
/
declare
obj fv_group_array := fv_group_array();
begin
select insert_groupby(c.fv,obj)
from cophir c;
end;
/
When I execute the code above I get the error
PL/SQL: ORA-00904.
PS .. Table cophir:
SQL> desc cophir
Nome Tipo
FV NUMBER(38)
ID NUMBER(38)
oracle stored-procedures plsql oracle12c
How iscophir
defined?
– William Robertson
Nov 10 at 23:28
Added this information to the question.
– Pedro
Nov 11 at 0:36
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is there a way to use an object as an input parameter of a UDF ? As I am trying bellow:
CREATE OR REPLACE TYPE fv_group as object(
fv NUMBER,
group_number INTEGER
);
/
CREATE OR REPLACE TYPE fv_group_array IS VARRAY(100) OF fv_group;
CREATE OR REPLACE PROCEDURE insert_groupby(FV NUMBER, fv_and_group IN OUT fv_group_array) IS
g fv_group;
BEGIN
IF fv < 15 THEN
g := fv_group(fv,1);
ELSE
g := fv_group(fv,2);
END IF;
fv_and_group.extend(1);
fv_and_group(fv_and_group.last) := g;
END;
/
declare
obj fv_group_array := fv_group_array();
begin
select insert_groupby(c.fv,obj)
from cophir c;
end;
/
When I execute the code above I get the error
PL/SQL: ORA-00904.
PS .. Table cophir:
SQL> desc cophir
Nome Tipo
FV NUMBER(38)
ID NUMBER(38)
oracle stored-procedures plsql oracle12c
Is there a way to use an object as an input parameter of a UDF ? As I am trying bellow:
CREATE OR REPLACE TYPE fv_group as object(
fv NUMBER,
group_number INTEGER
);
/
CREATE OR REPLACE TYPE fv_group_array IS VARRAY(100) OF fv_group;
CREATE OR REPLACE PROCEDURE insert_groupby(FV NUMBER, fv_and_group IN OUT fv_group_array) IS
g fv_group;
BEGIN
IF fv < 15 THEN
g := fv_group(fv,1);
ELSE
g := fv_group(fv,2);
END IF;
fv_and_group.extend(1);
fv_and_group(fv_and_group.last) := g;
END;
/
declare
obj fv_group_array := fv_group_array();
begin
select insert_groupby(c.fv,obj)
from cophir c;
end;
/
When I execute the code above I get the error
PL/SQL: ORA-00904.
PS .. Table cophir:
SQL> desc cophir
Nome Tipo
FV NUMBER(38)
ID NUMBER(38)
oracle stored-procedures plsql oracle12c
oracle stored-procedures plsql oracle12c
edited Nov 11 at 0:34
asked Nov 10 at 21:21
Pedro
455
455
How iscophir
defined?
– William Robertson
Nov 10 at 23:28
Added this information to the question.
– Pedro
Nov 11 at 0:36
add a comment |
How iscophir
defined?
– William Robertson
Nov 10 at 23:28
Added this information to the question.
– Pedro
Nov 11 at 0:36
How is
cophir
defined?– William Robertson
Nov 10 at 23:28
How is
cophir
defined?– William Robertson
Nov 10 at 23:28
Added this information to the question.
– Pedro
Nov 11 at 0:36
Added this information to the question.
– Pedro
Nov 11 at 0:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
To answer your question: yes, you can pass objects to a UDF. But that's not your problem.
In the anonymous block at the end of your code you've got the statement
select insert_groupby(c.fv,obj)
from cophir c;
However, insert_groupby
is a procedure. Procedures cannot be called from SQL statements because they don't return a value. You might be able to change insert_groupby
into a function, but you'll need to figure out what it should return.
Another option is to use a loop:
declare
obj fv_group_array := fv_group_array();
begin
FOR aRow IN (SELECT fv FROM cophir)
LOOP
insert_groupby(aRow.fv, obj);
END LOOP;
end;
Best of luck.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
To answer your question: yes, you can pass objects to a UDF. But that's not your problem.
In the anonymous block at the end of your code you've got the statement
select insert_groupby(c.fv,obj)
from cophir c;
However, insert_groupby
is a procedure. Procedures cannot be called from SQL statements because they don't return a value. You might be able to change insert_groupby
into a function, but you'll need to figure out what it should return.
Another option is to use a loop:
declare
obj fv_group_array := fv_group_array();
begin
FOR aRow IN (SELECT fv FROM cophir)
LOOP
insert_groupby(aRow.fv, obj);
END LOOP;
end;
Best of luck.
add a comment |
up vote
3
down vote
To answer your question: yes, you can pass objects to a UDF. But that's not your problem.
In the anonymous block at the end of your code you've got the statement
select insert_groupby(c.fv,obj)
from cophir c;
However, insert_groupby
is a procedure. Procedures cannot be called from SQL statements because they don't return a value. You might be able to change insert_groupby
into a function, but you'll need to figure out what it should return.
Another option is to use a loop:
declare
obj fv_group_array := fv_group_array();
begin
FOR aRow IN (SELECT fv FROM cophir)
LOOP
insert_groupby(aRow.fv, obj);
END LOOP;
end;
Best of luck.
add a comment |
up vote
3
down vote
up vote
3
down vote
To answer your question: yes, you can pass objects to a UDF. But that's not your problem.
In the anonymous block at the end of your code you've got the statement
select insert_groupby(c.fv,obj)
from cophir c;
However, insert_groupby
is a procedure. Procedures cannot be called from SQL statements because they don't return a value. You might be able to change insert_groupby
into a function, but you'll need to figure out what it should return.
Another option is to use a loop:
declare
obj fv_group_array := fv_group_array();
begin
FOR aRow IN (SELECT fv FROM cophir)
LOOP
insert_groupby(aRow.fv, obj);
END LOOP;
end;
Best of luck.
To answer your question: yes, you can pass objects to a UDF. But that's not your problem.
In the anonymous block at the end of your code you've got the statement
select insert_groupby(c.fv,obj)
from cophir c;
However, insert_groupby
is a procedure. Procedures cannot be called from SQL statements because they don't return a value. You might be able to change insert_groupby
into a function, but you'll need to figure out what it should return.
Another option is to use a loop:
declare
obj fv_group_array := fv_group_array();
begin
FOR aRow IN (SELECT fv FROM cophir)
LOOP
insert_groupby(aRow.fv, obj);
END LOOP;
end;
Best of luck.
answered Nov 10 at 23:44
Bob Jarvis
33.4k55783
33.4k55783
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243525%2fis-it-possible-to-use-an-object-as-the-parameter-of-a-udf-in-oracle-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How is
cophir
defined?– William Robertson
Nov 10 at 23:28
Added this information to the question.
– Pedro
Nov 11 at 0:36