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>

Similar Messages

  • 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

  • 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'));
    ;)

  • 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

  • Creating tables inside stored procedures

    is there a limitation as of how many tables i can cerate inside my stored proc using:
    execute immediate('CREATE TABLE xxx AS select * from yyy.... ?
    i have a stored proc that creates couple tables with the method shown above. but the compiler complains for the second create table zzz as select * from .... any idea why?
    I am attaching my procedure just in case:
    CREATE OR REPLACE
    procedure retail_cif_prep as
    begin
    begin
    execute immediate('drop table cif_retail');
    execute immediate('drop table cif_retail_wrong_ccsno');
    exception
    when others then
    null; -- or log errors other than -942 (table doesn't exist)
    end;
    execute immediate('CREATE TABLE cif_retail AS select * from cst where cstfnflag=1 and cstdatoc!=''00000000'' order by cstno');
    execute immediate('CREATE UNIQUE INDEX cif_retail_clustered ON cif_retail(CSTNO)');
    delete from cif_retail where CSTNAM='';
    execute immediate('CREATE TABLE cif_retail_wrong_ccsno AS select * from cif_retail where cstccsno not in (100, 110, 130, 900)');
    delete from cif_retail where CSTNO in (select CSTNO from if_retail_wrong_ccsno);
    end;

    Agree with 3360, this sort of things should be done beforehands.
    Basically what's happening is when you try and compile your procedure the delete statements are referencing your two tables, but I'm guessing these tables are yet to be created on the database and therefore the procedure won't compile without them.
    A dirty workaround is to put your delete statements inside execute immediate commands too.
    Then sit back, make a cup of coffee and have a good think about why on earth you are writing such poor code.

  • Can i create any procedure or function inside a oracle reserve package?

    Hi!
    Can i create any procedure or function inside a oracle reserve package. Suppose, I want to create a function called x in the dbms_output package. Can i do that? Or can i extend the features of this package and create/derived a function from it like we extend any class in JAVA. I'm not sure - whether this is at all possible. I'll be waiting for your reply.
    Thanks in advance.
    Satyaki De.

    No, but you can write a wrapper package and use that instead of using the Built-In package directly. So, instead of calling DBMS_OUTPUT, you call your own Package.
    Steven Feuerstein wrote a wrapper for DBMS_OUTPUT, called P:
    Re: DBMS_OUTPUT.PUT_LINE

  • 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;
    -----------------------------------------

  • Can we create a procedure inside a procedure

    DB version:11g
    hi ,
    Just wanted to ask you guys like can we create a procedure inside a procedure...if not is there any alternative??
    in db2 it is allowed so do oracle support this????
    thanks

    You probably would have been able to tell quicker if you'd just given it a go yourself.
    As Justin showed it's perfectly possible, though I don't personally subscribe to Justin's view that it's rarely appropriate. I go on the principle that if the functionality of a procedure/function is to be used in more than one place then it should be declared independently, but if it's a case of writing a procedure that has to perform a lots of functionality, some of which may be re-used several time within that procedure, then breaking that down into nested procedures for modularity and re-use within it is good practice and makes for more readable and maintainable code.
    So, I would say it's more a case of "it depends" and good design will dictate whether procedures should be nested or seperate.

  • How to find out list of procedures and functions inside a package

    How I can find out the list of Procedures and Functions inside a Package.

    Look at ALL_PROCEDURES and ALL_ARGUMENTS.

  • Member function and member procedure inside an object type in Oracle.

    Hi All,
    Please do have a look at these codes and help me understand. I have no idea about this member function and member procedure. How do they work? Please explain me about this.
    Regards,
    BS2012
    create type foo_type as object (
      foo number,
      member procedure proc(p in number),
      member function  func(p in number) return number
    create type body foo_type as
      member procedure proc(p in number) is begin
        foo := p*2;
      end proc;
      member function func(p in number) return number is begin
        return foo/p;
      end func;
    end;
    /

    Methods are just like functions or procedures in a package, except they're not in a package, their part of an object type.
    The object has attributes (which are the variables declared in it).
    To use such an object you would do things like this...
    SQL> set serverout on
    SQL>
    SQL> declare
      2    v_foo foo_type;
      3    v_val number;
      4  begin
      5    v_foo := foo_type(20); -- instantiate the object and initialize the object attributes
      6    v_foo.proc(20); -- call the object method (proc)
      7    v_val := v_foo.func(4); -- call the object method (func)
      8    dbms_output.put_line(v_val);
      9  end;
    10  /
    10
    PL/SQL procedure successfully completed.The Type definition you've declared creates the object class, but not actually an object itself.
    To actually have an object you need to declare a variable of that object class type, and then instantiate it. When you instantiate the object you need to initialize all the attributes (generally you can pass null if required for each of them to initialize them).
    Once you have your object instantiated, you can call the methods within that object as demonstrated above, a bit like calling functions and procedures in a package, except they are methods within the object type itself, and therefore called directly by referencing them from the variable.
    The documentation goes into a lot more detail of objects if you look it up.

  • Creating a SQL Stored procedure to call a CF function

    I need to create a method to migrate data from a DMZ inside a firewall.  To do this I was thinking of making a call from the DMZ web server (using CF) to an internal SQL server database stored procedure.  The stored procedure would then call a CF template on the internal web server to pull data inside the firewall.  Not my first choice on implementation but as a consultant I don’t make the rules I create the code to enforce them... Anyway these are the steps I need to follow.
    1.)    Call the stored procedure and pass an int value with the call.
    2.)    The Stored procedure calls a URL and passes the INT with it. I.E.  http://Mylocalhost/Xferdata/MyXferTemplate.cfm?MyIntValue=”PASSED IN INT VALUE”
    3.)    The MyXferTemplate does the actual data migration for me.
    My question is how do I create a simple stored procedure to do this on SQL Server 2008???  After looking at the CF documentation I don’t think there will be much of a problem making the call to the stored procedure… its just writing the stored procedure…  Any and all help is greatly appreciated!!!
    Have an Ordinary Day...
    Kurtis   ~|:-)

    So far this is what I got... When I "execute' this code in SQ
    L Server management studio it compiles without any errors but when I run it I get the message "http: is not recognized as an internal or extermnal command."
    /**********************************  Code to create the SP **************************/
    USE 
    [KDLTransfer]
    GO
    /****** Object: StoredProcedure [dbo].[Migrate_DMZ_Data] Script Date: 03/07/2011 16:48:50 ******/
    SET 
    ANSI_NULLS ONGO
    SET 
    QUOTED_IDENTIFIER ONGO
    -- =============================================
    -- Author: KDL
    -- Create date: 3/7/2011
    -- Description: Migrate data
    -- =============================================
    ALTER 
    PROCEDURE [dbo].[Migrate_DMZ_Data]  
    -- Add the parameters for the stored procedure here
    @MyIntValue
    int = null
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    EXEC xp_cmdshell 'http://localhost/IREC/KDL/KDL.cfm?@MyIntValue, no_output';
    END
    /**************** Code to call the SP ******************/
    execute  Migrate_DMZ_Data @MyIntValue = N'5'

  • Create a View, function or stored procedure for query?

    Hi All,
    I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    ;WITH d(d) AS (
    SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
    DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
    FROM sys.all_objects o
    ), cal AS (
    SELECT
    d.d,
    MONTH(d.d) AS m,
    YEAR(d.d) AS y
    FROM d
    SELECT
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
    CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
    vl.MarketRent,
    DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
    cal.y AS [Year],
    COUNT(*) AS DaysVoid,
    COUNT(*) * vl.MarketRent AS VoidLoss
    FROM
    #VoidLoss vl
    JOIN cal
    ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
    GROUP BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    vl.VoidStartDate,
    vl.LetDate,
    vl.MarketRent,
    cal.m,
    cal.y
    ORDER BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidStartDate
    Thanks

    A view or an inline-function is a single query, so this part does not fit in:
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
    The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Oracle Execution Time for function inside view

    Hi Guys,
    i would like to ask if i call a function inside a view , how does it behave in term of execution time and performance
    For Example i have a view as below
    create or replace view CUST.CUST_VIEW
    select a.nice , a.getCustomDisplay(a.name,a.pin,a.dos,b.master_key) as custom from CUST.customer as a , CUST.master as b
    where a.idno = b.main_id_no
    AND the function look like this
    create or replace function getCustomDisplay(a varchar2,b varchar2,c varchar2,d varchar2)
    begin
    select * from CUST.MAPPING_MATRIX order by idno asc;
    for loop
    //logic goes here to determine the result return from matrix
    end
    My Question is for example
    1. If i do select * from CUST.CUST_VIEW ( return 1000 records for example ) , so the function getCustomDisplay will be executed 1000 times also right ( that means select * from CUST.MAPPING_MATRIX order by idno asc; will also be executed 1000 times ) ?
    2. If i do select * from CUST.CUST_VIEW where rownum <= 20 , how many times getCustomDisplay() function will be executed ?
    The reason i ask this because recently we saw a few million execution times per day from AWR report for this query
    "select * from CUST.MAPPING_MATRIX order by idno asc;"
    But when i investigate , and put a logger whenever it call getCustomDisplay , the query above as mention in item no 2 only will be executed as many as the record that will be returned from ( view + where condition ).
    3. will it affect performance if my view return a lot of records ? or is there any way to improve it?
    Thanks

    Hi
    i have other solutions that seems work for reducing number of execution times but do you think its scalable and feasible ?
    CREATE OR REPLACE package body ACER.TYPE_CAT_PASS_UTIL_TEST as
    */* Private package data */*
    TYPE g_rec IS RECORD (
    id_no               VARCHAR2 (4),
    type_pass            VARCHAR2 (3),
    scheme_ind           VARCHAR2 (5),
    cat_pass             VARCHAR2 (2),
    entrepass            VARCHAR2 (2),
    display_type_pass        VARCHAR2 (15),
    display_cat_pass         VARCHAR2 (5),
    display_type_pass_desc    VARCHAR2 (80),
    rule_id                  VARCHAR2 (5)
    TYPE g_tab_type IS TABLE OF g_rec INDEX BY BINARY_INTEGER;
    g_tab   g_tab_type;
    i       BINARY_INTEGER;
    procedure initializeTypePassMatrix(test  IN varchar2) as
    begin
    if(g_tab.COUNT < 1)then
    FOR appln_rec in (
    SELECT tb_type_cat_pass_matrix.id_no,
    tb_type_cat_pass_matrix.type_pass,
    tb_type_cat_pass_matrix.scheme_ind,
    tb_type_cat_pass_matrix.cat_pass,
    tb_type_cat_pass_matrix.entrepass,
    tb_type_cat_pass_matrix.display_type_pass,
    tb_type_cat_pass_matrix.display_cat_pass,
    tb_type_cat_pass_matrix.display_type_pass_desc,
    tb_type_cat_pass_matrix.rule_id
    FROM tb_type_cat_pass_matrix ORDER BY id_no asc)
    LOOP
    dbms_output.put_line('g_tab.COUNT before insert: ' || g_tab.COUNT);
    i := g_tab.COUNT + 1;
    g_tab (i).id_no         := appln_rec.id_no;
    g_tab (i).type_pass         := appln_rec.type_pass;
    g_tab (i).scheme_ind        := appln_rec.scheme_ind;
    g_tab (i).cat_pass          := appln_rec.cat_pass;
    g_tab (i).entrepass        := appln_rec.entrepass;
    g_tab (i).display_type_pass     := appln_rec.display_type_pass;
    g_tab (i).display_cat_pass     := appln_rec.display_cat_pass;
    g_tab (i).display_type_pass_desc:= appln_rec.display_type_pass_desc;
    g_tab (i).rule_id         := appln_rec.rule_id;
    DBMS_OUTPUT.put_line ('g_tab.count after insert: ' || g_tab.COUNT);
    END LOOP;
    else
    DBMS_OUTPUT.put_line ('g_tab>=1, no need to initialize');
    end if;
    exception
    when others then
    dbms_output.put_line('error happen'||DBMS_UTILITY.format_error_backtrace);
    Logger.ERROR('TYPE_CAT_PASS_UTIL.initializeTypePassMatrix',SQLCODE,SQLERRM || ' ' ||DBMS_UTILITY.format_error_backtrace,'SYSTEM');
    end initializeTypePassMatrix;
    procedure populateTypeCatPassFullDesc(typePass  IN varchar2, schemeInd IN varchar2,catPass IN varchar2,entrePass IN varchar2, displayTypePass IN OUT varchar2,displayTypePassDesc IN OUT varchar2, displayCatPass IN OUT varchar2 )is
    v_displayTypePass varchar2(15) :='-';
    v_displayTypePassDesc varchar2(100) :='-';
    v_displayCatPass   varchar2 (2):='-';
    v_type_pass  varchar2(3)  := '';
    v_scheme_ind  varchar2(5) := '';
    v_cat_pass  varchar2(2);
    v_entrepass  varchar2(2);
    v_flag_valid_1 boolean:=false;
    v_flag_valid_2 boolean:=false;
    v_flag_valid_3 boolean:=false;
    v_flag_valid_4 boolean:=false;
    v_appln_rec g_rec;
    begin
    dbms_output.put_line('line 1');
    initializeTypePassMatrix('test');
    FOR nomor in g_tab.FIRST .. g_tab.LAST
    LOOP
    v_appln_rec := g_tab(nomor);
    dbms_output.put_line('line 2.1');
    v_flag_valid_1 :=false;
    v_flag_valid_2 :=false;
    v_flag_valid_3 :=false;
    v_flag_valid_4 :=false;
    v_type_pass     := v_appln_rec.type_pass;
    v_scheme_ind    := v_appln_rec.scheme_ind;
    v_cat_pass     := v_appln_rec.cat_pass;
    v_entrepass    := v_appln_rec.entrepass;
    dbms_output.put_line('line 2.2');
    if(typePass =  v_type_pass or v_type_pass = 'NA') then
    v_flag_valid_1:= true;
    end if;
    if(schemeInd = v_scheme_ind or v_scheme_ind='NA') then
    v_flag_valid_2 := true;
    elsif(schemeInd is null and v_scheme_ind is null) then
    v_flag_valid_2 := true;
    end if;
    if(catPass = v_cat_pass or v_cat_pass='NA') then
    v_flag_valid_3 := true;
    elsif(catPass is null and v_cat_pass is null) then
    v_flag_valid_3 := true;
    end if;
    if(entrePass = v_entrepass or v_entrepass='NA') then
    v_flag_valid_4 := true;
    end if;
    if(v_flag_valid_1 = true and v_flag_valid_2 = true and v_flag_valid_3 = true and v_flag_valid_4 = true) then
    v_displayTypePass     := v_appln_rec.display_type_pass;
    v_displayCatPass     := v_appln_rec.display_cat_pass;
    v_displayTypePassDesc   := v_appln_rec.display_type_pass_desc;
    dbms_output.put_line('rule id got :'||v_appln_rec.rule_id);
    dbms_output.put_line('rule no got :'||v_appln_rec.id_no);
    exit when (0 = 0);
    end if;
    END LOOP;
    displayTypePass := v_displayTypePass;
    displayCatPass  := v_displayCatPass;
    dbms_output.put_line('1type:' || v_displayTypePassDesc);
    displayTypePassDesc :=    v_displayTypePassDesc;
    dbms_output.put_line('2type:' || displayTypePassDesc);
    dbms_output.put_line('type:' || v_displayTypePass);
    dbms_output.put_line('cat :' || v_displayCatPass);
    exception
    when others then
    dbms_output.put_line('error happen'||DBMS_UTILITY.format_error_backtrace);
    Logger.ERROR('TYPE_CAT_PASS_UTIL.populateTypeCatPass',SQLCODE,SQLERRM || ' ' ||DBMS_UTILITY.format_error_backtrace,'SYSTEM');
    end populateTypeCatPassFullDesc;
    function getDisplayTypePass(typePass  IN varchar2, schemeInd IN varchar2,catPass IN varchar2,entrePass IN varchar2) return varchar2 is
    v_displayTypePass varchar2(15) :='-';
    v_displayTypePassDesc varchar2(100) :='-';
    v_displayCatPass varchar2(2) :='-';
    begin
    populateTypeCatPassFullDesc(typePass,schemeInd,catPass,entrePass,v_displayTypePass,v_displayTypePassDesc,v_displayCatPass);
    return  v_displayTypePass;
    exception
    when others then
    dbms_output.put_line('error happen'||DBMS_UTILITY.format_error_backtrace);
    Logger.ERROR('TYPE_CAT_PASS_UTIL.populateTypeCatPass',SQLCODE,SQLERRM || ' ' ||DBMS_UTILITY.format_error_backtrace,'SYSTEM');
    end getDisplayTypePass;
    end TYPE_CAT_PASS_UTIL_TEST;
    By Using like above even i do query on select * from <some_view) it will be only one execution for
    SELECT tb_type_cat_pass_matrix.id_no,*
    **tb_type_cat_pass_matrix.type_pass,**
    **tb_type_cat_pass_matrix.scheme_ind,**
    **tb_type_cat_pass_matrix.cat_pass,**
    **tb_type_cat_pass_matrix.entrepass,**
    **tb_type_cat_pass_matrix.display_type_pass,**
    **tb_type_cat_pass_matrix.display_cat_pass,**
    **tb_type_cat_pass_matrix.display_type_pass_desc,**
    **tb_type_cat_pass_matrix.rule_id**
    **FROM tb_type_cat_pass_matrix ORDER BY id_no asc*
    the key point is the initializeTypePassMatrix function but it seems the variable only works for one session ?
    if i open new session it will be reset again .

  • Running a function inside a package

    This is kind of a noob question: I have a function. I want to use this function inside a package. The function is not created inside the package.

    Here is an example;
      1  create or replace function test_func(v_one number, v_two number)
      2  return number
      3  as
      4  begin
      5  return v_one + v_two;
      6* end;
    SQL> /
    Function created.
    SQL> select test_funct(10,20) from dual
      2  /
    select test_funct(10,20) from dual
    ERROR at line 1:
    ORA-00904: "TEST_FUNCT": invalid identifier
    SQL> select test_func(10,20) from dual
      2  /
    TEST_FUNC(10,20)
                  30
    SQL> create or replace package test_pkg as
      2  procedure test_proc(v_name varchar2, v_one number, v_two number);
      3  end test_pkg;
      4  /
    Package created.
    SQL>
      1  create or replace package body test_pkg as
      2  procedure test_proc(v_name varchar2, v_one number, v_two number) is
      3  begin
      4     dbms_output.put_line(v_name || ' ' || test_func(v_one, v_two));
      5  end;
      6* end test_pkg;
    SQL> /
    Package body created.
    SQL> set serveroutput on
    SQL> exec test_pkg.test_proc('Krystian',10,20)
    Krystian 30
    PL/SQL procedure successfully completed.With kind regards
    Krystian Zieja

  • Function call in procedure within Package Body

    I am a novice in PL/SQL so that I can't find out where the problem is. I am testing a function call in procedure within a Package Body.
    But the PL/SQL Complier doesn't compile the package body but I don't know what I do wrong. Plz let me know how to call a function in procedure within a Package Body?
    Here are the Packaget test programs..
    CREATE OR REPLACE PACKAGE manage_students
    IS
    PROCEDURE find_sname;
    PROCEDURE find_test;
    PROCEDURE find_test_called;
    FUNCTION GET_LASTMT
    RETURN SEQUENCE_TEST.SEQ_NO%TYPE;
    END manage_students;
    CREATE OR REPLACE PACKAGE BODY manage_students AS
    v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
    PROCEDURE find_sname
    IS
    BEGIN
    BEGIN
    SELECT MAX(SEQ_NO)
    INTO v_max_nbr
    from SEQUENCE_TEST;
    DBMS_OUTPUT.PUT_LINE('MAX NUMBER is : '||v_max_nbr);
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    RETURN;
    END;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    END find_sname;
    PROCEDURE find_test
    IS
    BEGIN
    BEGIN
    DBMS_OUTPUT.PUT_LINE('MAX NUMBER Called from another procedure : '||v_max_nbr);
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    RETURN;
    END;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    END find_test;
    FUNCTION GET_LASTMT
    RETURN SEQUENCE_TEST.SEQ_NO%TYPE
    IS
    v_max_nbr SEQUENCE_TEST.SEQ_NO%TYPE;
    BEGIN
    SELECT MAX(SEQ_NO)
    INTO v_max_nbr
    from SEQUENCE_TEST;
    RETURN v_max_nbr;
    EXCEPTION
    WHEN OTHERS
    THEN
    DECLARE
    v_sqlerrm VARCHAR2(250) :=
    SUBSTR(SQLERRM,1,250);
    BEGIN
    RAISE_APPLICATION_ERROR(-20003,
    'Error in instructor_id: '||v_sqlerrm);
    END;
    END GET_LASTMT;
    PROCEDURE find_test_called
    IS
    BEGIN
    BEGIN
    V_max := Manage_students.GET_LASTMT;
    DBMS_OUTPUT.PUT_LINE('MAX_NUMBER :'|| V_max);
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    RETURN NULL;
    END;
    COMMIT;
    EXCEPTION
    WHEN OTHERS
    THEN DBMS_OUTPUT.PUT_LINE('Error in finding student_id: ');
    END find_test_called;
    END manage_students;
    DECLARE
    v_max SEQUENCE_TEST.SEQ_NO%TYPE;
    BEGIN
    manage_students.find_sname;
    DBMS_OUTPUT.PUT_LINE ('Student ID: Execute.');
    manage_students.find_test;
    manage_students.find_test_called;
    END;
    -----------------------------------------------------------------------------------------------

    Hi,
    Welcome to the forum!
    You'll find that there are a lot of people willing to help you.
    Are you willing to help them? Whenever you have a problem, post enough for people to re-create the problem themselves. That includes CREATE TABLE and INSERT statements for all the tables you use.
    Error messages are very helpful. Post the complete error message you're getting, including line number. (It looks like your EXCEPTION sections aren't doing much, except hiding the real errors. That's a bad programming practice, but probably not causing your present problem - just a future one.)
    Never post unformatted code. Indent the code to show the extent of each procedure, and the blocks within each one.
    When posting formatted text on this site, type these 6 characters:
    \(all small letters, inside curly brackets) before and after each section of formatted test, to preserve the spacing.
    For example, the procedure find_test_called would be a lot easier to read like this:PROCEDURE find_test_called
    IS
    BEGIN
         BEGIN
              V_max := Manage_students.GET_LASTMT;
              DBMS_OUTPUT.PUT_LINE ('MAX_NUMBER :' || V_max);
         EXCEPTION
              WHEN OTHERS
              THEN
                   DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
                   RETURN      NULL;
         END;
         COMMIT;
    EXCEPTION
         WHEN OTHERS
         THEN
              DBMS_OUTPUT.PUT_LINE ('Error in finding student_id: ');
    END find_test_called;
    It's much easier to tell from the code above that you're trying to return NULL from a procedure.  Only functions can return anything (counting NULL); procedures can have RETURN statements, but that single word"RETURN;" is the entire statement.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Editing 5.1 audio on a 2.1 system

    This might be a strange question but I really need to ask it to avoid wasting loads of time. I have got a copy of premiere cs4 to try out and I have a Panasonic SD20 camcorder which records audio in 5.1. I have a TV and surround sound set up at home

  • Printout of Change PO Only.

    Dear ALL, There is one requirement of my client. When a po is changed after the initial printout, the change output prints only the changes, and not the full PO. I know this is the standard way SAP works. Is there any way where we can take the print

  • Af:inputFile bug JDev10131 production ignores Per-request disk space limit

    Upload is not working on the new JDev10131 production. I followed the instructions, but it does not work. (http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/devguide/fileUpload.html) I used small (1k,30k) and big

  • How to key in chinese word

    how to key in chinese word in safari

  • Change my macbook pro for new generation? its free?

    somebody told me that if you buy a new macbook pro or any Apple device, if Apple change for a new version and you buy your computer less than 2 months ago the can give you the new version, or somethng like that?  it that real because y just bought my