要求把**高於1000的產地為杭州和中國的家電和電子產品放到表productinf_tmp,並轉換商品型別編號為商品型別,商品**高於2000下調5%
create
table
"scott"."productinfo"
(
"productid" varchar2(10),
"productname" varchar2(20),
"productprice"
number(8,2),
"quantity"
number(10,0),
"category" varchar2(10),
"desperation" varchar2(1000),
"origin" varchar2(10),
primary
key ("productid")
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('1', '天堂傘', 59, 50, '1', null, '杭州');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('2', '夏普lcd-48g100a', 7000, 20, '3', null, '日本');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('3', '海爾xqb50-918a', 1100, 29, '3', null, '中國');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('4', '三星xqb50-918a', 3600, 12, '3', null, '中國');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('5', '華為xqb50-918a', 2500, 111, '3', null, '中國');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('6', '台電qb50-918a', 400, 129, '4', null, '中國');
insert
into productinfo (productid, productname, productprice, quantity, category, desperation, origin)
values ('7', '恩克斯-918a', 2800, 22, '2', null, '中國');
commit;
create
table
"scott"."categoryinfo"
(
"categoryid" varchar2(10),
"categoryname" varchar2(30),
primary
key ("categoryid")
insert
into categoryinfo (categoryid, categoryname)
values ('1', '雨具');
insert
into categoryinfo (categoryid, categoryname)
values ('2', '路由器');
insert
into categoryinfo (categoryid, categoryname)
values ('3', '電視');
insert
into categoryinfo (categoryid, categoryname)
values ('4', '洗衣機');
insert
into categoryinfo (categoryid, categoryname)
values ('5', '***');
insert
into categoryinfo (categoryid, categoryname)
values ('6', '鞋');
commit;
declare
cur_categoryid categoryinfo.categoryid%type;
cur_categoryname categoryinfo.categoryname%type;
cur_prodrcd productinfo%rowtype;
tmpnum number(8,0);
cursor cur_prdt_catg is
select * from productinfo where productprice>1000
and origin in('中國','杭州') and category in
(select categoryid from categoryinfo where categoryname in('路由器','電視','洗衣機','***'));
cursor cur_catg is
select categoryid,categoryname from categoryinfo where categoryname in('路由器','電視','洗衣機','***');
begin
--把符合要求的資料放進productinfo_tmp
open cur_prdt_catg;
loop
fetch cur_prdt_catg into cur_prodrcd;
if cur_prdt_catg%found then
insert into productinfo_tmp(productid,productname,productprice,quantity,category,desperation,origin)
values(cur_prodrcd.productid,cur_prodrcd.productname,cur_prodrcd.productprice,cur_prodrcd.quantity,cur_prodrcd.category,cur_prodrcd.desperation,cur_prodrcd.origin);
else
dbms_output.put_line('已取出所有資料!共'||cur_prdt_catg%rowcount||'條記錄');
exit;
endif; end
loop;
commit;
--轉換產品型別
open cur_catg;
tmpnum :=0;
loop
fetch cur_catg into cur_categoryid,cur_categoryname;
if cur_catg%found then
update productinfo_tmp set productinfo_tmp.category=cur_categoryname where category=cur_categoryid;
if sql%found then
tmpnum := tmpnum+sql%rowcount;
endif; else
dbms_output.put_line('產品型別轉換完畢!共轉換'||tmpnum||'條記錄');
exit;
endif; end
loop;
--產品**下調
update productinfo_tmp
set productprice=productprice*0.95
where productprice>2000;
dbms_output.put_line('**下調完畢!共下調'||sql%rowcount||'條商品');
commit;
end;
--查詢結果
select * from productinfo_tmp
oralce 動態游標和靜態游標結合
create or replace procedure sgcm work plan history is type ref cursor type is ref cursor 定義乙個動態游標 usrs ref cursor type str classify id varchar2 250 類別...
游標簡單案例 增刪改
表 create table sp id int primary key identity,name varchar 50 商品名稱 price int,gz varchar 50 關注度 建立儲存過程 gocreate proc v add asbegin 建立游標 declare adds cu...
游標使用具體案例
drop procedure if exists workingday insert 建立儲存過程 create procedure workingday insert begin declare num int default 0 declare centguid sp varchar 100 申...