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)









share|improve this question
























  • How is cophir defined?
    – William Robertson
    Nov 10 at 23:28










  • Added this information to the question.
    – Pedro
    Nov 11 at 0:36















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)









share|improve this question
























  • How is cophir defined?
    – William Robertson
    Nov 10 at 23:28










  • Added this information to the question.
    – Pedro
    Nov 11 at 0:36













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)









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 0:34

























asked Nov 10 at 21:21









Pedro

455




455












  • How is cophir 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










  • 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












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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 23:44









        Bob Jarvis

        33.4k55783




        33.4k55783






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation