Dynamic function call in Forms PL/SQL [SOLVED]

I have a 10G form, which has a dropdown list of values. Depending on the value selected, I look up a setup table which will tell me the name of the database package/function to call.
I then want to call that function with a bind IN parameter and then retrieve the function return value (which is a varchar2 containing message(s) as a stream of text) to display to the user.
I have searched high and low and cannot find a good example.
(a) forms_ddl doesn't seem to have the ability
(b) dbms_sql - some forums/blogs warn away from this due to db version dependencies
(c) exec_sql seems to be very basic and more aimed at odbc calls, rather than calls to native oracle db functions.
Here is example pseudo-code of what I am attempting to do on a WHEN-BUTTON-PRESSED trigger
DECLARE
v_Param1 VARCHAR2 := 'myInputValue';
v_FunctionName VARCHAR2 := 'MYDBPKG.MYFUNCTION';
v_DynamicSQL VARCHAR2;
v_Result VARCHAR2;
BEGIN
v_DynamicSQL := 'BEGIN :v_result:='||v_FunctionName||'('||chr(39)||v_Param1||chr(39)||')'; END';
Bind v_result variable;
execute dynamic sql;
message('the resulting text was <'||v_result||'>');
END;
Obviously, my code above has the function name hard-coded, but my real-life code would retrieve this function name from a database table, so I cannot call the function directly in the Forms PL/Sql.
where the db package/function looks like this:
create or replace package MYDBPKG as
function myfunction(I_Param VARCHAR2) return VARCHAR2;
end mydbpkg;
Anybody got a good example ?
Thanks
Alan
Edited by: Alan Lawlor on 11-May-2011 09:34

Alan Lawlor wrote:
(a) forms_ddl doesn't seem to have the ability
(b) dbms_sql - some forums/blogs warn away from this due to db version dependencies
(c) exec_sql seems to be very basic and more aimed at odbc calls, rather than calls to native oracle db functions.you forgot
(d): don't use dynamic SQL
As far as I am concerned (from the code I am exposed to) 99,9% of dynamic SQL code is at best used when there is no need for it and at worst it is impemented the most horrific way you can imagine. OK, this is not the entire truth: in 0,4% it is used when there is no need for it, and in the other 0,5% it is used wrong. And in the other 99% it is a combination of both: it is used when there is no need for it plus it is used wrong. So the very best thing you can do is to avoid dynamic SQL.
but my real-life code would retrieve this function name from a database tablePlease don't do that. This is one of the worst things to do. Forget about the fact that it is a big security hole and most certainly will trash the shared pool of the database and bringing your server down. Most important to developers is that it is a hell of a nightmare to maintain and a lot worse to debug.
So seriously think about if you want to go down the Dynamic SQL route.
cheers

