我有一個託管MySQL數據庫的客戶端,開發人員一直要求我添加非常簡單的存儲過程。我看着這樣的存儲過程,我看不出有什麼理由將它作爲存儲過程實現,而不是在應用程序代碼中實現。我正確的說,這對存儲過程的使用是非常奇怪的嗎?這是MySQL存儲過程的邏輯用法嗎?
CREATE DEFINER = 'username'@'%' PROCEDURE `sp_get_payrollgl`(IN pi_glcode TEXT)
DETERMINISTIC
CONTAINS SQL
SQL SECURITY INVOKER
COMMENT ''
BEGIN
if (pi_glcode is null || pi_glcode = '') then
select glcode,descr,
case when crdb = 1 then 'CR' else 'DB' end as 'crdb',
case when taxable = 1 then 'Yes' else 'No' end as 'taxable',
case when billable = 1 then 'Yes' else 'No' end as 'billable',
case when active = 1 then 'Yes' else 'No' end as 'active'
from payrollgl;
else
select glcode,descr,
case when crdb = 1 then 'CR' else 'DB' end as 'crdb',
case when taxable = 1 then 'Yes' else 'No' end as 'taxable',
case when billable = 1 then 'Yes' else 'No' end as 'billable',
case when active = 1 then 'Yes' else 'No' end as 'active'
from payrollgl where glcode = pi_glcode;
end if;
END;
http://www.pcpro.co.uk/blogs/2008/05/18/when-to-use-stored-procedures/ – 2009-08-27 14:19:10