Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2005
    Posts
    14

    Unanswered: DB2 equivalence to Oracle's varchar2(n char)

    Hi list,
    We are trying to find a DB2 way to implement the Oracle definition of

    varchar2 (n char)

    which stores n chars instead of n bytes.

    How can we do this in DB2 ?

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    If you have DB2 9.7 you can also use VARCHAR2
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Aug 2005
    Posts
    14
    Yes, but does it work the very same way?
    does it do the same?


    a definition like:

    varchar2(n)

    should behave different than

    varchar2(n char)

  4. #4
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Sorry, don't know about that.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  5. #5
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    Also you can use in any version of DB2:

    select cast('abcd' as varchar(100))
    FROM sysibm.sysdummy1;

    select varchar('abcd', 100)
    FROM sysibm.sysdummy1;
    Lenny

  6. #6
    Join Date
    Aug 2005
    Posts
    14
    Yes but I am defining a Data Type.
    What I want to achieve is to define a variable that contains n characters, not n bytes.

    In Oracle this is defined as

    myvar varchar2(2 char) ---> myvar will contain 2 CHARACTERS
    myvar varchar2(2) ---> myvar will contain 2 BYTES

    But that's in Oracle.

    Now that DB2 9.7 is "oracle compatible", I wanted to know if there was some construct or definition that works the same way since the definition

    myvar varchar2(2 char)

    is not accepted in DB2 9.7.

  7. #7
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    You can use VARGRAPHIC or DBCLOB for double-byte character strings; the variable length will be understood to be given in double-byte characters.

Posting Permissions

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