Oracle number datatype

All,
I have a question.
I have a field in a table which is a number data type.
This field is of length '9'.
I have a java front end where if I give the last 4 digits of this field I should be able to pull record that matches.
But when I tested for '0000' I don't have any records pulled. Also when i tested for '0111' it did not take the leading '0' and it went to search for '111' and displayed 2 record that ended with 0111 and 1111.
My problem basically is the leading zeros are neglected.
How do i solve this problem? Please help.

You just need to make sure that the variable type passed from jave is appropriate for the way you use it.
Passing a string variable, as Hoek suggested, it would be something like:
SQL> var strvar varchar2(4);
SQL> exec :strvar := '0000'
PL/SQL procedure successfully completed.
SQL> WITH sample_data AS (
  2     SELECT 20110102345678 id, 324560000 pinnumber, 'AAA' firstname, 'ZZZ' lastname
  3     FROM dual UNION ALL
  4     SELECT 20110102345679, 324560111, 'BBB', 'ZZZ' FROM dual UNION ALL
  5     SELECT 20110102345680, 324561111, 'CCC', 'ZZZ' FROM dual UNION ALL
  6     SELECT 20110102345681, 324561234, 'DDD', 'ZZZ' FROM dual)
  7  SELECT * FROM sample_data
  8  WHERE SUBSTR(TO_CHAR(pinnumber, 'fm999999999'), -4) = :strvar
             ID       PINNUMBER FIR LAS
20110102345678       324560000 AAA ZZZ
SQL> exec :strvar := '0111'
PL/SQL procedure successfully completed.
SQL> /
             ID       PINNUMBER FIR LAS
20110102345679       324560111 BBB ZZZ
SQL> exec :strvar := '1111'
PL/SQL procedure successfully completed.
SQL> /
             ID       PINNUMBER FIR LAS
20110102345680       324561111 CCC ZZZOr, as numeric variable, as Frank suggested, it would be like:
SQL> var numvar number;
SQL> exec :numvar := 0;
PL/SQL procedure successfully completed.
SQL> WITH sample_data AS (
  2     SELECT 20110102345678 id, 324560000 pinnumber, 'AAA' firstname, 'ZZZ' lastname
  3     FROM dual UNION ALL
  4     SELECT 20110102345679, 324560111, 'BBB', 'ZZZ' FROM dual UNION ALL
  5     SELECT 20110102345680, 324561111, 'CCC', 'ZZZ' FROM dual UNION ALL
  6     SELECT 20110102345681, 324561234, 'DDD', 'ZZZ' FROM dual)
  7  SELECT * FROM sample_data
  8  WHERE MOD(pinnumber, 10000) = :numvar;
             ID       PINNUMBER FIR LAS
20110102345680       324561111 CCC ZZZ
SQL> exec :numvar := 0111
PL/SQL procedure successfully completed.
SQL> /
             ID       PINNUMBER FIR LAS
20110102345679       324560111 BBB ZZZ
SQL> exec :numvar := 1111
PL/SQL procedure successfully completed.
SQL> /
             ID       PINNUMBER FIR LAS
20110102345680       324561111 CCC ZZZJohn

