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 > Data Access, Manipulation & Batch Languages > ANSI SQL > constraint creation problems

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-28-03, 14:40
f_sly f_sly is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
constraint creation problems

I'm trying to add a constraint that will check the firt letter of a VARCHAR type to make sure its first letter is a letter not a number and second to make sure it is in uppercase but I haven't the faintest idea how to do it.

Does sqlplus support character indexind, in wich case I could probably do something like?:

AttributeName(1) BETWEEN 'A' AND 'Z'...

Or do I have to create a domain and check if the forst character of the varchar is in the domain?

And how do I select only the first character for my checking purposes?

Any reply will be greatly appreciated!
Reply With Quote
  #2 (permalink)  
Old 10-28-03, 15:26
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Lightbulb

Try this (In Oracle):

alter table MyTable
add constraint chk_UPPER1
check(nvl(substr(AttributeName,1,1),'?') between 'A' and 'Z');

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 10-28-03, 16:14
f_sly f_sly is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Quote:
Originally posted by LKBrwn_DBA
Try this (In Oracle):

alter table MyTable
add constraint chk_UPPER1
check(nvl(substr(AttributeName,1,1),'?') between 'A' and 'Z');

Thanks a bunch!

Since I'm creating the table can do this?

CREATE tableName
(AttributeName varchar(8) not null,
CONSTRAINT chk_upper1
check(nvl(substr(AttributeName,1,1),'?') between 'A' and 'Z')
)

P.S. I'm not sure if the nvl will work in oracle8 its sqlplus... Than I suppose that I can do it with decode...

Thanks again!
Reply With Quote
  #4 (permalink)  
Old 10-29-03, 11:10
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Exclamation

Yes, NVL will work in Oracle8 and yes you can define the constraint in the 'create table'

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 10-29-03, 11:28
f_sly f_sly is offline
Registered User
 
Join Date: Oct 2003
Posts: 4
Thumbs up

Quote:
Originally posted by LKBrwn_DBA
Yes, NVL will work in Oracle8 and yes you can define the constraint in the 'create table'

Thanks!
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