We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,617 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

VARCHAR contains only characters: how to do ?

Hello people,

I declared a field in my table : my_field VARCHAR(20), but I don't want it to contain any number: can you tell me how I can do that using a trigger or using a constraint ?

Thank you in advance for any help

3
Contributors
4
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
begueradj
Junior Poster in Training
70 posts since Mar 2007
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 0

The easiest way is to control this by the application that will be inserting and/or updating the column.
ie. Oracle Forms???

A more difficult way (but not too difficult) is to use a Before Insert trigger.
Loop through your digits (0..9)
and do an InStr() on your input string, checking for your digits.
Fail the trigger if you find any numbers.

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
Skill Endorsements: 1

The easiest way is to control this by the application that will be inserting and/or updating the column.
ie. Oracle Forms???

A more difficult way (but not too difficult) is to use a Before Insert trigger.
Loop through your digits (0..9)
and do an InStr() on your input string, checking for your digits.
Fail the trigger if you find any numbers.

Thank you very much for your help, I used the trigger as you advised me

begueradj
Junior Poster in Training
70 posts since Mar 2007
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 0

Please mark this thread as "solved".
Thank-You!

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
Skill Endorsements: 1
Question Answered as of 1 Year Ago by hfx642

Or you can put a constraint on the field to restrict the input. In your case, you'd check if the input contains numbers, if yes. then it won't be inserted.

ALTER TABLE TableName ADD CONSTRAINT ConstraintName CHECK(YourField........  )

Instead of the dots up there, you replace them with a function or something that checks if the input is CHAR or is not INT.

rotten69
Master Poster
747 posts since May 2011
Reputation Points: 36
Solved Threads: 47
Skill Endorsements: 13

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.5330 seconds using 2.66MB