Similar Messages

  • Oracle NUMBER column retreived as System.Double instead of System.Decimal

    We've been using the OleDb Managed Provider for some time now, and all oracle NUMBER datatypes have always come back from the db as System.Decimal.
    we recently installed a new database, and now NUMBER comes back as System.Double. The table create scripts are the same for the new db. The client is not the issue as I can point the same web server at the old db and it works fine.
    I've been unable to find any documentation on the subject.

    I have the same problem also. I'm using VC++6.0 and ADO 2.71 to perform queries with an Oracle Client 9.2.0.1. The same query on same table but on different Server version returns different results. With the production server, which is an 8.1.7.4 server, a NUMBER column returns a LONG value, while on the Test server, which is a 9.2.0.5.0 server, the same column returns a DOUBLE value. The problem is that using ADO I don't check data type/size when getting values, but I aspect a LONG value because a created the column with NUMBER specification. Could this be a different default from previous server version when creating the NUMBER column without any SCALE and PRECISION attributes?

  • Understanding number datatype [A help for beginners]

    I would like to share some practical aspects of Oracle Number datatype. Please visit following link.
    http://mamohiuddin.blogspot.com/2007/03/practical-approach-to-understand-oracle.html
    Thank you,
    aijaz

    My only comment would be, since this posting of yours is being made in March 2007, wouldn't it make sense to ensure that it's all correct for the latest version of Oracle (10.2) as 9iR2 is a little "old hat" now. I'm not saying that there is anything wrong with what you've demonstrated, but you only quote it as being compatible with 9iR2 and 10.2 has now been available for a good couple of years.

  • Preceeding Zeros in Number datatype

    Hello all
    Is there any way to store values with preceeding zeros in Oracle Number datatype (eg : person code: 00089034)
    Thanks in advance

    Yes it is possible, by storing it as a varchar2. However I would advice you to store the number as a number, and use a format mask for display:
    SQL> select to_char(89034,'00000009') from dual;
    TO_CHAR(8
    00089034
    1 rij is geselecteerd.Regards,
    Rob.

  • Number datatype

    Hi
    Assume I have 5 digits 2 numbers (as below). I notice that they do not occupy the same space.(First one consumes more storage.)
    What is the reason for this?
    99999
    10000
    Edited by: Pascal Nouma on Aug 15, 2009 6:42 PM

    Justin Cave wrote:
    Oracle, like all programs, stores numbers in binary. It takes more binary bits to store larger numbers than smaller numbers even if they have the same number of decimal digits.Actually, NUMBER datatype is not stored in binary - [Understanding Oracle NUMBER Datatype|https://metalink2.oracle.com/metalink/plsql/f?p=130:14:7587170171678335381::::p14_database_id,p14_docid,p14_show_header,p14_show_help,p14_black_frame,p14_font:NOT,1007641.6,1,1,1,helvetica]. And yes, 99999 and 10000 do not occupy same number of bytes:
    SQL> select dump(99999) from dual;
    DUMP(99999)
    Typ=2 Len=4: 195,10,100,100
    SQL> select dump(10000) from dual;
    DUMP(10000)
    Typ=2 Len=2: 195,2Reason is 10000 is exact value of POWER(100,2). As soon as we, for example, add or subtract 1 space occupied will increase:
    SQL> select dump(10001) from dual;
    DUMP(10001)
    Typ=2 Len=4: 195,2,1,2
    SQL> select dump(9999) from dual;
    DUMP(9999)
    Typ=2 Len=3: 194,100,100
    SQL> As you can see, number with more decimal digits can occupy less space.
    SY.

  • How to convert number datatype to raw datatype for use in data warehouse?

    I am picking up the work of another grad student who assembled the initial data for a data warehouse, mapped out a dimensional dw and then created then initial fact and dimension tables. I am using oracle enterprise 11gR2. The student was new to oracle and used datatypes of NUMBER (without a length - defaulting to number(38) for dimension keys. The dw has 1 fact table and about 20 dimension tables at this point.
    Before refining the dw further, I have to translate all these dimension tables and convert all columns of Number and Number(n) (where n=1-38) to raw datatype with a length. The goal is to compact the size of the dw database significantly. With only a few exceptions every number column is a dimension key or attribute.
    The entire dw db is now sitting in a datapump dmp file. this has to be imported to the db instance and then somehow converted so all occurrences of a number datatype into raw datatypes. BTW, there are other datatypes present such as varchar2 and date.
    I discovered that datapump cannot convert number to raw in an import or export, so the instance tables once loaded using impdp will be the starting point.
    I found there is a utl_raw package delivered with oracle to facilitate using the raw datatype. This has a numbertoraw function. Never used it and am unsure how to incorporate this in the table conversions. I also hope to use OWB capabilities at some point but I have never used it and only know that it has a lot of analytical capabilities. As a preliminary step I have done partial imports and determined the max length of every number column so I can alter the present schema number columns tp be an apporpriate max length for each column in each table.
    Right now I am not sure what the next step is. Any suggestions for the data conversion steps would be appreciated.

    Hi there,
    The post about "Convert Numbers" might help in your case. You might also interested in "Anydata cast" or transformations.
    Thanks,

  • Oracle 8i datatypes in bytes

    Hi,
    If you're able to help, I'm interested in finding out the size (in BYTES) of the following Oracle 8i datatypes:
    BLOB
    DATE
    NUMBER
    NUMBER(10,0)
    FLOAT
    LONG
    VARCHAR2
    Example, for CHAR(size) the number of bytes equal to size.
    Thanking you in advance for your time.
    Regards
    SoR
    null

    Use the SQL function VSIZE.
    SELECT ename, VSIZE (ename) "BYTES"
    FROM emp
    WHERE deptno = 10;
    ENAME BYTES
    CLARK 5
    KING 4
    MILLER 6

  • Using number datatype for date column

    Hi
    Is there a side effect for using "number" datatype for "date" column?
    If so, what is the disadvantage?
    Many thanks

    Hi,
    Ora_83 wrote:
    Hi
    Is there a side effect for using "number" datatype for "date" column?
    If so, what is the disadvantage?Yes, there's a definite disadvantage.
    Oracle provides date arithmetic and a number of functions for manipulating DATEs. None of them work with numbers.
    For example,
    SELECT    TRUNC (order_date, 'MONTH')     AS order_month
    ,       AVG (ship_date - order_date)     AS avg_delay
    FROM       orders
    GROUP BY  TRUNC (order_date, 'MONTH')
    ;order_month involves a DATE function; it's pretty easy to find the month that conatins order_date.
    avg_delay involves date arithmetic. It's extrememly easy to find how much the time passed between order_date and ship_date.
    Depending on how you code dates as numbers, doing either one of the above may be just as easy, but doing the other will be very difficult. You'll waste a lot of effort converting the NUMBERs to real DATEs whenever you need to manipulate them.
    Validation can be very difficult for NUMBERs, also.
    Watch this forum. It's a rare day when there's not some question about how to get around a problem caused by storing dates in a NUMBER (or VARCHAR2) column. Don't add to that. Always use DATE columns for dates.

  • Problem while modifying number datatype.

    Hi All,
    I have modified a column, which is of number datatype.
    Initially it was number(8,2), now I have changed this to Number(10,2).
    But, due to some change in requirement, I have to revese the changes. Now, I am trying to make it Number(8,2), but it is giving me the following error.
    Error report:
    SQL Error: ORA-01440: column to be modified must be empty to decrease precision or scale
    01440. 00000 - "column to be modified must be empty to decrease precision or scale"
    Is there a way to make it?
    Please suggest..
    I am using Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production.
    Thnx in advance..
    Bits..

    You'd have to jump through some hoops to decrease the allowable number of digits in a column. You'd either have to re-create the table, i.e.
    -- Save off the data in FOO
    ALTER TABLE foo
      RENAME TO foo_bkup;
    CREATE TABLE foo (
      -- New column definitions
    INSERT /*+ APPEND */ INTO foo( list_of_columns )
      SELECT list_of_columns
        FROM foo_bkupOr you could create a new column, copy the data, and rename the old column
    ALTER TABLE foo
       ADD( temp_col_name number(8,2) );
    UPDATE foo
       SET temp_col_name = old_col_name;
    ALTER TABLE foo
      DROP COLUMN old_col_name;
    ALTER TABLE foo
      RENAME COLUMN temp_col_name TO old_col_name;Justin

  • Domain of Number datatype

    Hi all,
    Recently i came across one of the most wierd situation across my whole Oracle experience of almost 3 Yrs. I created a table TESTAB (using Oracle 9i) as
    NUMBER_F NUMBER
    NUMBER_PS NUMBER(5,2)
    VARCHAR_F VARCHAR2(10)
    CHAR_F CHAR(10)
    Then i inserted a row as
    Insert into testab values ('0123.23', '099.34','Asim','Ahmed');
    and it accepted the data for Number datatype in single qoutes and automatically parse it for Number datatype.!!!
    SQL> select * from testab;
    NUMBER_F NUMBER_PS VARCHAR_F CHAR_F
    1 3.34
    23 34.34
    2.23 2.33 asim ahmed
    123.23 99.34 Asim Ahmed
    Can somebody explain is that the correct behaviour ! If it is, then i must say it is really shocking behavious for such a mature database like Oracle !
    Asim Ahmed.

    This feature is called 'implicit conversion'
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/03_types.htm#3435

  • Wht is max lenght of number datatype

    Hi all,
    Can any one tell me wht is the max lenght of number datatype in oracle
    9i and 10g
    Regards,

    William, this is amazing! Is is a bug?
    SQL> CREATE TABLE TEST3
      2  AS SELECT 1E45 BGN FROM DUAL
      3  /
    Table created.
    SQL> SET NUMW 50
    SQL> INSERT INTO TEST3 VALUES(1E39);
    1 row created.
    SQL> INSERT INTO TEST3 VALUES(1E50); <--"How it is taken the value more than the precision..."
    1 row created.
    SQL> INSERT INTO TEST3 VALUES(1E48);
    1 row created.
    SQL> SELECT * FROM TEST3;
                                                   BGN
        1000000000000000000000000000000000000000000000
              1000000000000000000000000000000000000000
    1.00000000000000000000000000000000000000000000E+50
    1000000000000000000000000000000000000000000000000
    SQL> SELECT DATA_PRECISION, DATA_SCALE FROM USER_TAB_COLS
      2  WHERE TABLE_NAME='TEST3'
      3  AND   COLUMN_NAME='BGN';
                                        DATA_PRECISION
                                            DATA_SCALE
    "Why these values are not shown ??"

  • Oracle Number and Java Format Mask Issue

    I have a oracle number column, in my view object it is of type BigDecimal and the query column type is NUMBER
    I put the following format mask in the hints section
    #####.00
    with a format type of Number,
    Yet when I run the application, I always get the following error
    java.lang.NumberFormatException: For input string: "-3750.00"
    Anyone any ideas why this does not work?
    Regards
    Orlando

    Hi,
    try with <af:convertNumber>
    See:
    http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_convertNumber.html
    ADF 11.1.1.4.0 af:convertNumber not working with #,##,##,##,##,##,##0.00

  • Trouble using getLong to get an Oracle Number(8,2) field from ResultSet

    I am having trouble using getLong to get an Oracle Number(8,2) field from ResultSet. The error message starts with:
    java.lang.ExceptionInInitializerError: [exception was kaffe.utilNotImplemented] at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(....
    and similar messages when I try getString, getDouble, etc. I am able to getString on the VARCHAR and DATE fields but have not been able to access the NUMBER(8,2) fields.

    java.lang.ExceptionInInitializerError: [exception was
    kaffe.utilNotImplemented] at
    oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(...
    kaffe.utilNotImplemented may be being thrown internally by your JDK.. AFAIK the Kaffe JDK is only JAVA 1.1 compatible and your driver may require JAVA 2.
    Col

  • Oracle Number Precision  format

    Hi,
    I have one doubt regarding Oracle Number format .
    If the Number format is (4,2) ,Its accepting total 5 Bytes.
    But if its 16,6 Its accepting 16 Bytes only . Its able to save numbers in 9,6 or 10,5 . Could you please me know Why it is so.
    Regards
    -

    user8873073 wrote:
    Sorry for the Confusion .
    here are the details .
    Say if the field type is 4,2 , It's accepting 12.34 ( total length 5)
    If the field length is 16,6 , From the above scenario , I am expecting to enter a data of length 17 . But Its possible to enter value of length 16 only.
    On trying to save 1234567890.123456 , its rounding off and displaying as 1234567890.12346 (5 missed) in table.Remember numbers are stored in an internal non-human readable format in Oracle. When you select a numeric
    column in your client it has to convert it to a form you can read. The default format for your client is probably
    rounding the result for you.
    Try using a to_char around the numeric column like to_char(col, '9999999999.999999').
    By the way, the '5' isn't missed in your example, it is simply rounding the .123456 bit to .12346 (rounding to 5 decimal places).
    SQL> create table test_number (
      2  num number(16,6)
      3  );
    Table created
    SQL> insert into test_number
      2  values(1234567890.123456);
    1 row inserted
    SQL> select to_char(num,'9999999999.999999')
      2  from test_number;
    TO_CHAR(NUM,'9999999999.999999
    1234567890.123456
    SQL> select to_char(num,'9999999999.99999')
      2  from test_number;
    TO_CHAR(NUM,'9999999999.99999'
    1234567890.12346Notice the difference in the last example.

  • ORA-600: [kestb_ebv_load-6], [Bad Oracle number] on startup of RAC Instance

    We have Installed Oracle Database 11g R2 Enterprise edition with RAC option.
    today at 1115am instance 2 down abnormally on racnode2 and after that we
    started mannually it is giving error
    Th.
    Fri Apr 13 11:15:53 2012
    Errors in file /oracle/app/oracle/diag/rdbms/nhpcerp/nhpcerp2/incident/incdir_594369/nhpcerp2_o
    ra_18547020_i594369.trc:
    ORA-00308: cannot open archived log '/arch11/2_51023_762112515.arc'
    ORA-27037: unable to obtain file status
    IBM AIX RISC System/6000 Error: 2: No such file or directory
    Additional information: 3
    ORA-00600: internal error code, arguments: [kestb_ebv_load-6], [Bad Oracle number], [], [], [],
    Errors in file /oracle/app/oracle/diag/rdbms/nhpcerp/nhpcerp2/trace/nhpcerp2_ora_18547020.trc:
    ORA-00600: internal error code, arguments: [kestb_ebv_load-6], [Bad Oracle number], [], [], [],
    Errors in file /oracle/app/oracle/diag/rdbms/nhpcerp/nhpcerp2/trace/nhpcerp2_ora_18547020.trc:
    ORA-00600: internal error code, arguments: [kestb_ebv_load-6], [Bad Oracle number], [], [], [],
    Error 600 happened during db open, shutting down database
    USER (ospid: 18547020): terminating the instance due to error 600
    Instance terminated by USER, pid = 18547020
    ORA-1092 signalled during: ALTER DATABASE OPEN...
    opiodr aborting process unknown ospid (18547020) as a result of ORA-1092
    Fri Apr 13 11:15:55 2012
    ORA-1092 : opitsk aborting process
    message after starting mannually
    $
    $ hostname
    racnode2
    $
    $ srvctl start instance -d nhpcerp -i nhpcerp2
    PRCR-1013 : Failed to start resource ora.nhpcerp.db
    PRCR-1064 : Failed to start resource ora.nhpcerp.db on node racnode2
    ORA-01092: ORACLE instance terminated. Disconnection forced
    ORA-00600: internal error code, arguments: [kestb_ebv_load-6], [Bad Oracle number]
    Process ID: 18940646
    Any help would be highly appreciated.

    Start here:
    ORA-00308: cannot open archived log '/arch11/2_51023_762112515.arc'
    ORA-27037: unable to obtain file status
    IBM AIX RISC System/6000 Error: 2: No such file or directory

Maybe you are looking for

  • As of late, my COMPUTER has been shutting down Randomly.....

    Ok here is what is happening. I am on the compuer, and all of a sudden the whole screen goes black and the computer sort of shuts down. but not completely. i can't see anything or do anything, but when i hold down the power buttton and push it, after

  • RRI Jump Target Issue, IMP

    How do I jump from one query to another with a set of values. I want a query to run for a set of all customers for a specific customer group from 0cust_sales. I tried both options using InfoObject and Variable and different options in selection type(

  • Java and PDA's

    Hi everybody, I'm thinking about purchasing a PDA and would like to develop my own apps for it with Java. What are the requirements are for running Java on any PDA? What OS's support Java? How do I get Java onto a PDA? Which PDA's support Java? As yo

  • Excise value are not pick

    hi experts hi i have a problem  while doing billing document against sales order and outbound delievery excise values are not pick by the system.but in the sales order it is showing . please help to resolve this issue ..

  • Poor gigabit performance, how do I improve it?

    Hello, I have a 1st generation 2x2Ghz power mac g5, and I'm trying to build a gigabit network with some PCs and a brand new MacBookPro (what a laptop!). Although the gigabit network is up and running (and either the laptop or the g5's ifconfigs say s