Passing databse functions with parameters as custom parameters from comand

Hi,
I have a database function get_id(ichar varchar2) which will return a number which I am trying to pass to a mapping as custom inout parameter using the following command:
@SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_ID=sample_pkg.get_id('I')"
and I get the following error
------ start----------
Session altered.
Role set.
override_custom_input_params(l_audit_execution_id, 'IN_FROM_DATE=1999/01/0108:00,IN_TO_DATE=2003/12/3108:00,BL_LOAD_ID=bl_job_control.get_bl_load_id('I')');
ERROR at line 215:
ORA-06550: line 215, column 155:
PLS-00103: Encountered the symbol "I" when expecting one of the following:
. ( ) , * @ % & | = - + < / > at in is mod not range rem =>
.. <an exponent (**)> <> or != or ~= >= <= <> and or like
between ||
The symbol ". was inserted before "I" to continue.
------ end ----------
However, the command line with NO parameter to the function like the following command works perfect:
@SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_ID=sample_pkg.get_id"
Will OWB commandline not accept function call with parameters? Please treat this as urgent and advice ASAP.
Thanks.

Thanks, Mark. It works.However facing another issue. I try to pass to_char(sysdate\,''yyyy/mm/ddhh:mi:ss'') as one of the custom parameters to the mapping as
@SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_STDT=2002/10/2010:10:03,INPUT_enddt=to_char(sysdate\,''yyyy/mm/ddhh:mi:ss'')"
and it erros out as
------ start ------
ORA-01841: (full) year must be between -4713 and +9999, and not be 0 ORA-06512: at line 1
------ end ------
Questions:
1. Why does a simple to_char(sysdate\,'yyyy/mm/ddhh:mi:ss') as an input parameter fail?
2.what is the date format that OWB expects when we pass date as an input parameter.Can the format be modified?
OWB seems to accept the format yyyy/dd/mm only. If I pass as different format, it errors with ORA 1861 Text: literal does not match format string.
3. Where can I change the format in OWB if it can be changed.
NOTE: OWB complains only about INPUT_ENDDT and not INPUT_STDT because, if I hardcode INPUT_ENDDT like 2003/11/178:00 it works.
example:
@SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," INPUT_STDT=2002/10/2008:00,INPUT_ENDDT=2003/11/1706:45:59"
works fine.
Am I missing something here?
Thanks again.

