Home » SQL & PL/SQL » SQL & PL/SQL » ORA-02291: how to assign value to varchar2 variable depending on specific input?
ORA-02291: how to assign value to varchar2 variable depending on specific input? [message #625644] Sun, 12 October 2014 06:00 Go to next message
Silently_Quiet_Logic
Messages: 1
Registered: October 2014
Junior Member
Hi all,
fresh to the forums, I'm using SQL Developer and am aware that error ORA-02291 has been
discussed many times, my situation is as follows:

(All variables used are varchar2(100), tables A and B were created and empty at first)
I have a unique non-primary key attribute (i.e. Animal) in table A that is
referenced in table B as a foreign key ('Species'), a value of 'Tabby Cat' was
inserted into Table A's Animal column, when I try to insert value 'Cat' into
Table B's Species column, I get the ORA-02291 error as expected.

Now I want the database to react so that when it reads 'Cat' in 'Tabby Cat' from
Table A, it would refer to it as instead 'Cat', how would one program this so that
it works for future inserts as well? Thanks in advance,

Silently_Quiet_Logic
Re: ORA-02291: how to assign value to varchar2 variable depending on specific input? [message #625645 is a reply to message #625644] Sun, 12 October 2014 06:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Don't you think it is silly to sign with a (stupid) nickname?

To use a foreign key you must have a unique (or primary key) constraint in the parent table, so define your unique constraint so that it matches what you want to do EXACTLY (so you have to be able to define with words what is this constraint).

If you can't define it with a constraint (because it is too fuzzy to be define as it) then use a trigger.

Re: ORA-02291: how to assign value to varchar2 variable depending on specific input? [message #625652 is a reply to message #625644] Sun, 12 October 2014 08:59 Go to previous message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Is this a school homework assignment? If so, a few more pointers: a context index on your unique column, then insert/update trigger on the child table that use CONTAINS to search the parent table. you also need update/delete triggers on the parent to ensure that you don't get orphaned rows.
Previous Topic: CASE STATEMENT IN DDL
Next Topic: query to quit after repeating values
Goto Forum:
  


Current Time: Thu Apr 25 03:32:17 CDT 2024