DB2 ´¿SQL´æ´¢¹ý³ÌÓ뺯ÊýµÄһЩÏÞÖÆ
*¸ø¶à¸ö±äÁ¿¸³Öµ
functionÖ»ÄÜʹÓÃ
set (a,b,c)=(select a,b,c from #);
procedureÖ»ÄÜʹÓÃ
select a,b,c into a,b,c from #
*functionÎÞ·¨Ç¶Ì×µ÷ÓôøÓÐinout»òout²ÎÊýµÄprocedure£¬ÏÖÏóΪ£ºÎÞ·¨´´½¨¡£
½ñÌìµÄ½øÕ¹½áÂÛÊÇ£º
function¿ÉÒÔµ÷ÓÃÈκÎprocedure£¬µ«±ØÐëÉùÃ÷Ϊmodifies sql data£¬Í¬Ê±±ØÐë·µ»ØtableÀàÐÍ£¬²»ÄÜʹµ¥Öµ»òrowÀàÐÍ
*procedure¿ÉÒÔǶÌ×µ÷Óã¬ÄÄÅÂÊÇ´øinout²ÎÊýµÄ´æ´¢¹ý³Ì.
*function ¿ÉÒÔǶÌ×µ÷ÓÃ.
*IBM¿ª·¢ÕßÍøվһƪÎÄÕÂ˵£ºfunctionµÄЧÂʱÈprocedure¸ß¡£
ÎҵĴð°¸ÊÇÏà·´¡£
ͬÑùµÄÓï¾ä£¬functionºÍprocedureµÄÊ״ε÷ÓÃʱ¼äÓÐ10±¶×óÓҵIJî¾à¡£
¾¹ý²âÊÔÓÐÈçϽáÂÛ£º
1.Èç¹û²ÎÊýÍêÈ«Ò»Ñù£¬Á½´Îµ÷ÓÃͬÑùµÄfunction£¬Ê״ε÷ÓÃËٶȺÜÂý£¨2Ãë×óÓÒ£©£¬µ«µÚ¶þ´Î¿ªÊ¼¾ÍºÜ¿ì£¨0.2Ãë×óÓÒ£©£¬µ«ºóÀ´ºÜ¿ìµÄµ÷ÓÃÓ¦¸ÃÊDzÉÓÃÁË»º´æ»úÖÆ£¬¶øÕâ¸ö»º´æµÄÉú´æÆÚδ֪¡£
2.ͬÑùµÄº¯Êý£¬Ö»Òª²ÎÊý·¢ÉúÈκα仯£¬ÄÇôÊ״λ¹ÊÇ»áºÜÂý¡£
3.procedureºÜÎȶ¨£¬µÚÒ»´ÎºÍºóÃæµÄµ÷Óòî±ð²»´ó¡£²¢ÇÒ¶¼ÊÇ0.2Ã뼶µÄ¡£
¶øÇÒ×îÈÃÈËÄÉÃƵÄÊÇÄÄÅ´úÂë½öÊÇһЩ±È½ÏÅжϣ¬¸ù±¾²»Éæ¼°Êý¾Ý£¬functionµÄЧÂÊÒ²²»¸Ò¹§Î¬¡£
ËùÒÔÈç¹ûÊÇʹÓÃƵÂÊÏ൱¸ßµÄ´úÂ룬ÎÞÂÛÈçºÎ£¬Ïë·½Éè·¨¶¼µÃ¸Ä³Éprocedure¡£
*procedureÎÞ·¨½øÐж¯Ì¬out²ÎÊýprocedureµ÷Óá£
ʲôÒâ˼ÄØ£¬¾ÍÊÇÒªµ÷ÓõÄprocedure²»ÊÇÓ²±àÂëµÄ
--ÕâÊÇûÓÐÎÊÌâµÄ
create procedure out_proc
call in_proc;
end
--ÕâҲûÓÐÎÊÌâµÄ
create procedure out_proc
...
statment='call in_proc()';
prepare s1 from statment;
execute s1;
end
--¿ÉÒÔ´´½¨£¬µ«ÔËÐÐʱ»á±¨´í
create procedure out_proc
...
declare out_param int;
statment='call in_proc('||cast(out_param as char(10))||')';
prepare statment;
execute statment;
end
ÕâЩÏÞÖÆÍêȫûÓÐÈκεÄÎĵµ¿ÉÒÔ²éѯµ½£¬ÊÇʵ¼Ê²âÊÔºóµÃ³öµÄ½áÂÛ£¬ÌؼÇÓÚ´Ë£¬ÃâµÃÒÔºóÓÖ×ßÍä·
Ä¿Ç°ÒѾдºÃÁ˵÷ÓÃprocedureµÄfunction£¬ÐÔÄÜȷʵҪǿ¹ýÖ±½Óµ÷ÓÃfunction¡£µ«Åöµ½ÁËÐÂÎÊÌ⣺
*µ÷ÓÃÁËprocedureµÄfunction²»ÄÜÏóÒ»°ãfunctionÒ»ÑùÔÚselectÓï¾äÖвéѯ£¬±ÈÈç
func1 returns table()
func2 returns table() --ÆäÖе÷ÓÃÁËprocedure
ÄÇô
--Ö±½Ó»ñÈ¡func1,Õý³£
select * from table(func1) as tmp
--Ö±½Ó»ñÈ¡func2£¬Õý³£
select * from t
Ïà¹ØÎĵµ£º
p.s. ²»ÓÃÊÔͼÔÚsql2000·þÎñ¹ÜÀíÆ÷ÉÏÃæ×¢²ásql2005µÄÔ¶³ÌÊý¾Ý¿â·þÎñÆ÷£¬Ö»ÄÜÏÈ´Ósql2005ÉÏÃæµ¼³öÊʺÏsql2000µÄ½¨±í½Å±¾£¬ÔÚsql2000ÉϽ¨¿â½¨±í£¬È»ºóÀûÓÃsql2000µÄµ¼ÈëºÍµ¼³öÏòµ¼£¬½«Êý¾Ý´Ó2005µ¼Èëµ½2000µ±ÖС£
2005תµ½2000µÄ²½Öè²½Öè
1. Éú³Éfor 2000°æ±¾µÄÊý¾Ý¿â½Å±¾
2005 µÄmanger studio
-- ´ò¿ª"¶ÔÏó×ÊÔ´¹ÜÀíÆ ......
ÔÎĵØÖ·£ºhttp://www.dingos.cn/index.php?topic=1688.0
OracleÓÐrownumÓÃÓÚ·ÃÎʱíÖÐÐкš£ÄÇôÔÚSQL ServerÖÐÊÇ·ñÓеÈЧµÄÄØ£¿»òÕßÔÚSQL ServerÖÐÈçºÎÊä³öÐкţ¿
-----------------------------------
ÔÚSQL ServerÖÐûÓÐÖ±½ÓµÈЧÓÚOracleµÄrownum
-----------------------------------
Ñϸñ˵À´£¬ÔÚ¹ØϵÊý¾Ý¿âÖУ¬± ......
ÔÎijö´¦£ºhttp://www.dingos.cn/index.php?topic=1874.0
¶¨ÒåºÍÓ÷¨
CONVERT() º¯ÊýÊÇ°ÑÈÕÆÚת»»ÎªÐÂÊý¾ÝÀàÐ͵ÄͨÓú¯Êý¡£
CONVERT() º¯Êý¿ÉÒÔÓò»Í¬µÄ¸ñʽÏÔʾÈÕÆÚ/ʱ¼äÊý¾Ý
Óï·¨
CONVERT(data_type(length),data_to_be_converted,style)
data_type(length) ¹æ¶¨Ä¿±êÊý¾ÝÀàÐÍ£¨´øÓпÉÑ¡µÄ³¤¶È£©¡£data_to_be_conve ......
ʹÓùýSQL Server 2000µÄÈ˶¼ÖªµÀ£¬ÒªÏëʵÏÖÐÐÁÐת»»,±ØÐë×ÛºÏÀûÓþۺϺ¯ÊýºÍ¶¯Ì¬SQL£¬¾ßÌåʵÏÖÆðÀ´ÐèÒªÒ»¶¨µÄ¼¼ÇÉ£¬¶øÔÚSQL Server 2005ÖУ¬Ê¹ÓÃÐÂÒý½øµÄ¹Ø¼ü×ÖPIVOT/UNPIVOT£¬Ôò¿ÉÒÔºÜÈÝÒ×µÄʵÏÖÐÐÁÐת»»µÄÐèÇó¡£
ÔÚ±¾ÎÄÖÐÎÒÃǽ«Í¨¹ýÁ½¸ö¼òµ¥µÄÀý×ÓÏêϸ½²½âPIVOT/UNPIVOTµÄÓ÷¨¡£
PIVOTµÄÓ÷¨£º
Ê×ÏÈ´´½¨²âÊÔ±í£¬È» ......
CREATE FUNCTION StringToBarcode
(@Value Varchar(50) )
RETURNS NVarchar(100)
AS
BEGIN
Declare @charCount int
Declare @charPos int, @minCharPos int
declare @currentChar int, @checksum int
Declare @isTableB int,@isValid int
&n ......