手順は以下の例外単一行副問合せ手順で複数の行を戻す
単一行のサブクエリが複数行を返すスロー
SQLでクエリを実行しながら、>クエリが細かい実行し、番組が をもたらします期待
create or replace procedure discount_purchase(cust_name customer1.cust_name%type)
as
amt int;
discount int;
begin
select sum(purch_amt) into amt
from orders
where customer_id=(select customer_id from customer1 where cust_name=cust_name);
dbms_output.put_line('Total amount is='||amt);
if(amt>=500) then
discount:=amt-(0.25*amt);
dbms_output.put_line('Discount amount is='||discount);
else
dbms_output.put_line('NO Discount on='||amt||'Discount only above 500');
end if;
end;
/
SQL> execのdiscount_purchase( 'ニック・リマンド');
BEGIN discount_purchase('Nick Rimando'); END;
*
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row
ORA-06512: at "ARPAN.DISCOUNT_PURCHASE", line 6
ORA-06512: at line 1
エイリアス名を使用してサブクエリの最初の行を取得 –
サブクエリは単一の値3002をcustomer_idとして返します –
リストから値を気にしない場合は、サブクエリ条件にrownum = 1を追加してください。同じ。 –