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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie: 'identifier must be declared' when deleting from table

Re: Newbie: 'identifier must be declared' when deleting from table

From: Niall Litchfield <n-litchfield_at_audit-commission.gov.uk>
Date: Thu, 17 Jul 2003 12:19:13 +0100
Message-ID: <3f168633$0$15038$ed9e5944@reading.news.pipex.net>


"Ian McCall" <ian_at_eruvia.org> wrote in message news:_fvRa.11097$ju6.206688_at_newsfep4-glfd.server.ntli.net...
>
> "Jim Kennedy" <kennedy-down_with_spammers_at_no_spam.comcast.net> wrote in
> message news:LetRa.81709$H17.25850_at_sccrnsc02...
> > Should be a date. Leaving it at midnight is perfectly acceptable. Dates
> > only take 7 bytes and give you flexibility to treat them as dates.
>
> Understand your point, and I'd normally agree. The problem I'm trying to
> avoid is catching bad coding that could mess up the primary key however.
>
> With archive_date as a date a user could run insert into target_table
> values(someValue, sysdate) and it would work. sysdate now has a resolution
> including a time component, which means they could run that statement
again
> and it would work, rather than faily with a duplicate key error (the
desired
> behaviour). Enforcing varchar(8) does mean I could potentially get
problems
> like (someValue, 'herring') working instead of the YYYYMMDD I expected,
but
> at least it won't allow two values for the same day.

I'd deal with this with a check constraint

SQL> create table tab1(
  2 col1 varchar2(200),
  3 archive_date date);

Table created.

SQL> alter table tab1 add constraint pk_tab1 primary key (archive_date);

Table altered.

SQL> alter table tab1 add constraint ck_archdate check(archive_date=trunc(archive_date));

Table altered.

SQL>
SQL> insert into tab1 values('somevalue',sysdate); insert into tab1 values('somevalue',sysdate) *
ERROR at line 1:
ORA-02290: check constraint (NIALL.CK_ARCHDATE) violated

SQL>
SQL> spool off Received on Thu Jul 17 2003 - 06:19:13 CDT

Original text of this message

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