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 > how to make DB2 as case in sensitive?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-07, 06:17
sunsanvin sunsanvin is offline
Registered User
 
Join Date: Nov 2006
Posts: 13
how to make DB2 as case in sensitive?

Dear Friends,

by default DB2 is case sensitive? or case-in-sensitive?

how to make DB2 as case-in-sensitive?

that means, while retrieving data, it should identify 'Ind' , 'IND' , 'ind' as same...........like this

how can i make this collation?


thanks in advance
Reply With Quote
  #2 (permalink)  
Old 03-30-07, 08:04
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The data in DB2 is case sensitive. If you want select columns to be "case insensitive", I suggest that you create the table with this column to have another column that is derived from the first column and is either lcase or ucase of that column. Then you always do you queries against the derive column. For example:

Instead of:

create table cust (c_id int, name varchar(50))

select * from cust where lcase(name) = lcase('Jones')

you would have:

create table cust (c_id int, name varchar(50), l_name varchar(50))

create trigger BITRIG_cust NO CASCADE BEFORE INSERT ON cust
REFERENCING NEW as newdata FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
SET newdata.l_NAME = lCASE(newdata.NAME);
END

select c_id,name from cust where l_name = 'jones'

This way you can put indexes on the column l_name and get a performance boost.

HTH

Andy
Reply With Quote
  #3 (permalink)  
Old 03-30-07, 12:45
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
sunsanvin,

You might have already noticed in this forum that the first input we would expect is the Environment details (platform,version...). No matter how simple the query is. Please give us this details.

Coming to Andy's solution, and assuming DB2 on Z/os. (for point 1 )

1.>
This may not work when LOAD utility is run with SHRLEVEL NONE.
Triggers are not activated when data is loaded using LOAD SHRLEVEL NONE.

2.> Data may not be consistent in the Derived Column.
I think we may need UPDATE trigger as well. Consider the situation,
A row is inserted and some time later it was updated to something else. An update trigger would be needed to put the derived column is sync with the actual column, If at all the table/column is updatable as per the functionality.
I'm not saying Andy missed this point, I just wanted to consider this situation.

3.> I'm not sure about the REORG utility. I think it would also depend on the SHRLEVEL parameter. Not sure though..!
__________________
Vinay,
Reply With Quote
  #4 (permalink)  
Old 03-30-07, 13:28
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Actually, I was assuming DB2 for LUW. And yes, there is a need for a BEFORE UPDATE trigger. I was just giving an example.

Andy
Reply With Quote
  #5 (permalink)  
Old 03-30-07, 13:31
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
To use Andy's fundamental approach and address Vinay's concerns, you can define l_name as

l_name varchar(50) GENERATED ALWAYS AS lcase(name)

When inserting/updaing data (and IMPORTing) the l_name is generated automatically.

If you are LOADing, following the load you will have to use SET INTEGRIY statement

REORG should have no specific impact here

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #6 (permalink)  
Old 04-02-07, 00:36
sunsanvin sunsanvin is offline
Registered User
 
Join Date: Nov 2006
Posts: 13
is there no other way to make the complete database as case in sensitive?
instead of using this lcase function regularly?
Reply With Quote
  #7 (permalink)  
Old 04-02-07, 08:05
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
No, not in DB2. SQL is a case-sensitive language - as are many other programming languages - and you have to say explicitly when to do case-insensitive comparisons.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 04-03-07, 04:38
sunsanvin sunsanvin is offline
Registered User
 
Join Date: Nov 2006
Posts: 13
Dear Friends,
the given solution by is an excellent one. I got much confidence that we can easily start migration in DB2. is it possible to do the same thing in oracle? if so, can you please give me the syntax and related functions?

thank you very much
Reply With Quote
  #9 (permalink)  
Old 04-03-07, 04:45
vini_srcna vini_srcna is offline
Registered User
 
Join Date: May 2006
Posts: 82
You may get very few answers here.
(sometimes wrong answers too for Oracle - )

Please try @ http://www.dbforums.com/oracle/

This is the only link i'm aware of -
__________________
Vinay,
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