Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 7th, 2004, 07:23 PM
jarednielsen jarednielsen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 jarednielsen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Postal Code Constraint

Hey everyone!

I'm currently working on a project for school, and I can't wrap my brain around one of the constraints for our Canadian postal code. It's alpha numeric for those who don't know, and it looks like T1W1W1. I am not exactly sure how to do a check on this to ensure that it's in that format.

Any insight is greatly appreciated.

Thanks!

Jared

Reply With Quote
  #2  
Old September 8th, 2004, 08:59 AM
Sasi242 Sasi242 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 9 Sasi242 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 22 sec
Reputation Power: 0
Hi Jarednielsen
Check this

Assuming The Postal Codes Exists Between t1w1v1-t9w9v9.
SQL> ed
Wrote file afiedt.buf

1* create table a(code varchar2(10) check(code>='t1w1v1' and code<='t9w9v9'))
SQL> /

Table created.

SQL> insert into table a('&code');
Enter value for code: a
old 1: insert into table a('&code')
new 1: insert into table a('a')
insert into table a('a')
*
ERROR at line 1:
ORA-00903: invalid table name


SQL> ed
Wrote file afiedt.buf

1* insert into table a values('&code')
SQL> /
Enter value for code: t1w1v1
old 1: insert into table a values('&code')
new 1: insert into table a values('t1w1v1')
insert into table a values('t1w1v1')
*
ERROR at line 1:
ORA-00903: invalid table name


SQL> ed
Wrote file afiedt.buf

1* insert into a values('&code')
SQL> /
Enter value for code: t1w1v1
old 1: insert into a values('&code')
new 1: insert into a values('t1w1v1')

1 row created.

SQL> /
Enter value for code: t2w3v3
old 1: insert into a values('&code')
new 1: insert into a values('t2w3v3')

1 row created.

SQL> /
Enter value for code: a1w2v3
old 1: insert into a values('&code')
new 1: insert into a values('a1w2v3')
insert into a values('a1w2v3')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.SYS_C003034) violated


SQL> /
Enter value for code: t1v6w3
old 1: insert into a values('&code')
new 1: insert into a values('t1v6w3')
insert into a values('t1v6w3')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.SYS_C003034) violated


SQL> /
Enter value for code: t2w2v6
old 1: insert into a values('&code')
new 1: insert into a values('t2w2v6')

1 row created.

so when ever we try to violate the series of "TWV" it will not accept.
Hope This Is Helpful,If Not Pls Get Back With An Example.
Happy Coding
sasidharis@yahoo.com

Reply With Quote
  #3  
Old September 8th, 2004, 09:33 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Do you wnat to only insert the canadian postal code or american also?? If only canadian then follwoing code might be useful for you, this code checks the total lenght of the postal code that should be siz and the sorting order of latter, like first letter should be character, second numeric, third character,fourth numeric, fifth character, and sixth numeric.
CREATE TABLE postal_codes
(postal_code varchar2(6)
check ('X9X9X9'=translate(postal_code,'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'9999999999XXXXXXXXXXXXXXXXXXXXXXXXX'))
)
/
new add the postal code you wnat, for example my postal code is K1V9S2.

insert into postal_codes('K1V9S2')
/
1 row created.

now I am trying to add some faulty data, for example 'K1V' and 'K1VB2G'

insert into postal_codes('K1VB2G') -- format does not match
/
error will be occured

insert into postal_codes('K1V') -- shorten of length
/
error will be occured


Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Postal Code Constraint


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway