有商品表(商品号,商品名,分类,单价),请编写一个实现更改商品单价的Oracle存储过程(过程

过程名为pUpdate),更改规则如下:“电脑”类商品降价10%,“电视”类商品降价6%,“冰箱”类商品降价3%,其他商品不降价。以商品的分类作为输入参数,假设“分类”为字符串类型,长度最多为6个汉字。如果商品表中没有用户指定的分类,则用输出参数返回字符串“指定的分类不存在”;如果用户指定的分类存在,则用输出参数返回字符串“修改已成功”。
(小弟Oracle初学者,请哪位大大耐心帮忙看下(请给出详细代码,代码中仅使用最简单的动态SQL即可,不要用其它高级特性,否则初学者看不懂。O(∩_∩)O~)

建表语句如下:
create table TB_PRODUCT
(
TYPE_ID NUMBER,
TYPE VARCHAR2(100)
)
create table TB_PRICE
(
TYPE VARCHAR2(12),
PRICE NUMBER
)

存储过程如下:
create or replace procedure pUpdate(productTypeIn in varchar2, outStr out varchar2)
as
flag number;
begin
if length(productTypeIn) > 12 then
outStr := 'Please input parameter litter than 6 Chinese letter!';
else

select count(*)
into flag
from tb_product product
where product.type = productTypeIn;

if flag = 0 then
outStr := 'No such product!';
else
case productTypeIn
when 'Computer' then
update tb_price t
set t.price = t.price * 0.9
where t.type = productTypeIn;
when 'tv' then
update tb_price t
set t.price = t.price * 0.94
where t.type = productTypeIn;
when 'bx' then
update tb_price t
set t.price = t.price * 0.97
where t.type = productTypeIn;
end case;
commit;
outStr := 'Modify success!';
end if;
end if;
end pUpdate;

纯手写,已验证。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-10-13
以下是SQL的,不过大同小异
create proc pUpdate @分类 char(6) As
declare @输出变量 char(50)
if(select count(*) from 商品表 where 分类=@分类)=0
begin
select @输出变量='指定的分类不存在'
else
begin
-----进行修改
select @输出变量='修改已成功
end
select @输出变量 as outPrint追问

我想要个ORACLE版本的答案。sql server版的答案我有,但我是学oracle的初学者,看不懂其它版本的代码

相似回答