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: CUSTOM data integrity constraint

Re: CUSTOM data integrity constraint

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 25 Aug 1999 11:51:00 GMT
Message-ID: <37c5d883.2598576@newshost.us.oracle.com>


A copy of this was sent to Nandakumar <N.Kumar_at_rocketmail.com> (if that email address didn't require changing) On Tue, 24 Aug 1999 21:11:13 GMT, you wrote:

>
>
>In article <37c7de9a.108513494_at_newshost.us.oracle.com>,
> tkyte_at_us.oracle.com wrote:
>> A copy of this was sent to Nandakumar <N.Kumar_at_rocketmail.com>
>> (if that email address didn't require changing)
>> On Tue, 24 Aug 1999 16:41:42 GMT, you wrote:
>>
>> >Hi,
>> >
>> >There are two fields in a table which are of datatype varchar2.
>> >Say Field1, Field2.
>> >When Field1 is NON NULL, Field2 CAN'T be NULL.
>> >How could i impose this as a constraint to one of the fields?
>> >...
>> >I think this is achievable with INSERT trigger.
>>
>> create table t
>> ( f1 int,
>> f2 int,
>> check ( f1 is null or ( f1 is not null and f2 is not null ) )
>> )
>> /
>>
>> if f1 is NULL, the data is OK
>> if f1 is not null then f2 must also be not null....
>
>Is it possible to attach this constraint to a field in a view made over
>the table t? ie) i want to restrict the constraint to ONLY one of the
>views of the table.
>

No -- you cannot put declaritive constraints on views.

You can however, in Oracle8.0 and up, put triggers on views (instead of triggers) to do this sort of checking there.

>Thanks!
>>
>> --
>> See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to
>Oracle8i'...
>> Current article is "Part I of V, Autonomous Transactions" updated June
>21'st
>>
>> Thomas Kyte tkyte_at_us.oracle.com
>> Oracle Service Industries Reston, VA USA
>>
>> Opinions are mine and do not necessarily reflect those of Oracle
>Corporation
>>

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Aug 25 1999 - 06:51:00 CDT

Original text of this message

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