Is it better to use NUMBER or VARCHAR2 performance wise?

Hi,
maybe it's a silly question,
but if i want to save a numeric code in my table is it better to use NUMBER or VARCHAR2, the code will never be use in any calculation.
I'm asking this because i have an idea that is to use NUMBER for a column type only when that value will be used in mathmatic calculations of some sort, if it's not going to be used in calculation i use VARCHAR2.
But other than my choice I've been wondering what is the best choice considering performance.
Can you help?
Best regards

Sentinel wrote:
Unless you need to preserve leading zeros, the number data type is the most appropriate data type to use for numeric data.I have to disagree I'm afraid.
"Leading zeros" is a display issue and should not determine how you store your data on the database. If you need to display leading zeros, then that should be done at the front-end. You can't determine future requirements against the data (businesses change their minds) so you will give yourself problems of updating your data if you find the business decides that another area should display it with e.g. another 2 leading zeros or they don't want leading zeros etc. Never store numbers as varchar for display purposes.
It's quite simple, if you are dealing with numbers, store them as numbers, if you are dealing with varchars store them as varchars, if you are dealing with dates and times, store them as date etc.
As for performance, there is no noticable difference between the datatypes... it's all Binary data when you get down to machine code level.
If you store numbers as varchar you could end up with other issues, apart from possible problems in calculations...
Comparisons against numbers stored as varchar are notoriously problematic...
SQL> select 'TRUE' from dual where '150' > '1000';
'TRU
TRUE
SQL> select 'TRUE' from dual where '150' < '1000';
no rows selected
SQL>... and then the developer wonders why the data isn't being returned. ;)

