Skip to content

Commit

Permalink
Create promotions.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam1841 committed Dec 4, 2015
1 parent fce3049 commit ef1e6ef
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions promotions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set serveroutput on;

DECLARE
rand number(2);
ct number(2);
type prod is record(pid PRODUCT.PRODUCTID%type,
pname PRODUCT.NAME%type,
price PRODUCT.PRICE%type,
image PRODUCT.IMAGE%type);
rec prod;
begin

FOR i IN 1..4 LOOP
select max(PRODUCTID) into ct from PRODUCT;
select dbms_random.value(1,ct) into rand from dual;

select productid, name, price, image into rec.pid,rec.pname,rec.price,rec.image from PRODUCT where productid = rand;
update promotions
set productid = rec.pid, name=rec.pname, price=rec.price, image=rec.image
where repeatnum = i;
END LOOP;


end;

0 comments on commit ef1e6ef

Please sign in to comment.