Similar Messages

  • How to call a AM method with parameters from Managed Bean?

    Hi Everyone,
    I have a situation where I need to call AM method (setDefaultSubInv) from Managed bean, under Value change Listner method. Here is what I am doing, I have added AM method on to the page bindings, then in bean calling this
    Class[] paramTypes = { };
    Object[] params = { } ;
    invokeEL("#{bindings.setDefaultSubInv.execute}", paramTypes, params);
    This works and able to call this method if there are no parameters. Say I have to pass a parameter to AM method setDefaultSubInv(String a), i tried calling this from the bean but throws an error
    String aVal = "test";
    Class[] paramTypes = {String.class };
    Object[] params = {aVal } ;
    invokeEL("#{bindings.setDefaultSubInv.execute}", paramTypes, params);
    I am not sure this is the right way to call the method with parameters. Can anyone tell how to call a AM method with parameters from Manage bean
    Thanks,
    San.

    Simply do the following
    1- Make your Method in Client Interface.
    2- Add it to Page Def.
    3- Customize your Script Like the below one to Achieve your goal.
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("GetUserRoles");
    operationBinding.getParamsMap().put("username", "oracle");
    operationBinding.getParamsMap().put("role", "F1211");
    operationBinding.getParamsMap().put("Connection", "JDBC");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    return null;
    i hope it help you
    thanks

  • Deploying forms and reports with parameters from portal

    hi , how do i build forms and reports from database limiting them with parameters from the login details on the portal on my application server.

    I had the same problem.
    I resolve with a new third party tool:
    RunDev
    I've found it on:
    solutionmarketplace.oracle.com
    searching "rundev".
    James

  • Executing a oracle function with parameters ...

    Hi All,
    I'm trying to execute this part of the code:
    <cfdirectory action="list"
    directory="#getDirectoryFromPath(sharedPath)#"
    name="currentDir">
    <cfoutput query="currentDir">
    <cfset filename = sharedPath & name>
    <cfif find(".csv",name)>
    <cfexecute name = "#Application.c_script_dropfileupload_path#main_dropfileupload.sh"
    arguments = """#name#"" ""#sharedPath#"""
    variable = "Variables.upload_progress"
    timeout = "500">
    </cfexecute>
    <tr>
    <td colspan="3" class="text">
    <cfquery name="getvalcount"
    datasource="#Application.c_dsn#"
    dbtype="ODBC"
    password="#Session.Password#"
    username="#Session.UserID#">
    SELECT pk_cpv_drop_file_upload.sf_drop_validate_and_count(replace(#name#,".csv","")) FROM dual
    </cfquery>
    <cfoutput> #getvalcount.sf_drop_validate_and_count# </cfoutput>
    </td>
    </tr>
    but I'm receiving the error from oracle telling: illegal zero-length identifier
    My question is...
    IS there a way to pass the parameter #name# to this function sf_drop_validate_and_count ? or should I work with parameters to a stored procedure?
    Thanks in advance
    Regards
    Alex

    Hi ALL,
    Just to inform you that I've found a solution when you need to apply variables as a parameter:
    preserveSingleQuotes(vFileName)
    preserveSingleQuotes function will keep the string like this 'dadsadsad' and so, you can use it inside your functions, procedures, etc..
    Thanks for all the reponses I've received.
    Best regards
    Alex

  • AddEventListener and Function with Parameters

    Hello guys
    I got this situation
    nameTxt.addEventListener(FocusEvent.FOCUS_IN,formTextHandler);
             private function formTextHandler(text:String):void{
    where i want to send some additional information too
    so how could i do that?
    Thanks

    hi,
       it seems like you will need to extend your text Component and Event class as well. Its not clear from your code that what component you are referring to . so generally you will extend your required component .
    you will need to addEvent Listener
    FocusEvent.FOCUS_IN
    in your custom extended component and in the handler of that focusEvent you will dispatch your new custom event with the parameters from this FocusEvent you received and as well as new parameters that are also required by your new extended Event.
    Method of extending events is straight forward. e.g this a sample for extending Events you will need to modify it with the paramaters you require in your event .
    package
        import flash.events.Event;
        public class AccountEvent extends Event
            public var accountObj:Object
            public static var NewAccount:String='newAccount'
            public function AccountEvent(type:String,newAccount:Object)
                super(type)
                this.accountObj=newAccount
    and here is the code how to use this event
    package
        import flash.events.Event;
        import flash.events.FocusEvent;
        import AccountEvent
        import mx.controls.TextInput
        public class customText extends TextInput
            public function customText()
                super();
                addEventListener(FocusEvent.FOCUS_IN,onFocus)
            private function onFocus(e:FocusEvent):void{
                dispatchEvent(new AccountEvent(paramaters.....///here you will add your custom paramerters and 
               //you will catch this event in your main application rather then catching the focus in event

  • Calling DB2 Stored procedure(with parameters) from powershell

    Hi 
    I am trying to call a DB2 stored procedure that has parameters from Powershell scrip and I am not able to can some one help me here?
    $ServerName = 'XXXX'
    $dbalias='XXXXX'
     $conn_string = "Provider=IBMDADB2;DBALIAS=$dbalias;Uid=;Pwd=;"
     $conn = new-Object system.data.Oledb.OleDbconnection
     $conn.ConnectionString = $conn_string
     $conn.open()
     $query="CALL DBID_CONTROL.GET_TABLE_MAINT_CTL(?,?,?,'MSAS','DATABASE_CONNECTIONS_CUBE','CUBE_PARTITION');"
     $cmd = new-Object system.data.Oledb.OleDbcommand($query,$conn)
      $ds=New-Object system.Data.DataSet
     $da=New-Object System.Data.OleDb.OleDbDataAdapter($cmd)
      $da.Fill($ds) [int]$cur_utc_date_key = $ds.Tables[0].Rows[0][0]
     $cur_utc_date          = $ds.Tables[0].Rows[0][1]
     ###list current date key & current date values
     write-output "current date key value is $cur_utc_date_key"
     write-output "current date value is $cur_utc_date"
     write-output " "
    Thanks

    Hi 
    This is the error message i get when i run the script
    Exception calling "Fill" with "1" argument(s): " CLI0100E  Wrong number of parameters. SQLSTATE=07001"
    At line:45 char:10
    +  $da.Fill <<<< ($ds)
        + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : DotNetMethodException

  • PL/SQL to execute exe file with parameters from DB

    Hi all,
    I have a bit of a problem.
    I am in need to write all Logon, Logoff and Logon fail data onto the Windows Application Log. To do this I already tried various solutions but with my configuration (Oracle EE 10.2.0.4 and Windows Server 2003 R2 X64) the only possible solution (apparently) is the following.
    I create a Table with the info I need:
    CREATE TABLE logonaudittable
    event VARCHAR2(15),
    sid NUMBER,
    serial# NUMBER,
    orario DATE,
    username VARCHAR2(30),
    osuserid VARCHAR2(30),
    machinename VARCHAR2(64)
    I create a trigger for Logon Data, one for Logoff and one for Logon Fail:
    LOGON trigger.
    CREATE OR REPLACE TRIGGER logonauditing AFTER LOGON ON database
    DECLARE
    machinename VARCHAR2(64);
    osuserid VARCHAR2(30);
    v_sid NUMBER(10);
    v_serial NUMBER(10);
    CURSOR c1 IS
    SELECT sid, serial#, osuser, machine
    FROM v$session WHERE audsid = userenv('sessionid');
    BEGIN
    OPEN c1;
    FETCH c1 INTO v_sid, v_serial, osuserid, machinename;
    INSERT INTO logonaudittable VALUES ( 'LOGON', v_sid, v_serial, sysdate,
    user, osuserid, machinename );
    CLOSE c1;
    END;
    LOGOFF trigger
    CREATE OR REPLACE TRIGGER logoffauditing
    BEFORE LOGOFF ON database
    DECLARE
    machinename VARCHAR2(64);
    osuserid VARCHAR2(30);
    v_sid NUMBER(10);
    v_serial NUMBER(10);
    CURSOR c1 IS
    SELECT sid, serial#, osuser, machine
    FROM v$session WHERE audsid = userenv('sessionid');
    BEGIN
    OPEN c1;
    FETCH c1 INTO v_sid, v_serial, osuserid, machinename;
    INSERT INTO logonaudittable VALUES ( 'LOGOFF', v_sid, v_serial, sysdate,
    user, osuserid, machinename );
    CLOSE c1;
    END;
    LOGON FAIL trigger
    CREATE OR REPLACE TRIGGER logonfailauditing
    AFTER SERVERERROR ON database
    DECLARE
    machinename VARCHAR2(64);
    osuserid VARCHAR2(30);
    v_sid NUMBER(10);
    v_serial NUMBER(10);
    CURSOR c1 IS
    SELECT sid, serial#, osuser, machine
    FROM v$session WHERE audsid = userenv('sessionid');
    BEGIN
    IF (IS_SERVERERROR(1017)) THEN
    OPEN c1;
    FETCH c1 INTO v_sid, v_serial, osuserid, machinename;
    INSERT INTO logonaudittable VALUES ( 'FAILLOGON', v_sid, v_serial, sysdate,
    user, osuserid, machinename );
    CLOSE c1;
    END IF;
    END;
    The I create a trigger that starts every time something is written on the table.
    This trigger needs to start an EXE file that writes the latest data written on the table into the Windows Application Log.
    So I need a trigger that executes my WRITELOG.EXE file adding the parameters. For example:
    Execute WRITELOG.EXE event sid orario username
    So my program will write a Log in Windows with this data:
    Event: LOGON
    Sid: 2938473
    Orario: 12/12/2011 11:45:32
    Username: Scott
    And so on.
    I already have the program that does this, I need to execute the program with the right data directly from trigger or from a procedure executed by my trigger.
    Hope I've been clear and REALLY hope someone can help me!!!
    Thank you all!

    The java and PL/SQL you need to set up is in the very first response in the link. (I don't have a windows Oracle DB DBMS_JAVA to try it myself). Change the UNIX command '/usr/bin/ls' to your Windows command 'c:\yourdirectory\FILE.EXE'. Assuming you created everything and set permissions as Tom describes (later in the thread), your PL/SQL call in your trigger might look something like this:
    CREATE OR REPLACE TRIGGER logonauditing AFTER LOGON ON database
    DECLARE
    machinename VARCHAR2(64);
    osuserid VARCHAR2(30);
    v_sid NUMBER(10);
    v_serial NUMBER(10);
    CURSOR c1 IS
    SELECT sid, serial#, osuser, machine
    FROM v$session WHERE audsid = userenv('sessionid');
    BEGIN
    OPEN c1;
    FETCH c1 INTO v_sid, v_serial, osuserid, machinename;
    INSERT INTO logonaudittable VALUES ( 'LOGON', v_sid, v_serial, sysdate,
    user, osuserid, machinename );
    RUN_CMD('c:\yourdirectory\FILE.EXE LOGON '||v_sid||' '||v_serial||' '||to_char(sysdate,'MM/DD/YYYY')||' '||user||' '||osuserid||' '||machinename);
    CLOSE c1;
    END;
    Since you want to log what the trigger is writing to the table, you can call the executable with the same information you are writing, instead of writing then reading it back out again.

  • Function Module to fetch Customer Number from Sales Order or Process Order

    Hi Gurus,
    I am looking for a Function module which gives me customer number from Sales order or Process order.
    Please let me know of any FM's available.
    Regards,
    Madan

    Hi,
    Thanks for your response.
    I am actually looking for function modules which take "Sales Order" or "Process Order" as input (import parameter) and return Customer Number as output (export parameter).
    Please suggest some function modules you know any.
    Many Thanks,
    Madan

  • How to call a function with parameters in ScriptStart function

    i am trying to call ScriptStart function from SUD dialog. This is how iam calling Call ScriptStart(path & "test.vbs","abc") abc is function which is written test.vbs. It is working. But when i want to pass some parameters to the abc function of test.vbs. It is not working why. can anybody suggest where i went wrong. I am calling the same function as Call ScriptStart(path & "test.vbs","abc(" & text1.Text & ")"). It is not working why ? Is the ScriptStart function only point to functions. it does not take any parameters or waht ?

    Hi abc421,
    Another option in addition to UserCommands would be to use ScriptInclude(path). If you execute a ScriptInclude(path) command at the beginning of your VBScript, then all the functions and Subs in the VBscript located at "path" are now available to you-- including passing parameters and receiving return values from functions. If you are calling a VBscript that uses only VBScript variables, then this is the preferred method.
    If instead you are calling a VBScript that uses global DIAdem variables declared in a VAS file (their variable names all end with the "_" character), then those parameters are already available at the subroutine called with ScriptStart(path, routine).
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Call Plugin-Function with parameters via JavaScript

    Hi!
    I have following problem: I wrote a plugin for Illustrator CS2 in C++ and now I would like to call a function of the plugin from outside of illustrator (from a JavaScript).
    This can be done with the Actionsuite. But how could I then give some parameters to my function?
    For example:
    In the plugin, I have a function "void myFun(char * test)" and I want to call this function in JavaScript with test="Hello World" for example.
    The only possible way right now seems to write parameters into a file and open that file in the plugin to "receive" them.

    Hi,
    Could you send your plugin coding.
    Regards,
    Maria

  • Use of IN function with parameters?

    is it possible to use a parameter with an IN function, inside an explicit cursor?
    oracle doesn't accept varchars or collections.
    it should be something like this:
    CURSOR (myParam VARCHAR2) IS
    SELECT *
    FROM myTable
    WHERE myColumn IN (myParam);
    Thank you!
    Saverio M.

    Sorry just one correction
    Do you mean Parameterized Cursors ?
    declare
    v_emp number;
    v_emp1 number;
    cursor c1(v_emp in number)
    is
    select * from empdept where empno=v_emp;
    begin
    v_emp1 :=9939; -- For Example you
    for x in c1(v_emp1)
    loop
    --- Do your processes.
    null;
    end loop;
    end;
         | Legal | Privacy

  • Call pl-sql function with parameters All

    I want to call a procedure inside Discoverer; i know how to do that. I have three page elements ; when i choose specific value for each one my function work properly.
    When i choose <All> like a value for any page element ; funtion doesn't run properly. We decide to display the input value when i call function; when i choose <All> value i can't see the value of the parameter. I put nvl(P1,'ABC') and i can't see the value of the parameter.
    In Discovere; when we choose <All> value what is the real value or character used to call function.
    Thanks
    Marc

    see my function
    FUNCTION "F_SSDW_TEMPS_NET_FONCT_MIN"("P_NO_CENTRE_DISTR" IN NUMBER,
    "P_ID_QUART_TRAVAIL" IN NUMBER,
    "P_CODE_EQUIPEMENT" IN VARCHAR2 ,
    "P_DATE_TRANSACTION" IN DATE ) RETURN VARCHAR2 IS
    CURSOR CRS_TEMPS_NET_FONCT_MIN IS
    SELECT SUM(NVL(EFF_REMPL.TEMPS_NET_FONCT_MIN,0))
    FROM SSDW_EFF_REMPL EFF_REMPL,
    SSDW_EFF_REMPL_QUART_TRAVAIL EFF_QUART
    WHERE EFF_REMPL.NO_CENTRE_DISTRIBUTION = P_NO_CENTRE_DISTR
    and EFF_REMPL.id_quart_travail = EFF_QUART.ID_QUART_TRAVAIL_CENTRE_DISTR
    and EFF_QUART.quart_travail = P_ID_QUART_TRAVAIL
    AND EFF_REMPL.CODE_EQUIPEMENT = decode(UPPER(P_CODE_EQUIPEMENT),'TOUS',EFF_REMPL.CODE_EQUIPEMENT, P_CODE_EQUIPEMENT )
    AND TRUNC(EFF_REMPL.DATE_TRANSACTION) = TRUNC(P_DATE_TRANSACTION);
    V_TEMPS_NET_FONCT_MIN NUMBER;
    BEGIN
    OPEN CRS_TEMPS_NET_FONCT_MIN;
    FETCH CRS_TEMPS_NET_FONCT_MIN INTO V_TEMPS_NET_FONCT_MIN;
    CLOSE CRS_TEMPS_NET_FONCT_MIN;
    RETURN ('ZZ'||to_char(P_CODE_EQUIPEMENT||'ZZ');
    END;
    I know how to use a function inside discoverer; my question is ; for my four input parameters ( each one correspond to a page-element )
    My question is ; if i decide to choose to select the value <All> for equipement code; what will be the real value passed in parameter to my function.
    Like you can see in my code ; i decide to return the parameter in value.
    When i select <All> the output parameter equal nothing ; i see absoltely nothing in screen ; i don't see 'ZZ'
    Thanks
    Marc

  • Apex3.2.1 pipelined functions with parameters send cpu to 100 percent

    I have just installed 11g and exported a schema from 10g into it.
    When I run Apex3.2.1 and open a page with a flash chart that running off a table object populated by a pipelined function the CPU goes in overload 100%.
    I have tracked the problem to parameters on the pipelined function if I use bind parameters( :P640_YEARS, :P640_EMPLOYER_ID) then the problem happens but if I hard code values all is fine (2010,99).
    This happens with every flash chart we have, which makes our application and database unusable.
    Any ideas.
    Derek

    Thanks very much for the posts, I took the opportunity to upgrade to Apex 4.0.2 as suggested by Patrick and the application works fine again now.
    Interestingly I did re-analyse the statistics but only as a reaction to the problem, should have been done regardless.
    I did consider re-writing the pipelined functions but to be honest it would have been difficult as they are extremely complex, I wasn't looking forward to the task. I have become quite a fan of pipelined functions for building flash charts, dash boards extra, its as always about tuning the sql.
    Thanks very to all
    Derek
    Edited by: 835735 on Feb 10, 2011 1:50 PM

  • [shellscript] Passing a script with parameters to AT

    Hey everybody,
    I would like to learn shell scripting so I created a script to mount/unmount my truecrypt volume. This is what I have so far:
    #!/bin/bash
    case "$1" in
    start)
    truecrypt -k '' /dev/array/vault /home/<user>/vault
    stop)
    truecrypt -d /home/<user>/vault
    echo "usage: $0 (start|stop)"
    esac
    exit 0
    Now I would like to add another feature. I want it to automatically unmount after 2 hours. I found the "at" command which should be able to do this.
    I would need to do something like:
    start)
    truecrypt -k '' /dev/array/vault /home/<user>/vault
    at -f "$1 stop" now + 2 hours
    However, running just " at -f "./vault.sh start" now + 2 minutes " fails:
    warning: commands will be executed using /bin/sh
    Cannot open input file ./vault.sh start: No such file or directory
    If I can get this working I would like the "stop" code to remove any scheduled stop operations (for when I do it manually).  Also, I would like to include a "keepalive" function that allows me to kill the scheduled stop task and reschedule it again to restart the countdown. This would allow me to keep the volume mounted if I want to use it for a longer period of time.
    Is it possible to execute scripts + parameters with "at"?  Can somebody help me to make this work?
    Thanks a bunch!
    P.S: Truecrypt also keeps asking me this:
    Protect hidden volume (if any)? (y=Yes/n=No) [No]:
    I would like to specify this in the command so that I don't have to hit enter every time. I've looked at the man page but found nothing helpfull. Anyone?

    Make sure that vault.sh exists in the directory that you are executing it from. It may be better to refer to the whole file location rather than just './'. eg use " at -f "~/vault.sh start" now + 2 minutes " rather than just  " at -f "./vault.sh start" now + 2 minutes ".
    Providing thatyou are happy for TrueCrypt to accept the default answer for any questions it asks you can just pipe yes into it:
    yes | truecrypt -k '' /dev/array/vault ~/vault
    Yes will 'press enter' to any questions that TrueCrypt asks.
    Last edited by gadget3000 (2011-07-14 16:46:01)

  • [8i] Help with function with parameters (for workday calculation)

    Let me start by saying, I've never written a function before, and I don't have access to create a function in my database (i.e. I can't test this function). I'm trying to come up with a function that I can ask my IT department to add for me. I'm hoping someone can take a look at what I've written and tell me if it should work or not, and if this is the right way to go about solving my problem.
    I am trying to create a function to do a very simple workday calculation (adding/subtracting a particular number of workdays from a calendar date).
    The database I'm working with has a table with the workday calendar in it. Here is a sample table and sample data, representative of what's in my workday calendar table:
    CREATE TABLE caln
    (     clndr_dt     DATE,
         shop_days     NUMBER(5)
         CONSTRAINT caln_pk PRIMARY KEY (clndr_dt)
    INSERT INTO     caln
    VALUES (To_Date('01/01/1980','mm/dd/yyyy'),0);
    INSERT INTO     caln
    VALUES (To_Date('01/02/1980','mm/dd/yyyy'),1);
    INSERT INTO     caln
    VALUES (To_Date('01/03/1980','mm/dd/yyyy'),2);
    INSERT INTO     caln
    VALUES (To_Date('01/04/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/05/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/06/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/07/1980','mm/dd/yyyy'),4);
    INSERT INTO     caln
    VALUES (To_Date('01/08/1980','mm/dd/yyyy'),5);
    INSERT INTO     caln
    VALUES (To_Date('01/09/1980','mm/dd/yyyy'),6);
    INSERT INTO     caln
    VALUES (To_Date('01/10/1980','mm/dd/yyyy'),7);
    INSERT INTO     caln
    VALUES (To_Date('01/11/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/12/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/13/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/14/1980','mm/dd/yyyy'),9);The actual table includes from 1/1/1980 though 12/31/2015.
    I've written (and validated) this parameter query which does my workday (mday) calculation:
    SELECT     cal.clndr_dt
    FROM     CALN cal
         SELECT     cal.shop_days+:mdays     AS new_shop_days
         FROM     CALN cal
         WHERE     cal.clndr_dt     =:start_date
         ) a
    WHERE     cal.shop_days     = a.new_shop_days
    AND     ROWNUM          =1
    ORDER BY     cal.clndr_dt;Based on this query, I've created the following function (and I have no clue if it works or if the syntax is right, etc.):
    CREATE OR REPLACE FUNCTION add_mdays
         (start_date     IN DATE,
         mdays          IN NUMBER(5))
    RETURN     DATE
    IS
         new_date DATE;
    BEGIN
         SELECT     cal.clndr_dt
         FROM     CALN cal
              SELECT     cal.shop_days+mdays     AS new_shop_days
              FROM     CALN cal
              WHERE     cal.clndr_dt     =start_date
              ) a
         WHERE     cal.shop_days     = a.new_shop_days
         AND     ROWNUM          =1
         ORDER BY     cal.clndr_dt;
         RETURN     new_date;
    END add_mdays;  //edit 9:31 AM - noticed I left off this bitI'm also not sure how to have the function handle results that would return a date outside of the date range that is in the table (Before 1/1/1980 or after 12/31/2015--or, another way to look at it is, before the MIN value of caln.clndr_dt or after the MAX value of caln.clndr_dt).
    My goal is to be able to use the function in a situation like the following:
    First, here's a sample table and data:
    CREATE TABLE orders
    (     ord_no          NUMBER(5),
         plan_start_dt     DATE,
         CONSTRAINT orders_pk PRIMARY KEY (ord_no)
    INSERT INTO orders
    VALUES (1,To_Date('01/08/1980','mm/dd/yyyy'));
    INSERT INTO orders
    VALUES (2,To_Date('01/09/1980','mm/dd/yyyy'));
    INSERT INTO orders
    VALUES (3,To_Date('01/10/1980','mm/dd/yyyy'));And here is how I would like to use my function:
    SELECT     orders.ord_no
    ,     orders.plan_start_dt
    ,     add_mdays(orders.plan_start_dt, -3) AS prep_date
    FROM     ordersThus, the function would allow me to return, for every order in my orders table, the date that is 3 workdays (mdays) prior to the plan start date of each order.
    Am I going about this the right way? Do I need to create a function to do this, or is there a way for me to incorporate my query (that does my mday calculation) into the sample query above (eliminating the need to create a function)?
    Thanks much in advance!
    Edited by: user11033437 on Feb 2, 2010 8:55 AM
    Fixed a couple typos in the last insert statements
    Edited by: user11033437 on Feb 2, 2010 9:31 AM (fixed some syntax in the function)

    Hi,
    Ah, mentioning Oracle 8 and not being able to test your own code makes me nostalgic for the good old days, when you typed your cards, and brought them to a window at the computer center, and waited an hour for the job to run, and then saw the printout to find that you had made a typo.
    If you're going to write functions, you really need to test them yourself. Like all code, functions whould be written in baby steps: write a line or two (or sometimes just part of what will later become one line), test, make sure it's running correctly, and repeat.
    Ideally, your employer should create a developement schema in a development database for you to use.
    You can legally download your own instance of Oracle Express Edition for free; just be careful not to use features that aren't available in the database where the code will be deployed.
    You don't need a function to get the results you want:
    SELECT       o.ord_no
    ,       o.plan_start_dt
    ,       MIN (e.clndr_dt)     AS prep_date
    FROM       orders     o
    ,       caln          l
    ,       caln          e
    WHERE       l.clndr_dt     = o.plan_start_dt
    AND       e.shop_days     = l.shop_days - 3
    GROUP BY  o.ord_no
    ,            o.plan_start_dt
    ;This would be more efficient (and a little simpler) if you added a column (let's call it work_day) that identified if each row represented a work_day or not.
    For each value of shop_days, exactly 1 row will be marked as a work day.
    Then the query might be something like:
    SELECT       o.ord_no
    ,       o.plan_start_dt
    ,       e.clndr_dt          AS prep_date
    FROM       orders     o
    ,       caln          l
    ,       caln          e
    WHERE       l.clndr_dt     = o.plan_start_dt
    AND       e.shop_days     = l.shop_days - 3
    AND       e.work_day     = 1
    ;You could use the analytic LAG function to populate the work_day column.
    A function would certainly be handy, though perhaps slower.
    The function you posted has a few mistakes:
    (a) An argument can't be declared as NUMBER (5); just NUMBER.
    (b) When you SELECT in PL/SQL, like you're doing, you have to SELECT INTO some variable to hold the results.
    (c) ROWNUM is arbitrary (which makes it useless in this problem) unless you are drawing from an ordered sub-query. I don't think you can use ORDER BY in sub-queries in Oracle 8. Use the analytic ROW_NUMBER function instead.
    (d) The function must end with an END statement.
    Given your current caln table, here's how I would write the function:
    CREATE OR REPLACE FUNCTION add_mdays
         ( start_date     IN           DATE          DEFAULT     SYSDATE,
           mdays          IN           NUMBER          DEFAULT     1
    RETURN     DATE
    DETERMINISTIC
    IS
         --     add_mdays returns the DATE that is mdays working days
         --     after start_date.  (If mdays < 0, the DATE returned
         --     will be before start_date).
         --     Work days do not include Saturdays, Sundays or holidays
         --     as indicated in the caln table.
         new_date     DATE;          -- to be returned
    BEGIN
         SELECT     MIN (t.clndr_dt)
         INTO     new_date
         FROM     caln     f     -- f stands for "from"
         ,     caln     t     -- t stands for "to"
         WHERE     f.clndr_dt     = TRUNC (start_date)
         AND     t.shop_days     = f.shop_days + TRUNC (mdays)
         RETURN     new_date;
    END     add_mdays;
    SHOW ERRORSProduction code whould be robust (that includes "idiot-proofing").
    Try to foresee what errors people might make in calling your function, and correct for them when possible.
    For example, if it only makes sense for start_date to be midnight, or mdays to be an integer, then use TRUNC in the function in case soembody passes a bad value.
    Allow for default arguments.
    Comment your function. Put all comments within the function (that is, after CREATE and before the final END) so that they will be kept in the data dictionary.
    If, given the same arguments, the function always returns the same value, mark it as DETERMINISTIC, for efficiency. This means the system may remember values passed back rather than call the function every time it is told to.
    I wish I could mark questions as "Correct" or "Helpful"; you'd get 10 points for sure.
    You posted CREATE TABLE and INSERT statements (without even being begged).
    You gave a clear description of the problem, including desired results.
    The code is nicely formatted and easy to read.
    All around, one of the most thoughtful, well-written questions I've seen.
    Well done! Keep up the good work!
    Edited by: Frank Kulash on Feb 2, 2010 1:10 PM
    Added my own version of the function.

Maybe you are looking for