If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 equivalence to Oracle's varchar2(n char)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-24-10, 02:53
pjbr34 pjbr34 is offline
Registered User
 
Join Date: Aug 2005
Posts: 14
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 ?
Reply With Quote
  #2 (permalink)  
Old 05-24-10, 10:21
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
  #3 (permalink)  
Old 05-24-10, 11:00
pjbr34 pjbr34 is offline
Registered User
 
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)
Reply With Quote
  #4 (permalink)  
Old 05-24-10, 11:02
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
  #5 (permalink)  
Old 05-24-10, 17:10
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Also you can use in any version of DB2:

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

select varchar('abcd', 100)
FROM sysibm.sysdummy1;
Lenny
Reply With Quote
  #6 (permalink)  
Old 05-25-10, 03:43
pjbr34 pjbr34 is offline
Registered User
 
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.
Reply With Quote
  #7 (permalink)  
Old 05-25-10, 11:56
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You can use VARGRAPHIC or DBCLOB for double-byte character strings; the variable length will be understood to be given in double-byte characters.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On