ʵÑé6 PLSQL³ÌÐòÉè¼Æ

(4) ´´½¨Ò»¸ö´æ´¢¹ý³Ì£¬ÒÔ³ö°æÉçÃûΪ²ÎÊý£¬Êä³ö¸Ã³ö°æÉç³ö°æµÄËùÓÐͼÊéµÄÃû³Æ¡¢ISBN¡¢Åú·¢¼Û¸ñ¡¢ÁãÊÛ¼Û¸ñÐÅÏ¢¡£

create or replace procedure proc_get_name( p_title books.title%type) as

cursor c_orderid is select order_id from orders where customer_id=p_customer_id; v_orderid orders.order_id%type;

cursor c_orderitem is select ISBN, sum(quantity) totalnum from orderitem where order_id=v_orderid group by ISBN; v_title books.title%type;

begin

open c_orderid; LOOP

fetch c_orderid into v_orderid;

exit when c_orderid%NOTFOUND; for v_orderitem in c_orderitem LOOP

select title into v_title from books where ISBN=v_orderitem.ISBN; DBMS_OUTPUT.PUT_LINE(p_customer_id||''||v_title||'µÄÊýÁ¿ÊÇ'||v_orderitem.totalnum); end LOOP; end LOOP; close c_orderid; end proc_get_orderinfo; /

set serveroutput on declare v_customer number; begin v_customer :=&x; proc_get_orderinfo(v_customer); end; /

(5) ´´½¨Ò»¸ö´æ´¢¹ý³Ì£¬Êä³öÿ¸ö¿Í»§¶©¹ºµÄͼÊéµÄÊýÁ¿¡¢¼Û¸ñ×ܶ

create or replace procedure proc_category_static as

cursor c_all_category is select distinct category from books; v_sum_cost number; begin

for v_each_category in c_all_category LOOP

select sum(retail) into v_sum_cost from books where category=v_each_category.category group by category;

dbms_output.put_line('ÖÖÀàΪ£º'||v_each_category.category||',×ܼ۸ñΪ£º'|| v_sum_cost); END LOOP;

end proc_category_static; /

set serveroutput on

exec proc_category_static; /

(6) ´´½¨Ò»¸ö´æ´¢¹ý³Ì£¬Êä³öÏúÊÛÊýÁ¿Ç°3ÃûµÄͼÊéµÄÐÅÏ¢¼°ÏúÊÛÃû´Î¡£

create or replace procedure proc_category_static as

cursor c_all_category is select distinct category from books; v_sum_retail number; begin

for v_each_category in c_all_category LOOP

select sum(cost) into v_sum_retail from books where category=v_each_category.category group by category;

dbms_output.put_line('ÖÖÀàΪ£º'||v_each_category.category||',ÊýÁ¿Îª£º'|| v_sum_retail); END LOOP;

end proc_category_static; /

set serveroutput on

exec proc_category_static;

(7) ´´½¨Ò»¸ö´æ´¢¹ý³Ì£¬Êä³ö¶©¹ºÍ¼ÊéÊýÁ¿×î¶àµÄ¿Í»§µÄÐÅÏ¢¼°¶©¹ºÍ¼ÊéµÄÊýÁ¿¡£

(8) ´´½¨Ò»¸ö´æ´¢¹ý³Ì£¬Êä³ö¸÷ÀàͼÊéÖÐÏúÊÛÊýÁ¿×î¶àµÄͼÊéµÄÐÅÏ¢¼°ÏúÊÛµÄÊýÁ¿¡£

(9) ´´½¨Ò»¸ö°ü£¬ÊµÏÖ²éѯ¿Í»§¶©¹ºÍ¼ÊéÏêϸÐÅÏ¢µÄ·ÖÒ³ÏÔʾ¡£

create or replace procedure proc_title_static as

cursor c_all_title is select distinct title from books; v_sum_retail number; begin

for v_each_title in c_all_title LOOP

select sum(cost) into v_sum_retail from books where title=v_each_title.title group by title; dbms_output.put_line('ÐÅϢΪ£º'||v_each_title.title||',ÊýÁ¿Îª£º'|| v_sum_retail); END LOOP; end proc_title_static; /

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ìæ»»Îª@)