Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2004
    Posts
    7

    Unanswered: Varchar2 Question

    Somebody told me that when you use varchar2 it's not necessary to specify the size of the string to be displayed.
    ie:
    (CONTENT varchar2);

    It gives me errors so I assume it doesn't work.
    Is there any other way of storing a varchar when you don't know how big the size wil have to be?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    You have to specify the maximum for a VARCHAR2 column. The biggest value allowed is 4000, so you could use VARCHAR2(4000) if you think a value that big is possible.

    If you think even 4000 is too small then you could use CLOB. This allows for up to 4 gigabytes.

    Stick to VARCHAR2 if possible; it's a lot simpler to work with than CLOB.

  3. #3
    Join Date
    Nov 2004
    Posts
    7
    Thanks. I don't want to use up unnecessary space so specifying varchar2 will be a waste of space.
    I may use CLOB. I thought that was called BLOB, or are they both the same thing?

  4. #4
    Join Date
    Jan 2004
    Posts
    492
    You don't want to use CLOB unless its absolutely necessary. Trust me specifying varchar2 is not a waste of space. The only way I would use CLOB is if I had video/pdf...etc files that took up too much space. Stick with Tony's advice.
    Oracle OCPI (Certified Practicing Idiot)

  5. #5
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Yes, you seem to have got the wrong end of the stick!

    If you declare a column as VARCHAR2(4000) and then insert the value 'hat' into it, Oracle only stores 3 characters not 4000. VARCHAR2 is the right way to store text in 99.9% of all cases.

    Only use CLOB if you intend to store something really big in there, like a short story or the small print of an insurance policy perhaps.

    CLOB = Character Large Object (text)
    BLOB = Binary Large Object (pictures, etc.)

  6. #6
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    Dont forget varchar2's only take up the same amount of space as the string you put in. So if you put in a short string say size 10 bytes then the column will take up 10 bytes plus a terminating character. Of course if you put a large string and then update it to a short string there will be wasted space in the row.

    Alan

  7. #7
    Join Date
    Nov 2004
    Posts
    7
    The field might contain an image as well as text (it's optional) so I dunno,I'll see. Thanks for the advice anyway.

Posting Permissions

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