Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Check constraint for hexadecimal values

Re: Check constraint for hexadecimal values

From: Maxim Demenko <mdemenko_at_gmail.com>
Date: Fri, 20 Jul 2007 08:27:02 +0200
Message-ID: <f7pkjj$2bi$03$1@news.t-online.com>


Michel Cadot schrieb:
> <red_valsen_at_yahoo.com> a écrit dans le message de news: 1184882576.408827.91680_at_o61g2000hsh.googlegroups.com...
> | I've attempted to create a check constraint on a column which will
> | contain up to 8 individual hexadecimal values (e.g., "FF1C3D0A", etc.)
> | like so:
> |
> | create table bla(
> | .
> | .
> | column hexvalue char(8)
> | check (hexvalue in ('a-f''A-F''0-9')),
> | .
> | .
> | )
> |
> | -- but the syntax is incorrect. What will work? Do I need a regular
> | expression? Use 'like'?
> |
> | The requirements for check constraints are rather severe, so I'm
> | beginning to doubt that I can do this.
> |
>
> SQL> create table t (
> 2 hexvalue varchar2(8)
> 3 check (to_number(hexvalue,'XXXXXXXX')<to_number('100000000','XXXXXXXXX'))
> 4 )
> 5 /
>
> Table created.
>
> Regards
> Michel Cadot
>
>

Nice approach.
Yet another idea:

SQL> create table t (

   2 hexvalue varchar2(8)
   3 check (length(hextoraw(hexvalue))<=8)    4 )
   5 /

Table created.

Best regards

Maxim Received on Fri Jul 20 2007 - 01:27:02 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US