Stored Procedures with Date data types and Oracle

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Stored Procedures with Date data types and Oracle

    This should be easy.... But i keep getting the error:

    ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in
    call to 'RETRIEVE_TS' ORA-06550: line 1, column 7: PL/SQL: Statement ignored

    And I got it worked out to where i know it is a problem with the way i am
    using the date data types in a stored procedure....

    In the past i usually avoided calling procedures in Oracle with date as the in
    type.... It is always easiest to let oracle convert the string to a date....
    Unfortunately now i am stuck with having a date type in the procedure call....
    So the question is:

    WHAT IS THE PROPER WAY TO SUBMIT DATE/TIME STAMP IN A STORED PROCEDURE?

    The Oracle Procedure looks like this:

    PROCEDURE retrieve_ts (
    p_at_tsv_rc IN OUT sys_refcursor,
    p_units IN OUT VARCHAR2,
    p_officeid IN VARCHAR2,
    p_timeseries_desc IN VARCHAR2,
    p_start_time IN DATE,
    p_end_time IN DATE,
    p_timezone IN VARCHAR2 DEFAULT 'GMT',
    p_trim IN NUMBER DEFAULT false_num,
    p_inclusive IN NUMBER DEFAULT NULL,
    p_versiondate IN DATE DEFAULT NULL,
    p_max_version IN NUMBER DEFAULT true_num
    )

    AND the stored procedure call looks like this:

    <cfset ed = Now()>
    <cfset sd = #DateAdd("d",-lbt,Now())#>

    <cfstoredproc datasource="CWMS"
    procedure="cwms.cwms_ts.retrieve_ts"
    returncode="no">
    <cfprocparam type="inout" variable="unit" value="#unit#"

    dbvarname="@p_units"
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="in" value="MVS"

    dbvarname="@p_officeid"
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="in" value=#id.cwms_ts_id#

    dbvarname="@p_timeseries_desc"
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="in" value="#sd#"

    dbvarname="@p_start_time"
    cfsqltype="cf_sql_date">

    <cfprocparam type="in" value="#_ed#"

    dbvarname="@p_end_time"
    cfsqltype="cf_sql_date">

    <cfprocparam type="in" value="#tz#"

    dbvarname="@p_time_zone"
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="in" value="0"

    dbvarname="@p_trim"
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="in" value=""
    null = "yes"

    dbvarname="@p_inclusive"
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="in" value=""
    null="yes"

    dbvarname="@p_versiondate"
    cfsqltype="cf_sql_date">

    <cfprocparam type="in" value="1"

    dbvarname="@p_max_version"
    cfsqltype="cf_sql_numeric">

    <cfprocresult name="ts_dat">

    </cfstoredproc>


    Text

    jasun123 Guest

  2. Similar Questions and Discussions

    1. Oracle Thin Client and Stored Procedures
      We have a stored procedures in Oracle that we are trying to call from ColdFusion MX 7 using the Oracle Thin Client. The request hangs -- we never...
    2. Calling Oracle overloaded stored procedures from CF 6.1
      Did any of you tried to call an Oracle overloaded stored procedure from CF 6.1? You will be amazed to know that it doesn't work. :)) Please test...
    3. Cannot view Oracle Stored Procedures in Dreamweaver XP
      Does anyone know how to get round this? I've defined and tested the connection to the Oracle database and everything seems to work OK, but when I...
    4. script to show last change date for stored procedures and tables?
      I need a script that will display the last change date for the definitions for stored procedures and tables within a database. I'd also be very...
    5. Oracle stored procedures vs Running from a flat .sql file
      Does anyone know what the advantages are to using stored procedures and java stored procedures over and above running from flat unix files. I...
  3. #2

    Default Re: Stored Procedures with Date data types and Oracle

    First of all, you can get rid of the dbvarname parameters, as they have been
    depricated in MX and server absolutely no purpose. You still must match up each
    cfprocparam with its stored procedure parameter in number, type, and order.

    What version of Oracle are you on? There have been some issues with recent
    versions of Oracle and date/time verses timestamp data types (10g for sure,
    later 9i as well), but assuming that this isn't the case, try using
    cfsqltype="CF_SQL_TIMESTAMP" instead of CF_SQL_DATE for Oracle date/time data
    types.

    Phil


    paross1 Guest

  4. #3

    Default Re: Stored Procedures with Date data types and Oracle

    Phil -

    We are running Oracle 9.2.0.6.....

    Tried timestamp... same error....

    jasun123 Guest

  5. #4

    Default Re: Stored Procedures with Date data types and Oracle

    Hmmm, try moving p_at_tsv_rc IN OUT sys_refcursor to being the last parameter in your stored procedure declaration (don't forget to move it in the package spec as well as in the body!)

    Phil
    paross1 Guest

  6. #5

    Default Re: Stored Procedures with Date data types and Oracle

    I will try moving the refference cursor to the end, but am afraid that isn't
    going to work either.... Let me try to clarify why i know it is a date
    datatype problem....

    What i did was right a similar pl/sql procedure that accepts all the same
    variable types as the package cwms_ts.retrieve_ts with one exception.... I
    send the start and endtimes as varchar to the stored procedure and convert them
    to dates inside Oracle.... It worked fine....

    Hence it is something with sending dates through the stored procedure....

    I think the links you show is the right direction to try.....



    jasun123 Guest

  7. #6

    Default Re: Stored Procedures with Date data types and Oracle

    OK, so the solution (for most) appears to be add this to the CF Admin JVM
    settings:
    -Doracle.jdbc.V8Compatible=true

    I did this.... It still doesn't work..... used both cfsqltype = cf_sql_date
    and cf_sql_timestamp....

    Any other ideas?


    jasun123 Guest

  8. #7

    Default Re: Stored Procedures with Date data types and Oracle

    Wow, I don't know what to tell you. I'm running Oracle 9.2.0.5 and MX 7
    (7,0,1,116466) and have not experienced the same problems that you are having.
    I created a test procedure with a date/timestamp IN parameter, a VARCHAR2 OUT
    parameter, and a ref cursor result set. The setup is listed below, and mine
    works like a champ.

    <<cfstoredproc procedure="test_pkg.test" datasource="myDSN" returncode="no">
    <cfprocparam type="IN" cfsqltype="cf_sql_timestamp" value="15-JUN-2005">
    <cfprocparam type="OUT" cfsqltype="cf_sql_varchar" variable="v_out">
    <cfprocresult name="rs1">
    </cfstoredproc>

    PROCEDURE test(
    v1_in IN date default null,
    v2_out OUT varchar2,
    v3_out OUT ref_cur_type)

    IS
    BEGIN

    v2_out := TO_CHAR(v1_in, 'mm/dd/yyyy');

    OPEN v3_out
    FOR
    SELECT *
    FROM user
    WHERE activation_date >= v1_in;

    END test;

    Phil

    paross1 Guest

  9. #8

    Default Re: Stored Procedures with Date data types and Oracle

    What about the number of arguments? There are 11 of them In the stored procedure and only 10 in thecalling page.
    CF_Oracle Guest

  10. #9

    Default Re: Stored Procedures with Date data types and Oracle

    Yeah.... One is a type INOUT ref cursor.... which is denoted by the
    cfprocresult....

    By the way:

    Phil - the code example with a little tweaking worked fine on my machine....

    <<cfstoredproc procedure="test_pkg.test" datasource="myDSN" returncode="no">
    <cfprocparam type="IN" cfsqltype="cf_sql_timestamp" value="15-JUN-2005">
    <cfprocparam type="OUT" cfsqltype="cf_sql_varchar" variable="v_out">
    <cfprocresult name="rs1">
    </cfstoredproc>

    PROCEDURE test(
    v3_out OUT ref_cur_type,
    v1_in IN date default null,
    v2_out OUT varchar2
    )

    IS
    BEGIN

    v2_out := TO_CHAR(v1_in, 'mm/dd/yyyy');

    OPEN v3_out
    FOR
    SELECT *
    FROM user
    WHERE activation_date >= v1_in;

    END test;

    Why do i still get this error......


    Here is what it looks like now:


    PROCEDURE retrieve_ts (
    p_at_tsv_rc IN OUT sys_refcursor,
    p_units IN OUT VARCHAR2,
    p_officeid IN VARCHAR2,
    p_timeseries_desc IN VARCHAR2,
    p_start_time IN DATE,
    p_end_time IN DATE,
    p_timezone IN VARCHAR2 DEFAULT 'GMT',
    p_trim IN NUMBER DEFAULT false_num,
    p_inclusive IN NUMBER DEFAULT NULL,
    p_versiondate IN DATE DEFAULT NULL,
    p_max_version IN NUMBER DEFAULT true_num
    )


    <cfstoredproc datasource="CWMS"
    procedure="cwms.cwms_ts.retrieve_ts"
    returncode="no">

    <cfprocparam type="INOUT" variable="p_units" value="#unit#" <!---p_units--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="MVS" <!---p_officeid--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value=#id.cwms_ts_id# <!---p_timeseries_desc--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="#sd#" <!---p_start_time--->
    cfsqltype="cf_sql_timestamp">

    <cfprocparam type="IN" value="#ed#" <!---p_end_time--->
    cfsqltype="cf_sql_timestamp">

    <cfprocparam type="IN" value="#tz#" <!---p_timezone--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="0" <!---p_trim--->
    cfsqltype="cf_sql_integer">

    <cfprocparam type="IN" value="" <!---p_inclusive--->
    null = "yes"
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="IN" value="" <!---p_versiondate--->
    null="yes"
    cfsqltype="cf_sql_timestamp">

    <cfprocparam type="IN" value="1" <!---p_max_version--->
    cfsqltype="cf_sql_integer">

    <cfprocresult name="ts_dat"> <!---sys_refcursor--->

    </cfstoredproc>


    If I truly am short a parameter, How do you specify the INOUT sys_refcursor?

    jasun123 Guest

  11. #10

    Default Re: Stored Procedures with Date data types and Oracle

    Jason, check this discussion on similar topic - it could help:
    [url]http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=6&threadid=1010746&messageid =3618652[/url]
    CF_Oracle Guest

  12. #11

    Default Re: Stored Procedures with Date data types and Oracle

    You are NOT short a parameter, as you would not include one for your refcursor
    since your CFPROCRESULT tag takes care of your refcursor, because that is how
    you are returning your result set. However, you should probably declare it as
    OUT only in your PL/SQL, as you would never be able to pass a refcursor
    parameter from ColdFusion to PL/SQL. Having said that, I modified my test
    procedure by making the refcursor an IN OUT, and also moving that parameter to
    be the first parameter in the PL/SQL declaration, and I did not get any error.
    So, I'm at a loss. This procedure isn't overloaded, is it?

    Phil

    paross1 Guest

  13. #12

    Default Re: Stored Procedures with Date data types and Oracle

    I have finally had some time to work on this again and I am still at a loss:

    Again its gotta be something with the date type:

    I get this to work:

    PL/SQL:

    CREATE OR REPLACE PROCEDURE "RET_TS2"(
    p_at_tsv_rc IN OUT sys_refcursor,
    p_units IN OUT VARCHAR2,
    p_officeid IN VARCHAR2,
    p_timeseries_desc IN VARCHAR2,
    p_start_time IN VARCHAR2,
    p_end_time IN VARCHAR2,
    p_timezone IN VARCHAR2 DEFAULT 'GMT',
    p_trim IN NUMBER DEFAULT cwms.cwms_ts.FALSE_NUM,
    p_inclusive IN NUMBER DEFAULT NULL,
    p_versiondate IN DATE DEFAULT NULL,
    p_max_version IN NUMBER DEFAULT cwms.cwms_ts.TRUE_NUM
    )

    IS

    st DATE := TO_DATE(p_start_time, 'MM-DD-YYYY HH24:MI');
    et DATE := TO_DATE(p_end_time, 'MM-DD-YYYY HH24:MI');

    BEGIN

    cwms.cwms_ts.retrieve_ts(p_at_tsv_rc, p_units, p_officeid, p_timeseries_desc,
    st, et, p_timezone, p_trim, p_inclusive, p_versiondate, p_max_version);

    END;
    /



    Coldfusion:

    <cfset ed = #DateFormat(Now(), "mm-dd-yyyy")#&" "&#TimeFormat(Now(), "HH:mm")#>

    <cfset temp_sd = #DateAdd("d",-lbt,ed)#>
    <cfset sd = #DateFormat(temp_sd, "mm-dd-yyyy")#&" "&#TimeFormat(temp_sd,
    "HH:mm")#>

    <cfstoredproc datasource="CF" result="test1"
    procedure="ret_ts2"
    debug="yes">

    <cfprocparam type="INOUT" variable="p_units" value="#unit#" <!---p_units--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="MVS" <!---p_officeid--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value=#id.cwms_ts_id# <!---p_timeseries_desc--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="#sd#" <!---p_start_time--->
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="#ed#" <!---p_end_time--->
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="US/Central" <!---p_timezone--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="0" <!---p_trim--->
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="IN" value="" <!---p_inclusive--->
    null = "yes"
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="IN" value="" <!---p_versiondate--->
    null="yes"
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="1" <!---p_max_version--->
    cfsqltype="cf_sql_numeric">

    <cfprocresult name="ts_dat1"> <!---sys_refcursor--->

    </cfstoredproc>

    Still stuck..... Any more advice????



    jasun123 Guest

  14. #13

    Default Re: Stored Procedures with Date data types and Oracle

    By any chance, is this procedure overloaded?

    Phil
    paross1 Guest

  15. #14

    Default Re: Stored Procedures with Date data types and Oracle

    Ok... Overloaded - yes i think?.... I had a function pipelined called
    retrieve_ts... I renamed it to retrieve_ts_pipe.... Ran the stuff again...
    Same error....

    [Macromedia][Oracle JDBC Driver][Oracle]ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'RETRIEVE_TS'
    ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in
    call to 'RETRIEVE_TS' ORA-06550: line 1, column 7: PLS-00306: wrong number or
    types of arguments in call to 'RETRIEVE_TS' ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    sd and ed are created using the now and dateadd functions

    ed {ts '2006-06-08 13:16:25'}
    sd {ts '2006-06-04 13:16:25'}

    I am using Oracle 9i and I get the same error when i do:

    <cfprocparam type="IN" value="#DateFormat(DateAdd("d",-lbt,Now()),
    "yyyy-mm-dd")#" <!---p_start_time--->
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="#DateFormat(Now(), "yyyy-mm-dd")#"
    <!---p_end_time--->
    cfsqltype="cf_sql_date">

    If that isn't a valid date format for the Oracle driver, do you know where i
    can find it?


    jasun123 Guest

  16. #15

    Default Re: Stored Procedures with Date data types and Oracle

    Overloading a procedure means that you would have two or moe procedures with
    the same name, but different datatypes, and would be declared more than once in
    a package. An example of this would be the Oracle TO_CHAR() function, which can
    take numbers or dates as parameters, and return VARCHAR, etc. If your
    procedures have different names, then they aren't overloaded.

    What happens if you "hard code" some date values like below?

    <cfprocparam type="IN" value="1-JUN-2006" cfsqltype="cf_sql_date">
    <cfprocparam type="IN" value="8-JUN-2006" cfsqltype="cf_sql_date">

    Phil


    paross1 Guest

  17. #16

    Default Re: Stored Procedures with Date data types and Oracle

    <b>As suggested</b>:

    <cfstoredproc datasource="CWMS"
    procedure="cwms.cwms_ts.retrieve_ts"
    debug="yes">

    <cfprocparam type="INOUT" variable="p_units" value="#unit#" <!---p_units--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="MVS" <!---p_officeid--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value=#id.cwms_ts_id# <!---p_timeseries_desc--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="1-JUN-2006" <!---p_start_time--->
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="8-JUN-2006" <!---p_end_time--->
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="US/Central" <!---p_timezone--->
    cfsqltype="cf_sql_varchar">

    <cfprocparam type="IN" value="0" <!---p_trim--->
    cfsqltype="cf_sql_integer">

    <cfprocparam type="IN" value="" <!---p_inclusive--->
    null = "yes"
    cfsqltype="cf_sql_numeric">

    <cfprocparam type="IN" value="" <!---p_versiondate--->
    null="yes"
    cfsqltype="cf_sql_date">

    <cfprocparam type="IN" value="1" <!---p_max_version--->
    cfsqltype="cf_sql_integer">

    <cfprocresult name="ts_dat_ini"> <!---sys_refcursor--->

    </cfstoredproc>
    <b>Yields</b>

    Error Executing Database Query.
    [Macromedia][Oracle JDBC Driver][Oracle]ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'RETRIEVE_TS'
    ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in
    call to 'RETRIEVE_TS' ORA-06550: line 1, column 7: PLS-00306: wrong number or
    types of arguments in call to 'RETRIEVE_TS' ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    The error occurred in /var/apache/htdocs/cf/realtime/api/retrieve_ts_api.cfm:
    line 220

    218 : cfsqltype="cf_sql_integer">
    219 :
    220 : <cfprocresult name="ts_dat_ini"> <!---sys_refcursor--->
    221 :
    222 : </cfstoredproc>




    --------------------------------------------------------------------------------

    SQL {call cwms.cwms_ts.retrieve_ts( (param 1) , (param 2) , (param 3) ,
    (param 4) , (param 5) , (param 6) , (param 7) , (param 8) , (param 9) , (param
    10) )}
    DATASOURCE CWMS
    VENDORERRORCODE 6550
    SQLSTATE HY000





    jasun123 Guest

  18. #17

    Default Re: Stored Procedures with Date data types and Oracle

    Well, you sure got me stumped! I use lots of Oracle stored procedures, in fact
    my Oracle applications use them 100% of the time and I return lots of ref
    cursors, and I've never had this problem! And, I can't duplicate your problem
    either. Funny that the test procedure that you tried back on 5/10 worked OK. I
    must be missing something, but sure as heck don't see it.

    Sorry,
    Phil

    paross1 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139