Problem with Passing Integers to Oracle StoredProcedures

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

  1. #1

    Default Problem with Passing Integers to Oracle StoredProcedures

    I've been working with Oracle Stored procedures for a short time and have run
    into a glitch
    when working with data types of integer. I have a form that I use to collect
    data from users
    to add/edit records in an Oracle table. The form has a text field that
    validates the data as integer.
    When the form is submitted, I use a cfstoredprocedure call with cfparam type
    cf_sql_integer to
    pass the integer value to the Oracle stored procedure. If the number entered
    into the text field
    on the form is strictly numeric, ie. 1200 the data is okay. If the user
    enters a number with a
    comma in it, ie. 1,200 (which will not raise a validation error on type
    integer) the number
    that ends up in the Oracle field is incorrect. It usually ends up being a
    large negative number.





    stlaw Guest

  2. Similar Questions and Discussions

    1. Passing boolean parameters to Oracle
      Hello there everyone. I have just started to work with Oracle stored procedures. I have written a procedure that takes a boolean value as one of...
    2. Converting integers to datetime
      I have the following fields in a database: year integer(4) not null default '0' month integer(2) not null default '0' day ...
    3. Display integers in CFChart
      :| The Yaxis which is passed an integer is displaying decimal numbers. How do I disable the decimal numbers in CFChart ? <!DOCTYPE HTML PUBLIC...
    4. Consume RPC/Encoded webservice from ASP.NET double,integers,boolean problem
      After many hours of searching I cannot find the answer why I cannot consume a webservice method from a Apache/Java RPC/Encoded webservice from...
    5. #23668 [Opn->Fbk]: oracle<defunct> problem apache2+php+oracle
      ID: 23668 Updated by: sniper@php.net Reported By: thecluster at argentina dot com -Status: Open +Status: ...
  3. #2

    Default Re: Problem with Passing Integers to Oracle StoredProcedures

    How are you validating that your input is numeric? If I use the IsNumeric()
    function, I get a NO for something like IsNumeric("1,234") but a YES for
    IsNumeric("1234"). Are you using CFFORM? You will probably need to either
    perform further tests on the input and reject values that contain non-numeric
    characters, or remove them yourself by parsing the string and removing anything
    that isn't a number.

    Phil

    paross1 Guest

  4. #3

    Default Re: Problem with Passing Integers to Oracle StoredProcedures

    Phil,
    Thanks for your reply. I'm using a cfform with a cfinput type="text,
    validate="integer", validateat="onblur, onserver". Validation as a whole
    doesn't appear to be working well for me. On some cfinputs it doesn't perform
    the validation at all, even though I copied and pasted the validate="integer"
    and validateat="onblur" from a field where it does work. For the fields that
    it does work on, it appears that the non-numeric characters of plus, minus, and
    comma will pass validation for integer. You can put any of these characters
    anywhere (12,+34,56) and it will pass validation. If you put a decimal or any
    other character or symbol in the input, it will fail validation. This must be
    a bug. Unfortunately the lesson learned is that I can't rely on CFForm
    validation. :brokenheart;

    stlaw Guest

  5. #4

    Default Re: Problem with Passing Integers to Oracle StoredProcedures

    Since you are using stored procedures, you could even do the validation in the
    PL/SQL itself. You would need to change your parameters to VARCHAR2 instead of
    NUMBER, and probably have an OUT parameter as a procedure status, so that if
    the "integer" parameter that was passed to the procedure ended up being
    non-numeric, your ColdFusion code could evaluate the status parameter and act
    accordingly. In other words, you do have options. One thing about making all of
    your stored procedure parameters VARCHAR2 is that you avoid type mismatch
    errors, and you can control how you want to handle bad data within your
    procedure, which can be a good idea, especially if you plan on calling these
    procedures from other front ends, etc. (For example, I pass all of my date
    values as VARCHAR2, which has saved me tons of problems as we have migrated
    through various versions of ColdFusion and Oracle. I do the conversions in the
    procedure, if necessary, and handle any exceptions accordingly.)

    Just something to think about.

    Phil

    paross1 Guest

  6. #5

    Default Re: Problem with Passing Integers to Oracle StoredProcedures

    Phil,

    I was actually planning on doing the validation on the Oracle side and using
    replace to strip the commas out, but I've found an even better solution. If I
    change my cfparam to cf_sql_varchar instead of cf_sql_integer and in the oracle
    stored procedure map the data type to the field in the oracle table instead of
    using type number, it works like a charm. I've used data type mapping for
    dates which works really well, but I hadn't thought about it for numbers. To
    map a data type in an Oracle stored procedure you use the following coding
    parameter1 in tablename.fieldname%type

    Thanks again for your suggestions.

    Theresa

    stlaw Guest

  7. #6

    Default Re: Problem with Passing Integers to Oracle StoredProcedures

    I almost always use type mapping, as it saves you a LOT of work if you ever have to alter a column in the database, etc., especially for local variables in your procedure.

    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