如果条件满足,我正在尝试创建模糊某些信息的过程。我能够创建程序,但执行不起作用!
这是表格:
drop table orders;
create table Orders(
OrderID number,
Firstname varchar2(10),
State varchar2(2),
ProductDescription varchar2(20),
Qty number,
ItemPrice number);
insert into Orders values(1, 'Inaae', 'Kim','IL','hard drive', 2,200);
insert into Orders values(3, 'Lisa','Simpson','CA','Books',5,25);
insert into Orders values(4, 'Bart','Simpson','MD','Video',20,3);
insert into Orders values(5, 'Inaae','Kim','WA','ear ring',3,10);
insert into Orders values(6, 'Hommer','Simpson','IN','Beer',50,2);
insert into Orders values(7, 'Marge','Simpson','FL','coffee machine',1,150);
insert into Orders values(8, 'Gerret','W','NY','Chair',1,180);
这是程序代码:
create or replace function fn_extended_price(itemprice IN NUMBER, Qty IN NUMBER) RETURN NUMBER
as
begin
RETURN itemprice * Qty;
end;
/
create or replace procedure sp_order
as
cursor c_order is select OrderId, Firstname, Lastname, ProductDescription, Qty, itemprice, State from Orders;
order_val c_order %ROWTYPE;
vOrder char(20); --will handle extention price blur
vQty number;
vItemPrice number;
vState varchar2(2);
begin
FOR order_val in c_order LOOP
vOrder := fn_extended_price(order_val.itemprice, order_val.Qty);
vQty := order_val.Qty;
vItemPrice := order_val.itemprice;
vState := order_val.State;
if vState = 'CA' OR vState = 'MD' OR vState = 'IL' THEN
vOrder :='*********';
vQty :='********';
vItemPrice :='******';
end if;
DBMS_OUTPUT.PUT_LINE('---------------------------------');
DBMS_OUTPUT.PUT_LINE('Order ID: ' || order_val.orderid);
DBMS_OUTPUT.PUT_LINE('First Name: ' || order_val.firstname);
DBMS_OUTPUT.PUT_LINE('Last Name: ' || order_val.lastname);
DBMS_OUTPUT.PUT_LINE('Product Description: ' || order_val.ProductDescription);
DBMS_OUTPUT.PUT_LINE('Qty: ' || order_val.Qty);
DBMS_OUTPUT.PUT_LINE('Item Price::' || order_val.itemprice);
DBMS_OUTPUT.PUT_LINE('Extended Price: $' || vOrder);
END LOOP;
end;
/
错误是:
SQL> exec sp_orders
BEGIN sp_orders; END;
*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'SP_ORDERS' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
谁能告诉我这是什么错误?
谢谢
答案 0 :(得分:2)
您已将过程命名为sp_order
,但您尝试运行名为sp_orders
的过程。
此外,您尝试将******
值存储在代码中的NUMBER变量中,这会产生"PL/SQL: numeric or value error%s"
异常,请按以下步骤更改您的过程:
create or replace procedure sp_order
as
cursor c_order is select OrderId, Firstname, Lastname, ProductDescription, Qty, itemprice, State from Orders;
order_val c_order %ROWTYPE;
vOrder char(20); --will handle extention price blur
vQty number;
vItemPrice number;
vState varchar2(2);
begin
FOR order_val in c_order LOOP
vOrder := fn_extended_price(order_val.itemprice, order_val.Qty);
vQty := order_val.Qty;
vItemPrice := order_val.itemprice;
vState := order_val.State;
if vState = 'CA' OR vState = 'MD' OR vState = 'IL' THEN
vOrder :='*********';
vQty :=NULL;
vItemPrice :=NULL;
end if;
DBMS_OUTPUT.PUT_LINE('---------------------------------');
DBMS_OUTPUT.PUT_LINE('Order ID: ' || order_val.orderid);
DBMS_OUTPUT.PUT_LINE('First Name: ' || order_val.firstname);
DBMS_OUTPUT.PUT_LINE('Last Name: ' || order_val.lastname);
DBMS_OUTPUT.PUT_LINE('Product Description: ' || order_val.ProductDescription);
DBMS_OUTPUT.PUT_LINE('Qty: ' || order_val.Qty);
DBMS_OUTPUT.PUT_LINE('Item Price::' || order_val.itemprice);
DBMS_OUTPUT.PUT_LINE('Extended Price: $' || vOrder);
END LOOP;
end;
/