Home » SQL & PL/SQL » SQL & PL/SQL » Global data update script help !!!
Global data update script help !!! [message #19552] Wed, 27 March 2002 06:02 Go to next message
Arpit
Messages: 99
Registered: March 2001
Member
Hi,

I need to write a script that will do a global update on the Product_No field in the Product table. This product_no field is linked to four tables and the update needs to be done on all of these four tables.

The key thing is that this script / routine will be ran by the user who will key in the old product_no and the new product_no and it should do the global update on all the tables.

Can someone please let me know how I could create this script with a prompt for the old and new product nos. so that the user can key it and behind the scene do the global update in the database.

Your help on this would be highly appreciated.

Thanks!
Re: Global data update script help !!! [message #19555 is a reply to message #19552] Wed, 27 March 2002 08:44 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
if you have foreign keys between those thables then it's not straight forward.

http://govt.oracle.com/~tkyte/update_cascade/

You could recreate the FK, PK constraints as DEFERRABLE.
drop table emp;
drop table dept;
CREATE TABLE dept
   (deptno   NUMBER NOT NULL PRIMARY KEY ,
    deptname VARCHAR2(30) NOT NULL );

CREATE TABLE emp
   (empno   NUMBER NOT NULL PRIMARY KEY,
    empname  VARCHAR2(20) NOT NULL,
    deptno   NUMBER,
       CONSTRAINT emp_fk1 foreign key (deptno) references dept(deptno) DEFERRABLE);

insert into dept values (10, 'Sales');
insert into emp values (1, 'Joe', 10);
commit;

-- see if we can do it with just deferrable constraints
begin
 update dept set deptno = 100 where deptno = 10;
 update emp set deptno = 100 where deptno = 10;
end;
/

-- no, we need to set the constraints to deferred in this session
-- in pl/sql block because most applications would typically use it this way
begin
Execute immediate 'SET CONSTRAINTS ALL DEFERRED';
update dept set deptno = 100 where deptno = 10;
update emp set deptno = 100 where deptno = 10;
 -- set them back on again now that we are done
 -- else they are reset to default (immediate)
 -- on commit/rollback
Execute immediate 'SET CONSTRAINTS ALL IMMEDIATE';
end;
/
select * from dept;
select * from emp;
Previous Topic: count function with outer Join on Oracle8i
Next Topic: How to update the Array - Please HELP
Goto Forum:
  


Current Time: Fri Apr 26 19:50:29 CDT 2024