Calling a Function inside a procedure

Can you call a function inside a procedure?...if so....how?

Not all built-in functions can be used directly in an assignment.
SQL> CREATE PROCEDURE p (p_val IN VARCHAR2) AS
  2  l_v VARCHAR2(10);
  3  BEGIN
  4     l_v := DECODE(p_val,'YES','TRUE','FALSE');
  5  END;
  6  /
Warning: Procedure created with compilation errors.
SQL> show error
Errors for PROCEDURE P:
LINE/COL ERROR
4/4      PL/SQL: Statement ignored
4/11     PLS-00204: function or pseudo-column 'DECODE' may be used inside
         a SQL statement onlyTTFN
John

Similar Messages

  • Call a function inside a package from a stored procedure

    Hello:
    I am kind of new to the stored procedure. Does anyone know how to call a function inside a package from another stored procedure?
    I have a existing function (func_b) inside a package (pack_a) and it returns a cursor. I want to call this function from a stored procedure (proc_c) so that I use the data inside the cursor.
    can I do the following in proc_c:
    my_cursor1 SYS_REFCURSOR;
    begin
    my_cursor1 := exec pack_a.func_b
    end
    It will be very helpful if anyone can point me to any reading or example. Thank you very much for your information.

    guys:
    Thank you for your information so far. I need some more help here. I was able to run the function in my stored procedure. However, I was not able to print the result on the screen to view the cursor result, although I am using dbms_output.put_line statement inside my stored procedure.
    I use the following statement to execute my stored procedure on sql*plus. I can tell the stored procedure is executed successfully, but I did see anything printed:
    DECLARE TEMP VARCHAR2(100);
    BEGIN PROC_LAWS_CAD_NAME_SEARCH('LPD', 'TEST DEVICE ID', 'TEST LAST NAME', 'TEST FIRST NAME', 'F', '11112009', TEMP); END;
    I tried to use 'set serveroutput on' and got the following error:
    ERROR:
    ORA-06502: PL/SQL: numeric or value error: host bind array too small
    ORA-06512: at line 1
    I am kind of confused now. thank you for your help.
    Jack
    Here is my procedure:
    create or replace
    PROCEDURE PROC_SEARCH
    ( AGENCY_ID IN VARCHAR2,
    DEVICE_ID IN VARCHAR2,
    L_NAME IN VARCHAR2,
    F_NAME IN VARCHAR2,
    SEX IN VARCHAR2,
    DOB IN VARCHAR2,
    CAD_NAME_SCH_RESULT_STR OUT VARCHAR2)
    AS
    v_agy_id varchar2(10);
    v_device_id varchar2(20);
    v_l_name varchar2(25);
    v_f_name varchar2(15);
    v_sex varchar2(1);
    v_dob date;
    -- this cursor is going to be used to store a list of warrant matching
    -- name search criteria
    cad_srch_cursor sys_refcursor;
    objSrch SEARCH_RESULT_TEMP%ROWTYPE;
    BEGIN
    cad_srch_cursor := SEARCH_PKG.SEARCH('TESTING', 'TESTER', null, null,null, null, getPhonetic('TESTING'));
    LOOP
    FETCH cad_srch_cursor INTO objSrch;
    EXIT WHEN cad_srch_cursor%NOTFOUND;
    --insert into SEARCH_RESULT_TEMP (name_last) values (objSrch.name_last);
    CAD_NAME_SCH_RESULT_STR := objSrch.name_last;
    dbms_output.put_line('First:'||objSrch.name_first||':Last:'||objSrch.name_last||':Middle:'||objSrch.name_middle);
    end LOOP;
    END PROC_LAWS_SEARCH;
    -----------------------------------------

  • Calling a function inside a symbol?

    Hi there,
    I'm one of those flash-devs that are trying to get Edge Animate to do what I usually do in Flash, so I might be doing this the wrong way, but I've got a symbol with a function "inside" on my stage, and I wanna call that function from the stage.
    I've been trying to use sym.getComposition().getStage().getSymbol("symbolName").functionName(); but it doesn't work.
    I don't have any problems manipulating the symbol itself by calling .play() or .hide() so I know the path works....can anyone show me the right syntax to call a function inside a symbol?
    Thx in advance

    Hi Abnesher,
    An important principle to grasp is that symbols (and the stage is one of them) lies in parallel, despite the fact of instances of different symbols being nested one in another (and all in fine nested in the stage).
    The consequence is that from inside your nested symbol you have no direct visibility of the function defined inside the stage symbol !
    Inside the Stage symbol, in the document.compositionReady event handler :
    sym.yourGlobalFunction = function( firstParameter)
      // your stuff
    Inside another symbol, in one of its events handlers :
    sym.getComposition().getStage().yourGlobalFunction( 5);
    Gil

  • Call library function inside a conditiona​l disable bug

    i'm trying to call a function in a dll using the call library function inside a conditional disable structure.
    one of the parameters is a pointer to a C structure.
    here is the prototype:
    short in myfunction(short in DevNum, void *pMetrics);
    outside of the conditional disable, LabVIEW allows me to wire the pMetrics parameter to a cluster.
    if i put the function inside the conditional disable, LabVIEW doesn't allow me to wire it.
    as a workaround, i put the cluster inside the conditional disable as well.
    any ideas?

    Simply create a constant of the cluster and and put it outside the disable structure. Wire this constant to all inputs (left side terminal) of the Call Library Node. A Call Library Node (CLN) set to Adapt to Type does need a valid datatype to adapt too. This works from the outside side (right side terminal) of the CLN only if the according indicator is inside the same data structure. In older LabVIEW versions you actually had to always define the left side by wiring a constant or a dummy control to it.
    This has to do with the algorithme that evaluates datatypes along wires. Making that algorithme go backwards (against the natural dataflow) inside one subdiagram without causing circular references or similar is already a challange. Doing that across diagram boundaries (case, disable, loop, etc. structures) is basically impossible without causing the entire edit operation to get very slow.
    Message Edited by rolfk on 10-20-2009 08:28 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Executing function inside a procedure

    I have a function like fun_a(a varchar) which returns a number
    I execute the function in sql prompt by select fun_a('hello') from dual;
    Now i have to execute that function inside a procedure and return the output of the function to a variable like the following
    create or replace procedure x is
    a number;
    vsql varchar2(255);
    i varchar2(40):='hello';
    begin
    vsql :='select fun_a('||i||') from dual';
    execute immediate VSQL INTO a;
    dbms_output.put_line(a);
    end;
    I am not getting the output . Please help me in this

    Or even:
    CREATE OR REPLACE PROCEDURE x
    IS
    vsql  VARCHAR2(255);
    i     VARCHAR2(40) := 'EMP';
    i1    VARCHAR2(40) := 'EMPNO';
    a     NUMBER := primary_check_fun(i, i1);
    BEGIN
    dbms_output.put_line(a);
    END;or just for fun,
    CREATE OR REPLACE PROCEDURE x
    IS
    vsql  VARCHAR2(255);
    i     VARCHAR2(40) := 'EMP';
    i1    VARCHAR2(40) := 'EMPNO';
    BEGIN
    dbms_output.put_line(primary_check_fun(i, i1));
    END;
    Well if we're going to extremes Will we could look at it and say that the parameters are pre-defined and just have...
    exec dbms_output.put_line(primary_check_fun('EMP','EMPNO'));
    ;)

  • Creating function inside a procedure.

    Hi all I am on data base 10g,
    is it possible to create a function inside a procedure I don't want to use package.
    thanks in advance.

    Like
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure demo1
      2  as
      3     dd number;
      4     function demo2( a number, b number ) return number
      5     as
      6     begin
      7             return a+b;
      8     end;
      9  begin
    10     dd := demo2(10,30);
    11     dbms_output.put_line(dd);
    12* end;
    SQL> /
    Procedure created.
    SQL> exec demo1;
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on
    SQL> /
    Procedure created.
    SQL> exec demo1;
    40
    PL/SQL procedure successfully completed.
    SQL>

  • Problem calling function inside a procedure

    I have a procedure that simply calls a function, but I'm not sure how to declare it.
    When I run my script oracle returns an error:
    CREATE OR REPLACE PROCEDURE pr_entrada_close(
         var_id_entrada int)
    AS
    BEGIN
         fn_criaJobAnalise(var_id_entrada);
    END;
    ERROR at line 5: PL/SQL: Statement ignored3. AS
    4. BEGIN
    5.      fn_criaJobAnalise(var_id_entrada);
    6. END;

    As far as I know, that structure worked in at least 8.0 and possibly earlier. I actually saw something similar in production code on that version of Oracle. The actual function took several parameters, and using those paramters did a series of statements along the lines of:
    BEGIN
       SELECT 1 INTO l_var
       FROM table1
       WHERE <predicates>
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
          RAISE APPLICATION_ERROR (-20001, 'Error');
       WHEN TOO_MANY_ROWS THEN
          RAISE APPLICATION_ERROR (-20002, 'Error');
    END;
    BEGIN
       SELECT 1 INTO l_var
       FROM table2
       WHERE <predicates>
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
          RAISE APPLICATION_ERROR (-20003, 'Error');
       WHEN TOO_MANY_ROWS THEN
          RAISE APPLICATION_ERROR (-20004, 'Error');
    END;
    -- About 4 or 5 more tables checked
    RETURN 1;and the caller looked kind of like:
    DECLARE
       NO_ROWS_TABLE1 EXCEPTION;
       DUP_ROWS_TABLE1 EXCEPTION;
       NO_ROWS_TABLE2 EXCEPTION;
       DUP_ROWS_TABLE2 EXCEPTION;
       PRAGMA EXCEPTION_INIT (NO_ROWS_TABLE1, -20001);
       PRAGMA EXCEPTION_INIT (DUP_ROWS_TABLE1, -20002);
       PRAGMA EXCEPTION_INIT (NO_ROWS_TABLE2, -20003);
       PRAGMA EXCEPTION_INIT (DUP_ROWS_TABLE2, -20004);
       l_v NUMBER;
    BEGIN
       BEGIN
          l_v := test_tables(<parameters>);
       EXCEPTION
          WHEN NO_ROWS_TABLE1 THEN
             <do something about it>
          WHEN DUP_ROWS_TABLE1 THEN
             <do something about it>
          WHEN NO_ROWS_TABLE2 THEN
             <do something about it>
          WHEN DUP_ROWS_TABLE2 THEN
             <do something about it>
       END;
       <Continue normal processing>
    END;and, yes, <Continue normal processing> occasionally failed for mysterious reasons when more than one of the checks would have failed had the function got to them, and l_v was never ever used.
    This was one of the clevererbits of code in that app.
    John

  • Calling a function inside an iFrame

    I have a app I'm building that plays videos through an iFrame (src is our server). I want to have buttons in my client that when clicked can call functions inside the iFrame (e.g. play, pause). Obviously the problem is with doing this is browser security will not allow it. I understand AIR provides extra parameters for an iFrame to achieve this. I have been reading up on this and seen to get the impression that calling functions in the iFrame can only be done before the page loads?
    Has anyone any basic examples of how I could achieve this?

    Not all built-in functions can be used directly in an assignment.
    SQL> CREATE PROCEDURE p (p_val IN VARCHAR2) AS
      2  l_v VARCHAR2(10);
      3  BEGIN
      4     l_v := DECODE(p_val,'YES','TRUE','FALSE');
      5  END;
      6  /
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE P:
    LINE/COL ERROR
    4/4      PL/SQL: Statement ignored
    4/11     PLS-00204: function or pseudo-column 'DECODE' may be used inside
             a SQL statement onlyTTFN
    John

  • How can I call a function from a procedure

    I have a function named: f_calc_value which return the variable v_result. This function is part of a package.
    How can I call this function from a new procedure I am creating?
    Thanks

    or refer this theread....calling function from procedure

  • How to call a function inside a class? 

    Hello, i am trying to fire a function onPress .. this
    function is inside a class.
    In this function i refer to another function inside the calss
    to call a Tween. It never arrives in the second function.
    I tried to make an example.
    In the fla file i have:
    var test:makeMovie = new makeMovie(this);
    You will see a red squere and you can press on it. It should
    run the tween class. Am i using the delegate class wrong?

    I always have to use test movie and trace a couple of times
    each time I start to use Delegate.
    It wraps function.apply I think, which I tend to use more
    often.
    try using:
    Container.onPress = Delegate.create(this,setAlpha);
    and then just
    setTween()
    inside your setAlpha....
    That's conceptually how I think I would try it above if I was
    doing something similar.
    I'm not sure it would have the desired effect even if the
    delegate was executed as you have it coded. Unless you want
    setTween's execution scope to be the Container clip in which case
    you might need to do what kglad said and change the Container
    reference to 'this'.
    The way you have it at the moment inside setAlpha the
    Delegate.create is simply creating a function...and not excuting
    it.
    its like : function something(){trace('what')}
    and not like : something();
    Below is some quick code that helps show how things work.
    Notice that I assigned the delegate function to mainFunc....so that
    along with the last example might provide a clue. Just paste it on
    a frame and take a look at what's happening.

  • Calling User Functions in ODI Procedure

    Hi All,
    Can anyone pass me the syntax in which i can call a ODI User Function in ODI Procedure?
    Thanks,
    Ritika

    Hi,
    just use
    function("parameter_char", parameter_number)
    Does it help you?
    Cezar Santos
    (www.odiexperts.com)

  • Dynamically call different functions inside a function

    Hi there,
    I was wondering if it is possible to dynamically define the function that you want to call. Almost like passing the function name that i want to call as a parameter.
    I am calling a function, but do not want to hardcode the function I am calling. I have different functions that all return a boolean value, and i want to call all of them at different times through the same procedure/function.
    Is this possible???
    Thank you in advance!
    Tanja

    Or combine your functions to use function overloading, then you can use the same name...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package mypk as
      2    FUNCTION gen_function (param1 IN NUMBER, param2 IN NUMBER) RETURN BOOLEAN;
      3    FUNCTION gen_function (param1 IN VARCHAR2, param2 IN VARCHAR2) RETURN BOOLEAN;
      4    FUNCTION gen_function (param1 IN BOOLEAN, param2 IN BOOLEAN) RETURN BOOLEAN;
      5    PROCEDURE test;
      6* end;
    SQL> /
    Package created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package body mypk as
      2    FUNCTION gen_function (param1 IN NUMBER, param2 IN NUMBER) RETURN BOOLEAN IS
      3    BEGIN
      4      RETURN (param1*2) = param2;
      5    END;
      6    FUNCTION gen_function (param1 IN VARCHAR2, param2 IN VARCHAR2) RETURN BOOLEAN IS
      7    BEGIN
      8      RETURN param1 = param2;
      9    END;
    10    FUNCTION gen_function (param1 IN BOOLEAN, param2 IN BOOLEAN) RETURN BOOLEAN IS
    11    BEGIN
    12      RETURN NOT(param1) = param2;
    13    END;
    14    PROCEDURE test IS
    15    BEGIN
    16      IF gen_function(1,2) THEN
    17        DBMS_OUTPUT.PUT_LINE('Test1: True');
    18      ELSE
    19        DBMS_OUTPUT.PUT_LINE('Test1: False');
    20      END IF;
    21      IF gen_function('Fred','John') THEN
    22        DBMS_OUTPUT.PUT_LINE('Test2: True');
    23      ELSE
    24        DBMS_OUTPUT.PUT_LINE('Test2: False');
    25      END IF;
    26      IF gen_function(TRUE,FALSE) THEN
    27        DBMS_OUTPUT.PUT_LINE('Test3: True');
    28      ELSE
    29        DBMS_OUTPUT.PUT_LINE('Test31: False');
    30      END IF;
    31    END;
    32* end;
    SQL> /
    Package body created.
    SQL> exec mypk.test;
    Test1: True
    Test2: False
    Test3: True
    PL/SQL procedure successfully completed.
    SQL>;)

  • Call Oracle function from Stored Procedure

    Hi,
    I have function Which returning one number. I want to use that number in a procedure. How to call the Oracle Function from the Procedure
    Create procedure
    AS
    Begin
    Check number;
    Select Function1 into check from dual;
    It is giving error.
    Can anyone provide me example for this.
    Thanks in advance

    Put the Check Number; before begin
    SQL> create or replace procedure abc as
      2 begin
    3 val number;
      4  select abcd into val from dual;
      5  dbms_output.put_line(val);
      6  end;
      7  /
    Warning: Procedure created with compilation errors.
    Elapsed: 00:00:00.00
    SQL> show error
    Errors for PROCEDURE ABC:
    LINE/COL ERROR
    3/5      PLS-00103: Encountered the symbol "NUMBER" when expecting one of
             the following:
             := . ( @ % ;
             The symbol ":=" was substituted for "NUMBER" to continue.
    SQL> create or replace procedure abc as
      2 val number;
    3 begin
      4  select abcd into val from dual;
      5  dbms_output.put_line(val);
      6  end;
      7  /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec abc;
    100.22
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL>

  • Calling a function inside another class

    I have the following two classes and can't seem to figure to figure out how to call a function in the top one from the bottom one. The top one get instantiated on the root timeline. The bottom one gets instantiated from the top one. How do I call functions between the classes. Also, what if I had another call instantiated in top one and wanted to call a function in the bottom class from the second class?
    Thanks a lot for any help!!!
    package
         import flash.display.MovieClip;
         public class ThumbGridMain extends MovieClip
              private var grid:CreateGrid;
              public function ThumbGridMain():void
                   grid = new CreateGrid();
              public function testFunc():void
                   trace("testFunc was called");
    package
         import flash.display.MovieClip;
         public class CreateGrid extends MovieClip
              public function CreateGrid():void
                   parent.testFunc();

    kglad,
    Although I agree that utilizing events the way you attempted in your suggestion is better for at least a reason of eliminating dependency on parent, still you code doesn't not accomplish what Brian needs.
    Merely adding event listener to grid instance does nothing - there is no mechanism in the code that invokes callTGMFunction - thus event will not be dispatched. So, either callTGMFunction should be called on the instance (why use events - not direct call - in this case?), or grid instance needs to dispatch this event based on some internal logic ofCreateGrid AFTER it is instantiated - perhaps when it is either added to stage or added to display list via Event.ADDED. Without such a mechanism, how is it a superior correct way OOP?
    Also, in your code in ThumbGridMain class testFunc is missing parameter that it expects - Event.
    Am I missing something?
    I guess the code may be (it still looks more cumbersome and less elegant than direct function call):
    package
         import flash.display.MovieClip;
         import flash.events.Event;
         public class ThumbGridMain extends MovieClip
             private var grid:CreateGrid;
             public function ThumbGridMain():void
                 grid = new CreateGrid();
                 grid.addEventListener("callTGMFunction", testFunc);
                 addChild(grid);
            // to call a CreateGrid function named cgFunction()
             public function callCG(){
                 grid.cgFunction();
             public function testFunc(e:Event):void
                 trace("testFunc was called");
    package
         import flash.display.MovieClip;
         import flash.events.Event;
         import flash.events.Event;
         public class CreateGrid extends MovieClip
             public function CreateGrid():void
                 if (stage) init();
                 else addEventListener(Event.ADDED, callTGMFunction);
             // to call a TGM function
             public function callTGMFunction(e:Event = null):void
               // I forgot this one
                removeEventListener(Event.ADDED, callTGMFunction);
                this.dispatchEvent(new Event("callTGMFunction"));
            public function cgFunction(){
                 trace("cg function called");
    I think this is a case of personal preference.
    With that said, it is definitely better if instance doesn't rely on the object it is instnatiated by - so, in this case, either parent should listen to event or call a function directly.

  • Can't call a function inside another function

    Hello,
    i have the following function :
    FUNCTION test_day_week (P_DATE DATE)
    RETURN VARCHAR2 IS
    BEGIN
    RETURN TO_CHAR(P_DATE ,'DAY');
    END;
    --it returns the day name of a given date
    FUNCTION TEST_DAY_NUMBER (P_DAY_NAME VARCHAR2)
    RETURN NUMBER IS
         V_RESULT NUMBER;
         V_RETURN_DAY VARCHAR2(30);
         P_DATE DATE;
    BEGIN
    V_RETURN_DAY := test_day_week (P_DATE );
    MESSAGE('V_RETURN_DAY'|| V_RETURN_DAY);
    MESSAGE('V_RETURN_DAY'|| V_RETURN_DAY);
    IF V_RETURN_DAY = 'MONDAY' THEN V_RESULT :=1;
         END IF ;
    IF V_RETURN_DAY = 'TUSEDAY' THEN V_RESULT :=2;
         END IF ;
    IF V_RETURN_DAY = 'WENDSDAY' THEN V_RESULT :=3;
         END IF ;
    IF V_RETURN_DAY = 'THURSDAY' THEN V_RESULT :=4;
         END IF ;
    IF V_RETURN_DAY = 'FRIDAY' THEN V_RESULT :=5;
         END IF ;                
    IF V_RETURN_DAY = 'SATURDAY' THEN V_RESULT :=6;
    END IF ;
    IF V_RETURN_DAY = 'SUNDAY' THEN V_RESULT :=7;
         END IF ;
    RETURN V_RESULT;
    END;
    --The above function returnds the day name in numbers
    The proble is that when i call test_day_week function it returns no value even it is tested separatly and works fine don't know where is my problem :
    1-number of argrments in function[b] TEST_DAY_NUMBER
    ?? and so ..!
    Regards,
    Abdetu..

    You could also cut the whole thing down to a simple function... (assuming you have a need to customise your start of week rather than use built in date functionality)
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE OR REPLACE FUNCTION test_day_week (P_DATE DATE) RETURN NUMBER IS
      2  BEGIN
      3    RETURN (INSTR('MONTUEWEDTHUFRISATSUN',TO_CHAR(P_DATE,'DY'))+2)/3;
      4* END;
    SQL> /
    Function created.
    SQL> select test_day_week(sysdate) from dual;
    TEST_DAY_WEEK(SYSDATE)
                         1
    SQL> select test_day_week(sysdate+1) from dual;
    TEST_DAY_WEEK(SYSDATE+1)
                           2
    SQL> select test_day_week(sysdate+2) from dual;
    TEST_DAY_WEEK(SYSDATE+2)
                           3
    SQL> select test_day_week(sysdate+3) from dual;
    TEST_DAY_WEEK(SYSDATE+3)
                           4
    SQL> select test_day_week(sysdate+4) from dual;
    TEST_DAY_WEEK(SYSDATE+4)
                           5
    SQL> select test_day_week(sysdate+5) from dual;
    TEST_DAY_WEEK(SYSDATE+5)
                           6
    SQL> select test_day_week(sysdate+6) from dual;
    TEST_DAY_WEEK(SYSDATE+6)
                           7
    SQL> select test_day_week(sysdate+7) from dual;
    TEST_DAY_WEEK(SYSDATE+7)
                           1
    SQL>

Maybe you are looking for