Similar Messages

  • Function called by what PL SQL procedure

    Hello.
    I want to see all the callers of a PL SQL function. I know it is called by some PL SQL procedures in a package. How do I see who calls the function?
    Thanks.

    i think you can try this : select * from
    user_dependencies where type = 'FUNCTION' actually, that what should what things are referenced by your function
    and you'd be better off with ALL_DEPENDENCIES, since references can cross schemas.
    select name, type from all_dependencies
    where referenced_owner= 'ME'
    and referenced_name= 'MY_FUNCTION'
    and referenced_type ='FUNCTION'
    this will show what other things are using your function. if it's used by a package, it will not show the exact procedure or function within that package.

  • How to make a dynamic function call from within a package procedure

    Hi:
    I need to call a function dynamically (name and parameters determined at run time, but return value is known:always an integer). I can build the call and place it in a dynamic sql using dbms_sql. But the function is inside a package and is not public.
    So, if I issue:
    dbms_sql.parse( cur,'SELECT '||call||' FROM dual', dbms_sql.v7 )
    where call is "DOS(234,'V')"
    I get:
    ORA-00904: "DOS": invalid identifier
    If I make the function ("DOS") public and "call" equals "pack.DOS(234,'V')", it works fine, but I don't want to make it public.
    Is there a solution?
    Thanks in advance
    RuBeck

    Hi, Kamal:
    Calling from outside of the owner package is not possible if it is not public.The calls are from inside the package. It looks like the dynamic select is executed "outside" the package, so the private function is unknown
    Make it available in the package headerLooks like it's the only solution
    How often this will be executed?This is a library for loading files into tables and executing dynamic validation procedures.
    Here's an example of the mechanics:
    create or replace package mypack as
         function one return number ; -- public function
         procedure execute_it( p_name VARCHAR2 ) ;
    end ;
    create or replace package body mypack as
    function one return number is
    begin
    return 1 ;
    end ;
    function two( i number, s varchar2 ) return number is -- private function
    begin
    return 2 ;
    end ;
    procedure execute_it( p_name VARCHAR2 ) is
    select_str VARCHAR2( 1000 ) ;
    v_num NUMBER ;
    cur NUMBER ;
    nf NUMBER ;
    begin
    select_str := 'SELECT '||p_name||' FROM dual' ;
    cur := dbms_sql.open_cursor ;
    dbms_sql.parse( cur,select_str,dbms_sql.v7 ) ;
    dbms_sql.define_column( cur,1, v_num ) ;
    nf := dbms_sql.execute( cur ) ;
    IF dbms_sql.fetch_rows( cur ) = 0 THEN
    RAISE no_data_found ;
    END IF ;
    dbms_sql.column_value( cur, 1, v_numero ) ;
    dbms_output.put_line( p_name||' returns '||v_num ) ;
    dbms_sql.close_cursor( cur ) ;
    end ;
    end ;
    begin
    mypack.execute_it( 'mypack.one' ) ; -- Call public function: Works fine
    mypack.execute_it( 'two(234,''v'')' ) ; -- Call private function: error 0904
    end ;
    Thanks for your hints
    RuBeck
    PS: The indentation is lost when I post the message! I wrote it indented!

  • Dynamic function Call

    Hi,
    I want to search which program is using the FM : FKK_AR_EVENT_0934.
    I tried using Where used List but it says "Possible Dynamic Calls'. How to search for that?
    Thanks,
    Sachin.

    Hi...,
    So as of now there is no program in your system which is using this function module.
    You can test the same by calling the same Fm from your own program,
    activate the program(with activate anyway), Now press where used list for this function module.
    Here you can get your program name.
    Thanks,
    Naveen.I

  • Dynamic Function Calling

    I am attempting to dynamically populate a function at runtime and then have the ability to call this function. Anybody know how this could be done?

    What you need is eval(). Unfortunately eval() is not available in AS3, although it is defined in ECMA script standard. (It was in AS1/2.)
    Fortunately, there are some very clever people who produced their own implementations I will use D.eval by RIA 1 here. http://www.riaone.com/products/deval/
    Let's say you have this XML:
    <function name="exampleFunction" arg0="num:int" arg1="str:String" returns="String">return num + str</function>
    First you have to convert it to a string in AS3 Function format:
    function exampleFunction(num:int, str:String):String{return num + str};
    Then evaluate it as Function, and execute it.
    import r1.deval.D;
    var xml:XML = <function name="exampleFunction" arg0="num:int" arg1="str:String" returns="String">return num + str</function>;
    var functionString:String = "function " + xml.@name + "(" + xml.@arg0 + ", " + xml.@arg1 + "):" + xml.@returns + "{" + xml + "};";
    var dynamicFunction:Object = D.parseFunctions(functionString);
    trace(D.eval("exampleFunction(3, ' spacemen');", null, dynamicFunction));
    Traces
    3 spacemen

  • Execute Oracle Package Function call from FORTE

    Has anyone EVER successfully execute an Oracle Package Function call from FORTE
    via " sql execute procedure "?
    Here's my question, I am able to execute a stored procedure but hasn't figured
    out a way to execute a function which defined in a package. The syntax goes
    like this: sql execute procedure <PackageName>.<FunctionName> ( input
    input_parm, output output_parm). If anyone EVER successfully execute a
    function, please let me know, thanks.

    You'll need to provide a column alias for the function call:
    select func(val) as alias from dual

  • More function calls in stored procedure

    Hi,
    I would like to know if there are more function calls in a PL/SQL stored procedure, would it affect the performance of this procedure?
    Or will it be more efficient to have the body of those functions inside the procedure itself.
    Of course a method call is always costlier than the monolithic procedure but my question is how much would be difference in performance.
    Rgds
    Varad

    Yes, avoid using UDF  , means especially a scalar udf... See how you can re-write a scalar udf  as table valued udf.
    http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/23/reuse-your-code-with-cross-apply.aspx
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Function Call returning old SQL Query

    Hello All,
    I have a Pipeline Function which creates a SQL within (Dynamic SQL that gets stored in a LONG variable) based on the parameter STRING passed to the function. Inside this function, once the SQL is built, I am inserting this SQL into a log table, for logging purpose.
    Note: my function has only one parameter which is a string. This string accepts a name:value pairs with a delimiter which I breakdown inside the function. But this functionality is working fine.
    Issue:
    When I run the function with parameter with a STRING say (Age = 20, Gender = M) for the first time, it works.
    <code>SELECT * FROM TABLE (
    PIPE_FUN_SEARCH_PKG.get_search_records ('EMP_AGE:20|EMP_GENDER:M'));
    </code>
    When I change the parameters to (Age = 20, Gender = F), it gives me the results of the earlier function call.
    <code>SELECT * FROM TABLE (
    PIPE_FUN_SEARCH_PKG.get_search_records ('EMP_AGE:20|EMP_GENDER:F'));
    </code>
    When I open the logs, I see the SQL being built is the earlier one.
    As a test I closed the session and ran (Age = 20, Gender = F) first. It works fine. When I run a different parameter string, it always mimics the earlier function call.
    Is CACHING in play here. I tried both the following:
    <code> dbms_result_cache.bypass(FALSE);
    dbms_result_cache.flush;
    </code>
    I tried multiple tests, with different parameters and only the first one runs fine and second one copied the earlier. However, when I open two sessions on two different windows it doesn't happen.
    Also, in the Logging table I am capturing the input string as a confirmation, which is coming correctly. But the SQL being build mimics the earlier call.
    I tried to set the variable which hold the SQL Statement to empty (v_sql := '';) at the beginning and also at the end. Still no use.
    Kindly help if I am over looking anything.
    Regards,
    Aj

    Aj09 wrote:
    I have a Pipeline Function which creates a SQL within (Dynamic SQL that gets stored in a LONG variable) based on the parameter STRING passed to the function. The LONG data type has been replaced by the LOB data type. Oracle specifically recommends not using the old LONG data type.
    Issue:
    When I run the function with parameter with a STRING say (Age = 20, Gender = M) for the first time, it works.
    <code>SELECT * FROM TABLE (
    PIPE_FUN_SEARCH_PKG.get_search_records ('EMP_AGE:20|EMP_GENDER:M'));
    </code>
    When I change the parameters to (Age = 20, Gender = F), it gives me the results of the earlier function call.
    <code>SELECT * FROM TABLE (
    PIPE_FUN_SEARCH_PKG.get_search_records ('EMP_AGE:20|EMP_GENDER:F'));
    </code>The tag is ** - not *<code>*.
    Why a pipeline function? Why dynamic SQL? Are you using +DBMS_SQL+ to create the dynamic cursor? If not, why not? Only +DBMS_SQL+ allows dynamic binding in PL/SQL. Without that, your code will burn a lot of additional CPU on hard parsing and trash and fragment Shared Pool memory.
    When I open the logs, I see the SQL being built is the earlier one.
    How do you record the current SQL? Are you using a static variable to capture the SQL statement generated?
    From what you have described - this is yet another horribly flawed approach in all respects. To data modelling. To relational databases. To Oracle. To SQL.
    Reinventing the SQL language for data retrieval as a pipeline function using a funky parameter interface - sorry, I just don't get that. It is an insane approach.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • PL/SQL Javascript Function Call

    Can anyone offer some help on this? I am attempting to get a javascript tool tip to work on an application I am developing. I have developed a line calendar using PL/SQL outputting HTML. When I embed a javascript function into my PL/SQL htp.p function, the javascript appears to go a little crazy. Here is an example of my code:
    "htp.p('<td onMouseover="ddrivetip("Yahoos Site", "yellow", 250)"
    onMouseout="hideddrivetip()">Yahoo</td>')
    I have tried a few iterations, using different javascript, and I always get the same result. The double quotes used in the onMouseover and onMouseout function calls are a result of PL/SQL not liking single quotes. The entire code for the tooltip can be found on dynamic drives page:
    http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm
    The CSS and javascript code is placed as appropriate in the HTML page header. Am I missing something on the htp.p command?
    Message was edited by:
    jason97m
    Message was edited by:
    jason97m

    This post covers it well.
    http://inside-apex.blogspot.com/2007/08/using-tooltips-in-oracle-apex.html
    Good luck.
    Brian

  • How to call a form with parameters in PL/SQL

    hi
    I added a button in my form,now I want to call another form in the button's PL/SQL prucedure. how to do it?
    thinks
    Frank

    Hi,
    You can use wwa_app_module.set_target api.
    declare
    l_url varchar2(2000);
    begin
    l_url := 'report1.show&p_arg_names=deptno&p_arg_values=10';
    <product_schema>.wwa_app_module.set_target(l_url, 'CALL');
    end;
    Thanks,
    Sharmila

  • Calling a form in a dynamic page

    Hi all,
    We are using dynamic pages for the creation of custom portlets. We can call a report in html tag by calling report.show procedure. What will I write for calling a form?
    Thanx,
    Gulsah

    Gulsah,
    In the component management screen you can find a URL-style "Run Link" which looks like this:
    PORTAL30.wwa_app_module.new_instance?p_moduleid=1060253649
    Also can put this PLSQL code:
    PORTAL30.wwa_app_module.link (
    p_arg_names => '_moduleid', p_arg_values => '[module id]',
    p_arg_names => '_show_header',p_arg_values => 'YES');
    where [module id] is your form id
    for more information please see the Portal FAQ:
    http://otn.oracle.com/products/iportal/htdocs/portal_faq.htm#BuildingApplications
    Thanks,
    Dmitry

  • How to call userdefined java script function in Oracle Forms 11g.

    Hi,
    I Created a java script contain a function, that will open and close the browser for some URL.
    CODE:-(webclose.jp)
    *function manageWindows() {*
    var windows = [], i = 0;
    var url =  "htttp://oracle:64578/xmlpserver/login.jsp?Go&id=admin&passwd=admini";
    *if (url.length) {*
    *windows[i] = window.open(url, ' tabWindow_'+i);*
    i++;
    *winows[i-1].close();*
    *delete windows[i-1];*
    return false;
    *}* Then i placed the javascript file in path <middleware_home>\user_projects\domains\<domain>\servers\WLS_FORMS\_WL_user\formsapp_11.1.1\e18uoi\war\
    After that i called the javascript function in to forms as
    WEB.JAVASCRIPT_EVAL_EXPR('webclose.manageWindows();');
    When running the form it showing error
    FRM-92190: JavaScript is unable to evaluate expression.
    If anybody knows pls help me.

    Always post code snippets in &#123;code&#125; tags as explained in the FAQ.
    I Created a java script contain a function, that will open and close the browser for some URL.
    CODE:-(webclose.jp)
    function manageWindows() {
    var windows = [], i = 0;
    var url = "htttp://oracle:64578/xmlpserver/login.jsp?Go&id=admin&passwd=admini";
    if (url.length) {
    windows = window.open(url, ' tabWindow_'+i);
    i++;
    winows[i-1].close();
    delete windows[i-1];
    return false;
    } Then i placed the javascript file in path <middleware_home>\user_projects\domains\<domain>\servers\WLS_FORMS\_WL_user\formsapp_11.1.1\e18uoi\war\
    After that i called the javascript function in to forms as
    WEB.JAVASCRIPT_EVAL_EXPR('webclose.manageWindows();');
    When running the form it showing error
    FRM-92190: JavaScript is unable to evaluate expression.
    If anybody knows pls help me.>
    This error has nothing to do with Forms, it is an JavaScript error.
    Most likely cause is this line
    if (url.length) {url.length returns a Whole number and so the conditions would be
    if (url.length > 0) {Or
    if (url) {  // not null checkCheers,

  • How to call java function in Oracle forms?

    Hi I am having Oracle 9i with 10g Developer Suite.
    I am new to Oracle forms..
    I had one function in java getDatas()..
    How can I call this function in Oracle Forms..
    Pls help
    Thanks

    Thanks Francois,
    I want to display values from my java code in the Forms..
    For that purpose only i am installing 10g Developer Suite..
    The below is java code..
    public class DBTest {
              public static String callDB(int id,String name){
              String ss="Hai";
              Connection con=null;
              try{
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   con = DriverManager.getConnection("url","id","pwd");
                   Statement st=con.createStatement();
                   System.out.println("Connected...");
              int r=st.executeUpdate("Insert into FORM_TEST VALUES('"+id+"','"+name+"')");
                   if(r==1){
                        ss="Inserted Sucessfully";
                   else{
                        ss="Insertion Failed";
              }catch(final Exception e){
              System.out.println(e);
              return ss;
         public static void main(String[] args) {
              int empid=102;
              String empname="Gilbert";
              String resultStr=callDB(empid,empname);
              System.out.println(resultStr);
    I want to dispaly Inserted or Insertion Failed in Oracle Forms..
    As per Gerd Volberg suggestion, i had placed DBTest.jar in
    E:\DevSuite\forms\java\DBTest.jar
    and in formsweb.cfg the below jar is added..
    archive_jini=frmall_jinit.jar,DBTest.jar
    But in Fomrs Builder-->Program-->Import Java Classes-->Oracle
    org,ice,com and subnodes are available.
    But my jar is not available..
    Is my way is coorect?
    Pls provide soln..
    Thanks

  • Function and procedure call overhead in PL/SQL

    ( I come from a programming background - java/c++ etc and not much PL/SQL )
    Im trying to get a feel of how much extra cycles are spent if something is wrapped inside a function or procedure. I mean will it become considerably inefficient if the logic is within a function as opposed to be directly inline ?

    I did some timings a few years ago and found procedure calls to be slightly more efficient than function calls, presumably due to the fact that functions must pass values back through the function invocation and procedures don't. This may have changed in more recent releases but you can check it yourself.
    Set up a function and a procedure and use dbms_utility to get a starting and ending time marker (this will be the number of seconds from an arbitrary start point as microseconds; you will have to convert). Get a start time, loop through the calls a lot of times, get and end time, and subtract the end time from the start time.
    The prevailing though is that use functions to return values and procedures to perform actions. You can use functions in SQL if written correctly but not procedures.

  • Put SQL query in a function/ call function from region

    How can I write a SQL query (like SELECT EMPNO, ENAME, JOB FROM EMP) as PL/SQL function, and then call this function from the PL/SQL Function Returning SQL Statement region?
    Thanks, Tom

    thanks jverd for your quick reply.
    I know passing in a reference to an object will do the job if I want to change the value several parameters in one function call.
    But I want to ask, is there any other ways?
    the following code works.....
    public class TestParameter {
         public static void main(String[] args) {
              Test2 t2 = new Test2();
              invokeChange(t2);
              System.out.println("x = " + t2.x + "\t y = " + t2.y);
         static void invokeChange(Test2 t2) {
              t2.x = 10;
              t2.y = 15;          
    class Test2 {     
         int x;
         int y;     
    }

Maybe you are looking for