Home > database >  PL/SQL cursor changes data tables
PL/SQL cursor changes data tables

Time:09-28



PL/SQL statement is used to implement
According to A, B corresponding id will save as empty data in B data of the same id in (only change space (only card may be null))

CodePudding user response:

- probably like this


The begin
For x in (select id from where a name is null) loop
Update a
Set name=(select the name from b where id=x.i d);
end loop;
The end;
/

CodePudding user response:

In oracle without constraints, to update all records, easy to cause the value of your other records to be updated to null, reference writing:
The update TMP a
The set a. d. jh=(select b.q SXZ from tmp2 b where a. sm=b.b sm)
where a. sm (select in BSM from tmp2)
Note: outside the where is very important, otherwise easy to cause data corruption, you can test it

CodePudding user response:

 
The CREATE OR REPLACE procedure p_fill_data (as_log OUT VARCHAR2) - CREATE a stored procedure
IS
CURSOR c_table_a IS the SELECT * FROM table_a FOR UPDATE. - define table a cursor
Ct c_table_a % ROWTYPE;
The BEGIN
The OPEN c_table_a;
LOOP
The fetch c_table_a into ct;
Exit the when c_table_a % notfound;
IF ct. The card IS NULL OR ct. Card="' THEN - IF NULL
The UPDATE table_a SET card=(SELECT card FROM table_b WHERE id=ct. Id); - update the data from table b
END LOOP;
The CLOSE c_table_a;
As_log:='execution success! ';
COMMIT; - submit
Abnormal EXCEPTION -
The when others then
As_log:=sqlcode | | '-' | | sqlerrm;
The ROLLBACK.
End p_fill_data;


CodePudding user response:

  • Related