1. (5 pts+2 bonus pts) Assume two tables T1 and T2 have been created as follows.
ID: 3601529 • Letter: 1
Question
1. (5 pts+2 bonus pts) Assume two tables T1 and T2 have been created as follows. create table T1 x number, y number create table T2 x number, y number Write a procedure ProcProblem1. The procedure should find rows from table T1 whose x are no greater than y, and copy such rows into table T2. For example, given the content of table T1: By calling procedure ProcProblem1, table T2 will become There are different approaches to implementing procedur e ProcProbleml a) b) Using a cursor (5 pts) Without using a cursor (2 bonus pts)Explanation / Answer
Hi..I have written procedure with cursor and withour cursor. Please check it and let me know any issues.
ProcProb1em1 with cursor
create or replace procedure ProcProb1em1 is
cursor c_emp is select * from T1 a where a.y>=a.x;
r_emp c_emp%ROWTYPE;
begin
open c_emp;
loop
fetch c_emp into r_emp;
exit when c_emp%NOTFOUND;
insert into table T2 values (r_emp.x,r_emp.y);
end loop;
close c_emp;
end;
ProcProb1em1 without cursor:
create or replace procedure ProcProb1em1 is
begin
for i in (select * from T1 a where a.y>=a.x)
loop
insert into table T2 values (i.x,i.y);
end loop;
end
Running a procedure:
SQL> call ProcProb1em1();
Call completed.
SQL> select * from T2;
X Y
3 3
2 8
Thank you... All the best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.