儲存過程 函式寫法

2021-09-01 03:48:24 字數 2533 閱讀 4232

函式

create or replace function f_productcard( str_in in varchar2 )--分類字段

return varchar2

is str_list varchar2(4000) default null;--連線後字串

str varchar2(20) default null;--連線符號

strvar1 varchar2(40) default null ; --訂單號

strvar2 varchar2(40) default null ; --卡號

begin

for x in ( select t.orderno,t.agric_card_no from v_send_product1 t where t.orderno = str_in ) loop

if(strvar1=x.orderno and strvar2=x.agric_card_no) then

str_list :=str_list;

else

str_list :=str_list||str||x.agric_card_no;

end if ;

str := ' | ';

strvar1 :=x.orderno;

strvar2 :=x.agric_card_no ;

end loop;

return str_list;

end ;

儲存過程

create or replace procedure pro_farmproductranking(v1 in  char,v2 in  char,saletime_cur out sale_pack.sale_cur,v3  in char) is

begin

open saletime_cur for

select rownum as id,a."order_id",a."productname",a."quantity",a."fee",null as statice_time from (

select rank() over

( order by sum(a.quantity) desc) order_id,--排名

b.productname,--產品名稱

sum(a.quantity) quantity,--成交總數量

sum(a.quantity*a.price) fee--成交總金額

from product b,--產品

order_item a,--訂單詳細

sales_order c

where a.productid=b.productid(+) and c.orderid=a.orderid and c.orderstatus=6 and to_char(c.updatetime,'yyyymmdd')>=v1 and to_char(c.updatetime,'yyyymmdd')<=v2 and b.productname like v3

and b.producttypeid='11'

group by b.productname) a

union all

select null as id,null as order_id,'合計'as productname,sum(quantity),sum(fee),null as statice_time from

( select rownum as id,a."order_id",a."productname",a."quantity",a."fee",null as statice_time from (

select rank() over

( order by sum(a.quantity) desc) order_id,--排名

b.productname,--產品名稱

sum(a.quantity) quantity,--成交總數量

sum(a.quantity*a.price) fee--成交總金額

from order_item a,--訂單詳細

product b,--產品

sales_order c

where a.productid=b.productid(+) and c.orderid=a.orderid and c.orderstatus=6 and to_char(c.updatetime,'yyyymmdd')>=v1 and to_char(c.updatetime,'yyyymmdd')<=v2 and b.productname like v3

and b.producttypeid='11'

group by b.productname) a

)b;end pro_farmproductranking ;

動態ref游標宣告:

create or replace package sale_pack  as

type sale_cur is ref cursor;

end sale_pack;

儲存過程寫法

引用 儲存過程呼叫 drop procedure if exists pro rep shadow rs delimiter rep shadow rs 用來處理資訊的增加,更新和刪除 每次只更新上次以來沒有做過的資料 根據不同的標誌位 需要乙個輸出的引數,如果返回為0,則呼叫失敗,事務回滾 如果返...

儲存過程寫法

引用 儲存過程呼叫 drop procedure if exists pro rep shadow rs delimiter rep shadow rs 用來處理資訊的增加,更新和刪除 每次只更新上次以來沒有做過的資料 根據不同的標誌位 需要乙個輸出的引數,如果返回為0,則呼叫失敗,事務回滾 如果返...

儲存過程寫法

建立儲存過程執行刪除操作 alter procedure dbo ad preempted timer asdeclare pid varchar 32 declare times date declare nowtime date declare difftime int 定義乙個游標 decla...