oracle数据库:业务数据处理之一
一、任务:
1、根据新一轮的促销策略,将原来折扣为0的调整为0.9,将原来折扣为1的调整为0.95,其他的调整为0.92,之后输出"0.9折的商品有XX件,0.92折的商品有XX件,0.95折的商品有XX件";引入PL/SQL,SQLCODE的引用、输出语句、变量等。
2、请用PL/SQL程序块实现将最早的采购单信息输出为:“最早的采购单单号为XXXX,采购日期为XXXX年XX月XX日,供应商名称是XXXXX,采购总金额为XXXXX元”
3、在用户信息查询中,要求除了显示用户基本信息以外,还要显示该用户成功的订单金额,请使用存储函数实现返回的订单总金额
脚本:
1、declare
v_u1 number;
v_u2 number;
v_u3 number;
begin
update t_good set gdiscount=.92 where gdiscount not in(0,1);
v_u1:=SQL%rowcount;
update t_good set gdiscount=.90 where gdiscount=0;
v_u2:=SQL%rowcount;
update t_good set gdiscount=.95 where gdiscount=1;
v_u3:=SQL%rowcount;
dbms_output.put_line('0.92折的商品有'||v_u1||'件,0.90折的商品有'||v_u2||'件,0.95折的商品有'||v_u3||'件');
end;
2、declare
v_pmid t_main_procure.pmid%type;
v_pdate t_main_procure.pdate%type;
v_sname t_supplier.sname%type;
v_pamount t_main_procure.pamount%type;
begin
select pmid,pdate,sname,pamount into v_pmid,v_pdate,v_sname,v_pamount
from t_main_procure a,t_supplier b where a.sid=b.sid
and pdate=to_date('2010-05-12','yyyy-mm-dd');
dbms_output.put_line('最早的采购单单号为'||v_pmid||',采购日期为'||v_pdate||',供应商名称是'||v_sname||',采购总金额为'||v_pamount||'元');
exception
when no_data_found then
dbms_output.put_line("没有找到数据,请检查数据");
when too_many_rows then
dbms_output.put_line('返回多条数据,请使用其他方式实现');
when other then
dbms_output.put_line(SQLERRM);
end;
3、create or replace function f_sumoamount(i_usid in t_main_order.usid%type)
return number
as
v_osum number(12,3);
begin
select sum(oamount) into v_osum from t_main_order where usid=i_usid;
return v_osum;
exception
when others then
dbms_output.put_line(SQLERRM);
return null;
end;
相关
1、truncate table后,往表中t_supplier中insert数据时,先是提示ORA-12899: 列值"SHOPPING_DBA"."T_SUPPLIER"."SNAME"值太大, alter table t_supplier modify sname varchar(30); 报ORA-00054:资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效,百度了一篇
http://hi.baidu.com/fynaa/item/c2978952d8d542dfd48bacf6,还没来得及细看
2、今天开始PL/SQL,原计划三天,根据今天的进度,估计得4天,得抓紧了
2013年7月7日,补充
--循环
declare
i binary_integer :=1;
begin
loop
dbms_output.put_line(i);
i:=i+1;
exit when (i>=11);
end loop;
end;
declare
j binary_integer :=1;
begin
while j<11 loop
dbms_output.put_line(j);
j:=j+1;
end loop;
end;
begin
for k in 1..10 loop
dbms_output.put_line(k);
end loop;
end;
begin
for k in reverse 1..10 loop
dbms_output.put_line(k);
end loop;
end;
本文来源 我爱IT技术网 http://www.52ij.com/jishu/5114.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
