1、要想檢視儲存過程,用如下命令:
show create procedure proc_dealwith_cs_incomingrecords;
refurl:
2、執行儲存過程:
call proc_dealwith_cs_incomingrecords('2015-01-27');
利用call命令,然後加上引數即可。這個在除錯時非常有用。
refurl:
3、刪除儲存過程:
drop procedure proc_dealwith_ec_incomingrecords
4、建立儲存過程:
create procedure `proc_dealwith_cs_incomingrecords`(in `p_in` date)
begin
/*1.first delete temp*/
delete from temp;
/*2.1 sum by province*/
insert into temp(province,businessname,count,incomingtime)
select province,businessname,count(*) as 'cnt',date_format(incomingtime,'%y/%m/%d') as incomingtime2
from t_incoming_records
where date_format(incomingtime,'%y/%m/%d')=p_in and type=0
group by province,businessname,incomingtime2;
/*2.2 sum by city*/
insert into temp(province,businessname,count,incomingtime)
select city,businessname,count(*) as 'cnt',date_format(incomingtime,'%y/%m/%d') as incomingtime2
from t_incoming_records
where date_format(incomingtime,'%y/%m/%d')=p_in and type=0 and city in (convert('青島市' using utf8),convert('深圳市' using utf8),convert('蘇州市' using utf8),convert('寧波市' using utf8))
group by city,businessname,incomingtime2;
/*3.row to column*/
insert into t_cs_incoming_report(institution,report,compensation,complaint,inquiry,other,yijianxian,incomingtime)
select province as institution,
sum(case when businessname=convert('1' using utf8) then count end) as 'report',
sum(case when businessname=convert('3' using utf8) then count end) as 'compensation',
sum(case when businessname=convert('4' using utf8) then count end) as 'complaint',
sum(case when businessname=convert('2' using utf8) then count end) as 'inquiry',
sum(case when businessname=convert('6' using utf8) then count end) as 'other',
sum(case when businessname=convert('5' using utf8) then count end) as 'yijianxian',
incomingtime
from temp
group by institution;
end
i)一開始要加上關鍵字,create procedure procudurename( 入參名字 in 入參型別)
2)在首尾加上begin和end,中間就是普通的sql**塊。
refurl:
refurl:
mysql儲存過程 MySQL儲存過程
在本節中,您將逐步學習如何在mysql中編寫和開發儲存過程。首先,我們向您介紹儲存過程的概念,並討論何時使用它。然後,展示如何使用過程 的基本元素,如建立儲存過程的語句,if else,case,loop,儲存過程的引數。下面每個教程都包含了易於理解的示例和詳細的說明。如果您瀏覽並學習所有教程,您可...
mysql 儲存過程 mysql 儲存過程
建立 為建立儲存過程的結束標誌,使用delimiter 可更改標誌 格式create procedure begin sqlend create procedure myprocedure in param integer begin select from tb role where tb rol...
mysql 儲存過程 MySQL儲存過程
目錄 儲存過程 簡介是一組為了完成特定功能的sql語句集合 比傳統sql速度更快 執行效率更高 儲存過程的優點 執行一次後,會將生成的二進位制 駐留緩衝區,提高執行效率 sql語句加上控制語句的集合,靈活性高 在伺服器端儲存,客戶端呼叫時,降低網路負載 可多次重複被呼叫,可隨時修改,不影響客戶端呼叫...