To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME 11g Central 10g Central 9i Central 8i Central Oracle News Scripts FAQ OCP Zone Resources Database Journal

Go Back   DBAsupport.com Forums > Oracle Forums > Oracle Development

Reply Post New Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-06-2009, 07:12 AM
ram_jetwani ram_jetwani is offline
Junior Member
 
Join Date: Dec 2003
Location: Mehamadabad
Posts: 14
Use Regular Expression to allow specific characters

Hi,
I want to put a validation on a column of a table. The column can have only following characters as a valid character.

0-9, a-z, A-Z, $, *, +, ?, @, °, !, %, &, ', -, /, :, (, ), ., ,, #
if any other characters are used an error is to be returned.

I tried to use regular expression to solve the problem but i am new to it and not able to find a solution.

Please help me out.
__________________
Ramchandra Jetwani
Reply With Quote
  #2  
Old 10-06-2009, 08:50 AM
PAVB's Avatar
PAVB PAVB is offline
Senior Advisor
 
Join Date: Mar 2007
Location: Ft. Lauderdale, FL
Posts: 2,629
Check Constraint looks like the appropriate tool for this job.

Code:
alter YOURTABLE
add CONSTRAINT check_YOURCOLUMN
   CHECK (YOURCOLUMN IN ('0', '1', '2', ... '#'));
__________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Reply With Quote
  #3  
Old 10-06-2009, 10:31 PM
ebrian ebrian is offline
Senior Member
 
Join Date: Apr 2006
Posts: 353
The following is a regex version:

Code:
SQL> create table check_reg (
  2     a1 varchar2(200)
  3     constraint a1_chk check
  4     (regexp_replace(a1, '[''0-9a-zA-Z$*+?@°!%&/:().,#-]') is null));

Table created.

SQL> insert into check_reg values ('_');
insert into check_reg values ('_')
*
ERROR at line 1:
ORA-02290: check constraint (TEST.A1_CHK) violated


SQL> insert into check_reg values ('$');

1 row created.

SQL> insert into check_reg values ('ABCD456:)');

1 row created.

SQL> insert into check_reg values ('''');

1 row created.

SQL>
SQL> select * from check_reg;

A1
---------------------------
$
ABCD456:)
'
Reply With Quote
  #4  
Old 10-07-2009, 04:54 AM
ram_jetwani ram_jetwani is offline
Junior Member
 
Join Date: Dec 2003
Location: Mehamadabad
Posts: 14
Thank you very much. The suggestion solved my problem.
__________________
Ramchandra Jetwani
Reply With Quote
Reply Post New Thread

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is On
Forum Jump


All times are GMT -4. The time now is 10:38 AM.


DBAsupport.com Recent Articles


 » Configuring Oracle as a Data Source for SQL Server

 » When tuning Oracle is not an option

 » Leveraging Logical Standby Databases in Data Guard

 » Building an Oracle Server Environment

 » Oracle 11g Security – Guidelines for Auditing

Search DBAsupport:
 


Click Here to Expand Forum to Full Width











Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.