Similar Messages

  • How can we say if Join better than using Sub Queries ??

    Hi all,
    I am trying to understand the rationale behind "Is _Inner Join_ better than using _Sub Query_ ?" for this scenario ...
    I have these tables --
    Table1 { *t1_Col_1* (PrimaryKey), t1_Col_2, t1_Col_3, t1_Col_4 }
    -- Number of rows = ~4Million , t1_Col_3 has say 60% entries non-zero -----> (Condition 4)
    Table2 { *t2_Col_1* (PK), t2_Col_2, t2_Col_3 }
    -- Number of rows = ~150Million, t2_Col_2 maps to t1_Col_1 -----> (Condition 1). This means for every distinct value of t1_Col_1 (its PK) we'll have multiple rows in Table2.
    Table3 { *t3_Col_1* (PK), t3_Col_2, t3_Col_3 }
    -- Number of rows = ~50K, t3_Col_1 maps to t1_Col_2 -----> (Condition 2)
    Table4 { *t4_Col_1* (PK), t4_Col_2, t4_Col_3 }
    -- Number of rows = ~1K, t4_Col_2 maps to t3_Col_2 -----> (Condition 3)
    Now here are the 2 queries: -
    Query using direct join --
    SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
    FROM Table1, Table2, Table3, Table4
    WHERE t1_Col_1=t2_Col_2 -- Condition 1
    AND t1_Col_2=t3_Col_1 -- Condition 2
    AND t3_Col_2=t4_Col_1 -- Condition 3
    AND t1_Col_3 != 0
    Query using SubQuery --
    SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
    FROM Table2,
    (SELECT t1_Col_1, t3_Col_1, t4_Col_2
    FROM Table1,Table3, Table4
    WHERE
    AND t1_Col_2=t3_Col_1 -- Condition 2
    AND t3_Col_2=t4_Col_1 -- Condition 3
    AND t1_Col_3!= 0
    WHERE t1_Col_1=t2_Col_2 -- Condition 1
    Now the golden question is - How can I document with evidence that Type-1 is better than Type-2 or the other way ? I think the 3 things in comparison are: -
    - Number of rows accessed (Type-1 better ?)
    - Memory/Bytes used (Again Type-1 better ?)
    - Cost ( ?? )
    (PS - testing on both MySQL, Oracle10g)
    Thanks,
    A

    So, is it right to conclude that Optimizer uses the optimal path and then processes the query resulting in nearly the same query execution time ?If the optimizer transforms two queries so that they end up the same, then they will run in the same time. Of course, sometimes it cannot do so because of the the way the data is defined (nulls are often a factor; constraints can help it) or the way the query is written, and sometimes it misses a possible optimization due to inaccurate statistics or other information not available to it, or limitations of the optimizer itself.
    Is this the right place to ask for MySQL optimization ?Probably not.

  • My question is which better to use every time my iPad until the battery is 0% then charge it to 100% then use it again until it is 0% or i use it until the percentage is low then charge it until it is 70 - 80 %  then use it but not let it charge to 100%

    My question is which better to use every time my iPad until the battery is 0% then charge it to 100% then use it again until it is 0% or i use it until the percentage is low then charge it until it is 70 - 80 % percentage then use it but not let it charge until it is 100% to reduce the number of circles and increase the life of battery as i read that it must at least one time a month use the device until the battery drain to 0% then charge it again to 100% but i don't understand is it must be one, two, three times a month or properly most of the times  to reduce the the number of circles and increase the life of the battery?

    wuzradioman,
    I was originally on your side in the discussion of batteries, however, after being contradicted by Meg St._Clair and others I took a leap of faith and took their advice with my Apple devices.  Much to my chagrin their advice has proven true.
    Long story short I have not noticed any differences in my battery life by changing my charging habits to what is convienant over what is more in line with conventional battery myths. 

  • Conversion/Type Cast of sys.XMLType to NUMBER and VARCHAR2

    How do we typecast or convert a variable of the type sys.XMLType to NUMBER and VARCHAR2?
    For e.g. I have a variable :-
    v_STATE sys.XMLType
    I want to convert it to either of the type NUMBER or VARCHAR2.

    How do we typecast or convert a variable of the type sys.XMLType to NUMBER and VARCHAR2?
    Your question is too vague to give a relevant answer.
    Typecasting doesn't make sense in this situation, XMLType is an opaque datatype, it's not like converting VARCHAR2 to NUMBER (or vice versa).
    Do you mean serializing the XML document, or extracting atomic node values, or something else ?
    Depending on your requirement, you may want to look for XMLSerialize() or XMLCast() functions.
    And on a side note, don't always expect people to search for your previous threads to find some useful information, such as a db version...

  • Using number as bind varilable in PLSQL block

    Hello, I need to use number for below bind variable. How can i achieve this? I am not in the situation that i can not use apha numeric vailable.
    Any help is appreciated.
    SQL> set serveroutput on
    SQL> declare
    2 var 1 varchar2(20);
    3 var 2 varchar2(20);
    4 exec :1 := 100
    5 exec :2 := 200
    6 begin
    7 select count(*) into v_cnt from temptable where no = :1 or no = :2;
    8 dbms_output.put_line(v_cnt);
    9 end;
    10 /
    SP2-0552: Bind variable "2" not declared.
    SQL>

    >
    Hello, I need to use number for below bind variable. How can i achieve this? I am not in the situation that i can not use apha numeric vailable.
    >
    I have no idea what you are saying. You say you 'need to use number' but hen say that you 'can not use apha numeric'. That doesn't make any sense.
    You only wrote 11 lines altogether and only half of them are correct.
    SQL> set serveroutput on
    SQL> declare
    2 var 1 varchar2(20);
    3 var 2 varchar2(20);
    4 exec :1 := 100
    5 exec :2 := 200
    6 begin
    7 select count(*) into v_cnt from temptable where no = :1 or no = :2;
    8 dbms_output.put_line(v_cnt);
    9 end;
    10 /#2 and #3 are wrong for two reasons. First because you put them AFTER the declare and you need to put them before it. They are sql*plus declarations. Second because var names cannot begin with a number.
    #4 and #5 are wrong for two reasons. First the assignments need to go AFTER the BEGIN statement. Second you dont' use 'exec' you just assign the value.
    #7 is wrong because you never declare 'v_cnt' any where.
    If you correct ALL of the above it should work. Don't have your table so can't test.
    set serveroutput on
    var a varchar2(20);
    var b varchar2(20);
    declare
    v_cnt number;
    begin
    :a := 100;
    :b := 200;
    select count(*) into v_cnt from temptable where no = :a or no = :b;
    dbms_output.put_line(v_cnt);
    end;
    /

  • Text size, better to use px or em?

    For text sizing, is it better to use px or em? And what are
    the advantages to one/both?
    thanks
    james

    You cannot begin a custom class with a number.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "jameswoody" <[email protected]> wrote in
    message
    news:g2c5kq$5h4$[email protected]..
    > I've made the following in Dreamweaver. In dreamweaver
    it displays as you
    > said,
    > where 50% text in a 50% div shows at 25%. In Safari and
    Firefox however,
    > it all
    > displays as the same size. Am I doing something wrong?
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN"
    > "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="
    http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    charset=UTF-8" />
    > <title>Untitled Document</title>
    > <style type="text/css">
    > <!--
    > .1 {
    > font-size: 50%;
    > }
    > .2 {
    > font-size: 50%;
    > background-color: #007700;
    > }
    > -->
    > </style>
    > </head>
    >
    > <body>
    > <div class="text">text is normal size</div>
    > <div class="1">
    > <p>text is 50%</p>
    > <div class="2">text is 50% in 50%</div>
    > </div>
    > </body>
    > </html>
    >
    >
    >

  • What is better to use and why?

    Hi,
    What is better to use and why?
    We have written follwing statements to check the existence of interested record in table.
    1).
    select count(*) from emp where deptno = 20;
    2).
    select 'X'
    from dual
    where exists (
    select 'X' from emp
    where deptno = 20);
    Thanks and Regards,
    Rushang Kansara

    Assuming a large table, number two would be the fastest. If empno in unique, you can leave out the where exists part and just select x from emp where empno = 20. If empno is not unique, then using where exists can be faster. Assuming that empno is not unique, query 1 may elect to scan the whole table looking for that empno. Number 2 can use the index and return your result in, typically, three LIOs.
    Again, it all depends on your indexing, size of tables, and uniqueness of key upon which you are searching.

  • 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.

  • Hql how to cast number to varchar2

    Hello.
    How to cast number to varchar2(to string)? I'm using hql toplink implementation and (don't know why) functions like cast(... as ...), to_char(...) and str(...) don't work. Please help me.
    Kuba :).
    Edited by: 854998 on 2011-04-27 03:12

    Hello Chris.
    First of all I'd like to thank you for answer. :)
    1)I can't use native query.
    2)What do you mean?
    3)I can't upgrade.
    I have something like this(it's only simple example, I have more complex query):
    getManager().createQuery("SELECT obj FROM " + EntityClass.class.getSimpleName() + " obj "
                        + " WHERE '14' = obj.number").getResultList();
    r.number is Number in Oracle and Long in entity class.
    I want to cast obj.number to String.
    Here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-expressions expressions like cast is valid.
    So, where's the problem? My toplink version is too old?
    Thanks a lot
    Kuba.

  • My firefox beta 12 using Linux platform does not update to firefox RC1 via the "check for update" function. I know windows' beta version had this fixed, when would Linux get similar support ?

    Current platform : Linux
    Current firefox version : Firefox 4 beta 12
    Issue : does not update to RC 1 using the check for update feature.
    Background : previously downloaded beta 8 and then it automatically updated to beta 12 using update features but for RC1, it does not.
    I know users under Windows platform had same problem but was resolved and they can now update via check for update feature.
    Please implement for Linux users too.
    Thanks !!

    If you can't update then you can download and install the full Firefox 4 RC version.
    * http://www.mozilla.com/firefox/all-beta.html

  • HT1443 I need to upgrade from 10.5.8 to 6.0 or better to use a new HP wireless printer.  How do I find the right item to download?

    I need to upgrade from 10.5.8 to 6.0 or better to use a new HP wireless printer.  How do I find the right item to download?

    There is no download; you need to buy a Mac OS X 10.6 DVD.
    (83218)

  • I Mini with an i7 processor. I would like to use Boot Camp to install windows based CAD software on my MAC. Would it be better to use a plugin external hard drive to load my software on and if so what hard drive would you recommend?

    I Mini with an i7 processor. I would like to use Boot Camp to install windows based CAD software on my MAC. Would it be better to use a plugin external hard drive to load my software on and if so what hard drive would you recommend?

    Thank you for your quick response. I can then use a ZIP drive for data storage. I want to keep as much of my hard drive free of data as possible.

  • I have a Mac pro(1 free bay) and a mac mini I need to back both of them  Is it better to use an external NAS HD or an internal hard drive on my mac pro (mid 2010) What option has the faster GB/s?

    I have a Mac pro(1 free bay) and a mac mini I need to back up both of them (time machine)  Is it better to use an external NAS HD or an internal hard drive on my mac pro (mid 2010)
    What option has the faster GB/s?

    Disk drive using native SATA bus interface will allow the drive to copy and always present and ready.
    But once you have backup any hourly changes should be smaller and as long as the NAS and your switch should allow enough.
    You should always have off line backups and don't rely on just one backup set or just TimeMachine.
    WD RED models are designed for RAID and NAS and 7.2k instead of your more standard slower green 5400 rpm green models while still costing less than WD Blacks.
    http://www.amazon.com/gp/product/B008JJLW4M/
    How to clone your system:
    http://macperformanceguide.com/Mac-HowToClone-backup.html
    http://macperformanceguide.com/Mac-HowToClone.html
    http://www.macupdate.com/app/mac/7032/carbon-copy-cloner
    Using Cloning as a Backup Strategy
    http://www.macupdate.com/app/mac/7032/carbon-copy-cloner
    http://www.bombich.com/software/updates/ccc-3.5.html
    Clone to internal, TimeMachine to NAS is one way to go at it.

  • Which one better to use - jsp:useBean or import statement

    Hi,
    I just want to know that which one is better to use jsp:useBean or import statement .
    I can instantiate and call method of myclass -
    1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
    2). by using <jsp:useBean tag....
    i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
    so what should i used , which one is better and why?
    useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
    but which tag should i use in my jsp?
    i am confused???

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Which is better to use in a corprate enviornment for back up Windows 2008 Vs. Mozy

    Which is better to use in a corprate enviornment for back up Windows 2008 Vs. Mozy

    Hi, 
    Microsoft provide the built-in backup utility Windows Server Backup to backup Windows server 2008. For more detailed information, please refer to the articles below:
    Windows Server Backup Step-by-Step Guide for Windows Server 2008
    http://technet.microsoft.com/en-us/library/cc770266(v=ws.10).aspx
    Save big bucks without risk: Get the most from Windows Server 2008 Backup Utility
    http://www.techrepublic.com/blog/data-center/save-big-bucks-without-risk-get-the-most-from-windows-server-2008-backup-utility/
    Please Note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    For Microsoft does not provide any third party software, you need to check with the third party software yourself.
    Regards,
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

Maybe you are looking for