Using packaged functions in Apex

Hi,
I'm fairly new to apex and I am about to write an app which needs to access a SQL server database. My local dba has set up the transparent gateway and I can select from and update the SQLServer database no problem via a db link. What I need to decide is whether to code the sql for reports etc directly into the apex page or to call a pl/sql function returning a select statement. I would like to have all the code in packages as a lot of it will be used by multiple apps in future but is there any extra overhead in doing this:
declare
l_sql varchar2(4000);
begin
select package.function into l_sql from dual;
return l_sql;
end;
rather than coding the SQL directly in the page? Also is there a more efficient way of using packaged functions to select data rather that just have it returning sql statements.
Thanks in advance.
Dave

Hi
I only use function returning select when I have a strong reason to do so, because it is so much more difficult to test and maintain. Not sure about performance, but I think it is not that much worse.
If you simply want to reuse SELECT statements, you could use views instead.
Anyway, if you decide to use the package solution, at least you can make it much simpler -- just code like this in the page:
return package.function;
I hope this helps.
Luis

Similar Messages

  • Using package functions in an update

    Okay, I have a package function that returns a correct value when used in a SELECT, but when used in an UPDATE, it returns Null. Why can't I used its result in the UPDATE?
    Package Spec
    FUNCTION fpub_get_contract_attribute
         (     n_contract_id_in                    IN               CONTRACT.CONTRACT_ID%TYPE,
              s_attribute_in                         IN               VARCHAR2 )
    RETURN VARCHAR2;
    PRAGMA RESTRICT_REFERENCES(fpub_get_contract_attribute,TRUST,WNDS);
    Source :
    clear;
    rollback;
    select
         contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL') "Before",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    update contract
    set original_sales_channel = NVL(contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL'),'Null')
    where contract_id = 52549615;
    select
         NVL(contract_functions.fpub_get_contract_attribute(52549615,'ORIGINAL_SALES_CHANNEL'),'Null') "After",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    rollback;
    Result :
    Rollback complete
    Before                ORIGINAL_SALES_CHANNEL
    RE                                                                              
    1 row updated
    After                 ORIGINAL_SALES_CHANNEL
    Null                  Null
    Rollback completeAny ideas?
    Thanks,
    Jason

    Pragma restrict_references has not been required since 8i, so you can get rid of that. However, certain things will still be enforced, with or without the pragma. For example, you cannot perform DML from within a packaged function when that function is used in a select statement, although you can perform DML within a packaged function when it is used in an update statement. So, if you are performing some sort of DML in your function, it would not raise an error when used in the update statement, but would cause it to return whatever is specified in the exception block when used in a select statement, causing the different results.
    Please see the demonstration below in which I have created a sample function that contains an insert statement. When I use the function from a select statement, it raises an error and does not insert a row. However, when I use the function in an update statement, it does not raise an error and inserts a row. I have then added an exception clause to the function and re-tested. When I used the function in a select statement, it now returns the value in the exception block, but still does not insert a row. When I used the function in an update statement, it returns a different value, not from the exception block, and inserts a row. Then I removed the insert statement from the function and re-tested. Now it returns the same value, whether used in a select statement or an update statement.
    scott@ORA92> SELECT banner FROM v$version
      2  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE     9.2.0.1.0     Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    scott@ORA92> CREATE TABLE test
      2    (col1 VARCHAR2(30))
      3  /
    Table created.
    scott@ORA92> CREATE TABLE contract
      2    (contract_id            NUMBER,
      3       original_sales_channel VARCHAR2(30))
      4  /
    Table created.
    scott@ORA92> INSERT INTO contract (contract_id) VALUES (52549615)
      2  /
    1 row created.
    scott@ORA92> COMMIT
      2  /
    Commit complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2;
      7  END contract_functions;
      8  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- test with insert statement and no exception handling:
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    END fpub_get_contract_attribute;
    12  END contract_functions;
    13  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> SELECT * FROM contract
      2  /
    CONTRACT_ID ORIGINAL_SALES_CHANNEL
       52549615
    scott@ORA92> COLUMN "Before" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> COLUMN "After" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with insert statement and exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    EXCEPTION
    12        WHEN OTHERS THEN RETURN 'RE';
    13    END fpub_get_contract_attribute;
    14  END contract_functions;
    15  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    RE
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    RE                             Null
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with no insert statement and no exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        RETURN 'Null';
    10    END fpub_get_contract_attribute;
    11  END contract_functions;
    12  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    Null                           Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92>

  • Using setTimeout function in APEX

    Hi,
    I am trying to show a print dialog box after which I need to take confirmation from the user whether the printout has come fine or not. For acheving this I am trying to use setTimeout in javascript which is not working. The confirmation box is coming before print dialog box which I do not want to happen.
    Below is the code I am writing in APEX
    <html>
    <head>
    <script language="JavaScript1.1" type="text/javascript">
    function updatePrintFlag()
    var print_flag = confirm("Has the printout come fine?");
    if(print_flag==true)
    alert('Printout has come fine. Updating in the database');
    function callPrint()
    window.print();
    var sleep = setTimeout(updatePrintFlag(),2000);
    alert(print_flag);
    </script>
    </head>
    <body onload='callPrint()'>
    <font size=2>Asking confirm after 2 Secs of print dialog box</font>
    </body>
    </html>
    Please help me in this issue. Thank you.
    Regards
    Dev
    Edited by: [email protected] on 18-Mar-2009 03:17

    Hi -
    Change this line (note quotes):
    var sleep = setTimeout("updatePrintFlag()",2000);Edited by: cmcneil on Mar 26, 2009 1:38 PM

  • DBMS_JOB using Packaged Functions but Package goes invalid

    Is there any way to check a package while running a PL/SQL procedure to see if it's state is valid and then catch the exception?
    In my case usually just calling any function in the package 1x clears it up but the procedure in question runs as a DBMS_JOB it just keeps failing. This procedure could run often enough that Oracle will mark it as broken but I want to give it every shot at execution on time instead of having to make it wait till the next cycle.
    What I would like to do is to catch the exception for the package state being invalid and basically have it go back to the beginning of the procedure and give it another try before failing in case it is just a failure because the package has been altered.
    Is there any way to do this?

    Firstly, I'll copy/paste my standard response regarding package state going invalid as it usually helps to have an understanding of these things...
    Packages tend to fail because of their "package state". A package has a "state" when it contains package level variables/constants etc. and the package is called. Upon first calling the package, the "state" is created in memory to hold the values of those variables etc. If an object that the package depends upon e.g. a table is altered in some way e.g. dropped and recreated, then because of the database dependencies, the package takes on an INVALID status. When you next make a call to the package, Oracle looks at the status and sees that it is invalid, then determines that the package has a "state". Because something has altered that the package depended upon, the state is taken as being out of date and is discarded, thus causing the "Package state has been discarded" error message.
    If a package does not have package level variables etc. i.e. the "state" then, taking the same example above, the package takes on an INVALID status, but when you next make a call to the package, Oracle sees it as Invalid, but knows that there is no "state" attached to it, and so is able to recompile the package automatically and then carry on execution without causing any error messages. The only exception here is if the thing that the package was dependant on has changes in such a way that the package cannot compile, in which case you'll get an Invalid package type of error.
    And if you want to know how to prevent discarded package states....
    Move all constants and variables into a stand-alone package spec and reference those from your initial package. Thus when the status of your original package is invlidated for whatever reason, it has no package state and can be recompiled automatically, however the package containing the vars/const will not become invalidated as it has no dependencies, so the state that is in memory for that package will remain and can continue to be used.
    As for having package level cursors, you'll need to make these local to the procedures/functions using them as you won't be able to reference cursors across packages like that (not sure about using REF CURSORS though.... there's one for me to investigate!)
    This first example shows the package state being invalided by the addition of a new column on the table, and causing it to give a "Package state discarded" error...
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    v_statevar number := 5; -- this means my package has a state
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * v_statevar;
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    BEGIN mypkg.myproc; END;
    ERROR at line 1:
    ORA-04068: existing state of packages has been discarded
    ORA-04061: existing state of package body "SCOTT.MYPKG" has been invalidated
    ORA-06508: PL/SQL: could not find program unit being called: "SCOTT.MYPKG"
    ORA-06512: at line 1
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALIDAnd this next example shows how having the package variables in their own package spec, allows the package to automatically recompile when it is called even though it became invalidated by the action of adding a column to the table.
    SQL> drop table dependonme
      2  /
    Table dropped.
    SQL>
    SQL> drop package mypkg
      2  /
    Package dropped.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package mypkg_state is
      2    v_statevar number := 5; -- package state in seperate package spec
      3  end mypkg_state;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    -- this package has no state area
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * mypkg_state.v_statevar;  -- note: references the mypkg_state package
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.---------------------------------------------------------------------------------------------
    Secondly, from this above standard response, you can see how to check for package state if you want to determine it programatically.
    ;)

  • How can I use 3D function in Photoshop CS6 (student package)?

    Please let me know how can I use 3D function in Photoshop CS6 (student package)?
    Thanks,

    Thanks so much for your helpful reply.
    Now I' ve already installed Adobe Creative Suite 6 Production Premium (Student Package), Extended included. But when I open Photoshop CS6, there' s still no 3D function in menu bar.
    Would you please tell me how to activate this function?
    Thanks,

  • How to use type, packages, functions, and procedures in another schema ?

    I have two target schema in one OWB project, such as A and B. In a mapping of A, I would like to use some types, packages, functions, and procedures from B. I have tried the method of synonym as suggested, but I could not find the metadata of these when importing ... The only type of synonym I can import is the synonym for table. Is there a bug for synonym?
    If I cannot use synonym for this issue, is there another way to solve the problem?

    Now, in some instances you will absolutely need to create the second module as Carsten describes, however it should also be noted that you can reference objects in things like Expressions even if you have not loaded up the metadata. It is only when you need strong binding that it becomes neccessary to import objects. For everything else, as long as the reference will resolve at compile-time then you are good to go.
    For example, I have a function in one target schema (S1) and a private synonym to it in another(s2). A mapping in the S2 schema has an expression object that uses the synonym to the function in the expression property for a couple of the output attirbutes. The synonym has not been loaded into metadata - indeed OWB has no knowledge of its existance. But it resolves at compile time so the mapping validates and generates successfully.
    Mike

  • Using a packaged function in a query

    Hi ,
    I have read the following statement (correct option for the question)in 1z0-147 questions.
    The question is :: WHEN USING A PACKAGED FUNCTION IN A QUERY which of the following is true ::
    The packaged function cannot execute DML statements against the table that is being queriedI tried the following to understand the above statement
    create or replace package test_pk is
    function fn_test(i number) return number ;
    end;
    create or replace package body test_pk is
    function fn_test (i number) return number is
      j number:=1;
    begin
        insert into a values(200,300);
        commit;
       return j;
       end;
    end test_pk;  Upon executing the above function in the select statement
    select TEST_PK.FN_TEST(1) from dualI got the error saying that Can't perform DML Inside SElect
    Is this example for the above statement is TRUE ????
    Could you please explain me if my example is wrong
    Thanks
    Edited by: Smile on Nov 22, 2012 9:47 AM

    No, it is not true. Any function used in SQL is not allowed to perform a DML operation other than SELECT regardless if it is against the table that is being queried or not. Select is allowed against any table. And function in your example does INSERT which is not allowed. Also, Any function used in SQL is not allowed to perform commit/rollback/savepoint.
    SY.
    Edit: unless function is autonomous transaction.
    Edited by: Solomon Yakobson on Nov 22, 2012 10:22 AM

  • Use a package function inside a select of the same package

    Hi.
    How can i use a function defined inside a package, with a select used inside that same package ?
    Example
    ... package example
    CREATE OR REPLACE PACKAGE BODY pkg_example
    AS
         FUNCTION sum_two_values(p_val1 NUMBER,p_val2 NUMBER) RETURN NUMBER
         IS
         BEGIN
         RETURN p_val1 + p_val2;
         END sum_two_values;
         FUNCTION use_another_function_example RETURN VARCHAR2
         IS
         v_value NUMBER;
         BEGIN
         SELECT sum_two_values(2,2) INTO v_value FROM dual;
         RETURN 'waaaazzzzupppppp'
         END use_another_function_example;
    END pkg_example;
    This will not work
    -- SELECT sum_two_values(2,2) INTO v_value FROM dual;
    How can i call a function inside a select statement, a function of the same package where the query is being called.
    (i have Oracle 9.2x)
    Cheers.

    are you sure? you are not using package1, you are using pack1
    SQL> CREATE OR REPLACE PACKAGE package1
      2  IS
      3     FUNCTION f1
      4        RETURN NUMBER;
      5 
      6     FUNCTION f2
      7        RETURN NUMBER;
      8  END;
      9  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY package1
      2  IS
      3     a   NUMBER;
      4 
      5     FUNCTION f1
      6        RETURN NUMBER
      7     IS
      8     BEGIN
      9        RETURN 1;
    10     END;
    11 
    12     FUNCTION f2
    13        RETURN NUMBER
    14     IS
    15     BEGIN
    16        SELECT package1.f1
    17          INTO a
    18          FROM DUAL;
    19 
    20        RETURN a;
    21     END;
    22  END;
    23  /
    Package body created.
    Why not just this
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE OR REPLACE PACKAGE BODY package1
      2  IS
      3     a   NUMBER;
      4     FUNCTION f1
      5        RETURN NUMBER
      6     IS
      7     BEGIN
      8        RETURN 1;
      9     END;
    10     FUNCTION f2
    11        RETURN NUMBER
    12     IS
    13     BEGIN
    14        a:= f1;
    15 RETURN a;
    16     END;
    17* END;
    SQL> /
    Package body created.formatted
    Message was edited by:
    devmiral

  • Calling Package Function dynamically using Forms_DDL

    I am trying to write a validation trigger which will validate entries within a text field. It will call a packaged function based on an entry within the Rule form field. As the data within the text field will vary (sometimes numeric, date, text etc), the validation function will also vary accordingly. Example details are shown below (this example will force the entry of a Y or an N):
    FORM FIELDS
    ARG_DEFAULT1 X (This is the parameter to be submitted to the function)
    RULE1 VAL_CHK_0001 (Function to be called).
    FUNCTION CODE
    FUNCTION VAL_CHK_0001 (P1 VARCHAR2) RETURN NUMBER IS
    SQL_RESULT NUMBER;
    ALERT_ID ALERT;
    ALERT_OK NUMBER;
    BEGIN
    IF UPPER(P1) NOT IN ('Y', 'N') THEN
    :GLOBAL.MSG := 'You must enter either "Y" for Yes or "N" for No - please re-enter';
    SQL_RESULT := '1';
    ALERT_ID := FIND_ALERT('VAL_ERROR_ALT');
    SET_ALERT_PROPERTY(ALERT_ID, TITLE, 'Validation Error');
    SET_ALERT_PROPERTY(ALERT_ID, ALERT_MESSAGE_TEXT, :global.msg);
    ALERT_OK := SHOW_ALERT(ALERT_ID);
    RAISE FORM_TRIGGER_FAILURE;
    RETURN SQL_RESULT;
    ELSE
    SQL_RESULT := '0';
    RETURN SQL_RESULT;
    END IF;
    END VAL_CHK_0001;
    VALIDATION TRIGGER CODE (CURRENT)
    DECLARE
    PKG_RUN VARCHAR2(200);
    BEGIN
    IF :PARAMETER_BK.RULE1 IS NOT NULL THEN
    PKG_RUN := ENV_VALIDATE_PKG.VAL_CHK_0001(:PARAMETER_BK.ARG_DEFAULT1)):
    FORMS_DDL(PKG_RUN);
    END IF;
    END;
    When the Rule1 field data is hard coded in (as shown above), it all runs fine and the Alert box is displayed as expected.
    I need the function name to refer to the rule1 parameter (and not a specific value) as shown below:
    PKG_RUN := 'ENV_VALIDATE_PKG.'||:PARAMETER_BK.RULE1||'('||:PARAMETER_BK.ARG_DEFAULT1||')';
    The form compiles without any errors but when the trigger runs, it completely ignores the Forms_ddl call and does nothing.
    I have hunted through this forum, Metalink, Ask Tom etc and have had no success in finding any solution. I have followed the instructions within NOTE:1017160.6 (How to programmatically call a procedure or function using Oracle Forms) which has got me this far. Nothing that I have read so far has suggested that what I am attempting to do is impossible.
    We are using Oracle Forms 10G with an Oracle 9.0.4 database.
    Any suggestions or advice will be greatly received!
    Thanks

    Like the others have said, Forms_DDL is a one-way street. You can only pass values to it, nothing can be returned. But you could probably get Forms_DDL to work if you wrote your validations as stored procedures that had only IN parameters. Then if the edit ran ok, just terminate normally, but if there is an edit error, to a Raise_application_error.
    Then you could use Forms_DDL to call the procedure, and check for Form_Success after the call. If it failed, you might be able to retrieve the error message from the Raise_application_error by checking SQLERRM. But that is completely untested, so I do not know whether it would work.
    The more sure method would be to call a package procedure on the database that calls Execute_Immediate, and then returns the result back to the calling form.
    Now a little advice: For generic routines such as this, pass dates and numbers as text, and you could cut down on the number of procedures you need to create and use.
    And last note: Do NOT define numeric variables, like SQL_Result, and then set the value using quotes. You are forcing the PL/SQL process to convert text to number. Always set numeric values like this:
    SQL_Result := 1;
    Now the question I am almost afraid to ask: What problem are you solving by creating these generic edit routines? I am wondering if you could just as easily write simple edit processes faster. ...the only way to completely parameterize editing would be to call a process on the database for each column value, passing the column name and value.

  • How to check if column_ name is used by any procedure ,package ,function

    Hello
    Help Is greatly appreciated .
    Kindly please let me know for the folllwoing:
    How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects

    >
    How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects
    >
    In general you can't. Code can always exist outside the database and it is always possible that you have dynamic code and there is no way to find references like that if used by dynamic code. That dynamic code reference could be based on a query stored in a table.
    And there is no way of knowing if external code (e.g. a Java app) references that column.
    Another issue is that a column could exist in multiple schemas and in multiple objects of different types in those schemas. So a global DB search for 'MY_COLUMN' might turn up references in multiple schemas and you may only care about one schema.
    Unfortunately a reference to 'MY_COLUMN' in code could refer to many different objects or to an object in different schemas so how would you resolve those? Especially if you take synonyms into account which can ponit about anywhere.
    Why don't you tell us what it is you are really trying to do?
    Are you trying to find the references to a particular column? Why? Are you planning on removing/renaming the column? If so then the simplest way is to remove/rename the column and see what objects become invalid. Those invalid objects will have become invalid because that column is no longer available.
    As suggested you can use DBA_SOURCE for references in code that use the standard names. But for tables/views you need to use all_tab_columns. And for dynamic code or client code (e.g. a Java application) there is no way.

  • Using pipelined functions with bind variables in Apex...

    Hy all:
    I have a table which has about 10 million records and it is hanging up the system when it is trying to retrieve the data from that table... so what I have done is I created a pripelined
    function and then trying to retrieve data using an SQL statement ... when I try to use a bind variable to filter by the date and location it is binding according to the location
    but not by date ... can anyone help me in this please!!
    Help greatly appreciated !
    Thanks in advance !

    Hi Denes:
    Create or replace type ohe1 as object (
    IMLITM NCHAR(50), IMAITM NCHAR(50), IMDSC1 NCHAR(60), COUNCS NUMBER(22), LIPQOH NUMBER(22),
    LIMCU NCHAR(24), LILOCN NCHAR(40), LILOTN NCHAR(60), LILOTS NCHAR(2), IOMMEJ NUMBER(22))
    CREATE OR REPLACE TYPE OHE AS TABLE OF Ohe1
    CREATE OR REPLACE FUNCTION GET_ohe
    return OHE PIPELINED
    IS
    m_rec ohe1:= ohe1 (NULL,NULL,NULL,0,0,NULL,NULL,NULL,NULL,0);
    begin
    for c in (select f1.LITM LITM, F1.AITM AITM, F1.DSC1 DSC1, F5.UNCS UNCS,
    F21.QOH QOH, F21.MCU MCU, F21.LOCN LOCN, F21.LOTN LOTN, F21.LOTS LOTS,
    F8.MEJ MEJ FROM F1 F1, F2 F2, F21 F21, F5 F5, F8 F8
    WHERE (F5.EDG='07') AND (F21.QOH != 0) AND F2.IBITM = F1.IMITM
    AND F21.ITM = F2.ITM AND F21.ITM = F5.ITM AND F21.MCU = F5.MCU
    AND F21.MCU = F2.MCU AND F21.LOTN = F8.LOTN AND F21.MCU = F8.MCU)
    loop
    m_rec.LITM:=c.LITM;
    m_rec.AITM:=c.AITM;
    m_rec.DSC1:=c.DSC1;
    m_rec.UNCS:=c.UNCS;
    my_record.QOH:=c.QOH;
    my_record.MCU:=c.MCU;
    my_record.LOCN:=c.LOCN;
    my_record.LOTN:=c.LOTN;
    my_record.LOTS:=c.LOTS;
    my_record.MEJ:=c.MEJ;
    PIPE ROW (my_record);
    end loop;
    return;
    end;
    select LITM , AITM , DSC1 , UNCS*.0001 UNCS, QOH*.0001 QOH, (UNCS*.0001)*(QOH*.0001) AMOUNT,
    MCU MCU, LOCN LOCN, LOTN LOTN, LOTS LOTS, jdate(DECODE(MEJ,0,100001,MEJ)) MEJ FROM
    TABLE (GET_ohe)
    WHERE trim(LIMCU)= TRIM(:OHE_BRANCHID)
    AND (jdate(DECODE(MEJ,0,10001,MEJ)) >=:FROMEXPDT
    AND jdate(DECODE(MEJ,0,10001,MEJ)) <=:TOEXPDATE)
    The MEJ is a julian date and I am trying to convert it into a date ..... using the function jdate! and the pipelined function is created without any errors
    and I am able to get the data with correct branch location bind variable but only problem is it is not binding the date filters in the sql.....
    Thanks
    Edited by: user10183758 on Oct 16, 2008 8:17 AM

  • Calling a function in apex region

    Hi
    I want to call a function from a package into Apex report region , but it wont the parse
    i tested in sql dev successfully
    sample code goes like this ..
    SELECT DISTINCT SOR_OFFENDER.FIRST_NAME ||' ' ||
    SOR_OFFENDER.MIDDLE_NAME || ' ' ||
    SOR_OFFENDER.LAST_NAME as "Name",
    SOR_OFFENDER_DETAILS.get_offlu_url(:p216_detail) ---package where function is define
    FROM SOR_OFFENDER,
    SOR_LOCATION
    WHERE SOR_OFFENDER.OFFENDER_ID = SOR_LOCATION.OFFENDER_ID
    AND :p216_detail = SOR_LOCATION.OFFENDER_ID
    any idea /help
    Edited by: Red_Bull on Aug 8, 2012 3:02 PM

    Tony
    I have to use this function to link other page or portal , using different parameter on different reports.
    CREATE OR REPLACE FUNCTION
    get_offlu_url (p_offender_id IN NUMBER) return VARCHAR2
         as
        temp_url_string varchar2(300);
        final_url_string varchar2(300);
        v_doc_num off_profile.doc_num%type;
        v_booking_id off_profile.offender_book_id%type;
        begin
           select http||server||port||dad||start_page into temp_url_string
            from offlu_url;
           select doc_num, offender_book_id into v_doc_num, v_booking_id
             from off_profile
             where offender_id = p_offender_id;
           final_url_string := temp_url_string||'doc_num='||v_doc_num||'&abc='||v_booking_id;
           return final_url_string;
        exception
           when too_many_rows then
               v_doc_num := 0;
               v_booking_id := 0;
        END get_offlu_url;

  • Using AUTHID = CURRENT_USER and Apex

    I'm new to Apex and am just assessing if we can make use of it, mainly for reporting functionality in our existing web based application.
    We have a schema that holds all of our procedures, packages, functions etc and they all have AUTHID = CURRENT_USER so each user can have their own set of tables in their own schema.
    I want to be able to create reports in Apex that will then report on the users table in their own schema but I can't quite work out how Apex actually works. Can I tell something in Apex to use AUTHID = CURRENT_USER?
    We used Webdb many years ago and that created the runtime package for all the forms and reports but I can't see anything that Apex creates so I assume it stores all the code in a table somewhere?
    Thanks
    Robert

    Hi Scott,
    does that mean, there is no way to make these packages work? Not even with additional direct grants to apex_public_user? I am aware of the implications but we have a significant amount of code using packages with authid current user.
    Our situation:
    We have four oracle schemas involved in a multi tenant application.
    GLB : Global objects
    BEE: tenant 1
    SIX: tenant 2
    IAM: tenant 3
    Then we have the user APEX_SCM. There we store the tables and objects for the APEX application. This is the parsing schema for the application.
    During page rendering we try change the CURRENT_SCHEMA to one of the tenants:
    declare
      l_sql varchar2(2000);
    begin
      if :P42_BRAND is null then
        :P42_BRAND := 'SIX';
      end if;
      l_sql := 'alter session set current_schema=' ||:P42_BRAND;
      apex_application.debug(l_sql);
      execute immediate l_sql;
    end;Then we call a stored function returning the report result:
    select *
    from table(six.inv_val_report_pack.fn_rpt_ar_nlf(to_number(:P42_BL_INV_CHECK_ID))) t,
      apex_scm.st_sor_v s, six.ls, ar
    where s.st_sor_id(+) = t.st_sor_id
    and ls.ls_id(+) = t.ls_id
    and ar.ar_id(+) = t.ar_idThe function is in a package with invoker rights:
    create or replace package inv_val_report_pack
    authid current_user
    is
    ...Now my questions:
    1) Is there a way to make this work (using invoker rights packages)?
    2) We cannot get the name resolution to work. Does execute immediate 'alter session set current schema=SIX' work at all? It seems to be ignored.
    I ran a test in the sql workshop as the parsing schema APEX_SCM.
    declare
    l number;
    begin
      execute immediate 'alter session set current_schema=SIX';
      select null into l from ls
      where rownum=1 ;
    end;
    /It only worked after I created a local synoynm for ls in the schema APEX_SCM. Weird, it seems like 'alter session set current schema=SIX' is just plain ignored.
    Any help would be greatly appreciated, by anyone ;).
    Thanks,
    ~Dietmar.

  • FR Studio 11.1.1.3 : You're not authorized to use this function...

    Hi,
    we have FR Studio (client, v. 11.1.1.3.0238 and Report Server v. 11.1.1.3.0.0301) distributed on Citrix terminal server (windows 2003 32-bit) and on latest 2 prod servers we have this error "You're not authorized to use this function. Contact your administrator." appearing.
    On QA server FR Studio works fine, we had an issue there when we forgot to set ports
    8295-8299 to "listening mode" = they were not defined on FR server's FR_servp.properties config files.
    This is also fixed on Prod FR servers and we have double checked firewalls are open.
    After adding them to QA FR servers we had no issues with FR Studio on QA, but on PROD the issue still exists.
    We have also checked that this shouldn' have anything to do with authentication.
    Odd thing is that we get at least partially same sort of error messages on both working and non-working FRClient.log files.
    On FRClient.log there are for example following records:
    08-04 09:26:11 ERROR ConfigResourceBundle     Could not find fr_configcache.properties file
    08-04 09:26:11 ERROR SerializableResourceBundle     Could not get registry instance
    08-04 09:26:11 ERROR SerializableResourceBundle     java.io.FileNotFoundException: C:\Apps\Hyperion\common\config\9.5.0.0\reg.properties (The system cannot find the file specified)
    com.hyperion.hit.registry.exceptions.RegistryException: java.io.FileNotFoundException: C:\Apps\Hyperion\common\config\9.5.0.0\reg.properties (The system cannot find the file specified)
         at com.hyperion.hit.registry.RegistryUtils.createNewConnection(RegistryUtils.java:158)
         at com.hyperion.hit.registry.RegistryConnection.getInstance(RegistryConnection.java:155)
         at com.hyperion.hit.registry.Registry.getInstance(Registry.java:309).....
    Caused by: java.io.FileNotFoundException: C:\Apps\Hyperion\common\config\9.5.0.0\reg.properties (The system cannot find the file specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(FileInputStream.java:106)
         at com.hyperion.hit.registry.RegistryUtils.createNewConnection(RegistryUtils.java:151)
         ... 15 more
    08-04 09:26:11 ERROR HRResourceBundleFactory     Could not locate registry
    08-04 09:26:11 ERROR HRResourceBundleFactory     5500
    com.hyperion.reporting.util.HyperionReportException: Server not yet configured. Please configure the server.
         at com.hyperion.reporting.config.ConfigResourceBundle.<init>(Unknown Source)
         at com.hyperion.reporting.config.ConfigResourceBundle.getInstance(Unknown Source)
         at com.hyperion.reporting.config.HRResourceBundleFactory.getConfigBundle(Unknown Source)...
    That propably gives already an idea what FR Studio is logging.
    Does anyone have idea about this .properties file for frconfig cache?
    Should that be defined somehow during system configuration as we don't find that from any of our environments?
    Just for additional info:
    We have used following packages and installed HFM Admin Client, FR Studio and EPMA File Generator GUI.
    •     02. installer - V17382-01.zip
    •     03. foundation 1 of 4 - V17397-01.zip
    •     03. foundation 2 of 4 - V17369-01.zip
    •     04. architect - V17398-01.zip
    •     08. financial reporting - V17378-01.zip
    •     11. financial management - V17365-01.zip
    Patches:
    + hfm_11113_50-p9976978_111130_WINNT.zip
    + financial reporting_11113_20-p9657652_11113_WINNT.zip
    During the installation we selected:
    Foundation \
    Performance Management Architect\Performance Management Architect File Generator
    Financial Management\
    Financial Management Client
    Financial ManagementADM Driver
    Financial Reporting\
    Financial Reporting Studio Client
    I noticed that apparently no configuration was run neither in QA or in PROD, not sure though if FR Studio even requires that? HFM Admin Client does work on all environments Citrix servers.
    But in Dev and LAB where FR Studio is working fine - FRClient logs absolutely no recods at all and there we did run configuration to tell which SQL db is on background.
    Not sure though whether that config run has any significance for FR Studio.
    Sorry for extremely long story, but just in case if anybody has faced similar issues and whether there could be something with Windows server settings I should go and check?
    Btw... even adding this fr_configcache.properties manually (to try to highlight FR server name and port) it seems FR Client can't find the file.
    Br, MJK

    Denis,
    Thank you for the prompt reply.
    >
    Denis Konovalov wrote:
    > if those reports were saved with security - you're not goingt o be able to open them with Xi3.1 Deski.
    Forgive me for my mundane question but what does saving with security mean?
    Thanks

  • Unable to edit some functions in APEX Sql Workshop

    Hi
    Users are able to edit some procedures/functions in APEX SQL Work shop. ( Object Browser - functions - EDIT)
    When we press edit we get cursor in the code area and can edit some procedures, But for some procedures when we click edit we don't get cursor in the code area and we are not able to edit the functions/procedures.
    I am using fairfox browser.This is happening with only some. Is there any security.grants issue???
    Thanks
    Sree

    Hi
    This is happening with some procedures, For others this works fine.In IE I get red block in code area.
    EDIT is working for some procedures so I think may not be the browser issue.
    Thanks
    Sree

Maybe you are looking for

  • How to set Internet limits to particular user by gpo ?

    How to set Internet limits to particular user by gpo ? Thanks & Regards, Amol . Amol Dhaygude

  • Advice on using BDE 2.1 with SAP 8.81

    Hi I am writing a program for SAP 8.81 using BDE 2.1 which performs operations on the sales order matrix. I have added an addon component of the sales order form and matrix and then added a listener to trap when various columns have left focus etc Al

  • Error when attempting to run auto invoice report

    Hi, We are currently using Oracle E-Business Suite 11.2.  One of our users was attempting to run an Auto Invoice Report this morning and got an error occur.  The log file shows the following: SELECT INTERFACE_LINE_ID FROM   RA_INTERFACE_LINES L2 WHER

  • Hard drive settings for Ultra 2, IBM DNES-309170, 390-0007 drives

    I recently acquired an Ultra 2 workstation without hard drives. I found some working IBM DNES-309170 drives from a Dell Pentium 2 server and see that they are Sun part 390-0007 for use in the Ultra 2. When I try to load Solaris 8, an error appears th

  • Transfer of custom control property one exit to another exit

    Hi expert     I have created one custom control in the exit EXIT_SAPLCOKO_005 for entering long text (TCODE : COR2) and I want to transfer     the same custom control propert to exit EXIT_SAPLCOKO_006 .How can i transfer this.In this case the scope o