ã¹ãã¢ãããã·ã¼ã¸ã£ã§ã§ããªãã¨æãã®ã¯Oracleã®ãã
ãã¹ãã¢ãããã·ã¼ã¸ã£ã§ã§ããªããã§ããããããªããã¨ããã®ã¯ãOracleã®ã¹ãã¢ãããã·ã¼ã¸ã£ï¼ãã¡ã³ã¯ã·ã§ã³ï¼ã§SELECTç³»ã®å¦çãã©ããã¦ãé£ããããã§ãã
ãã¹ãã¢ãããã·ã¼ã¸ã£ã§å¼ç¤¾ã§ä½¿ã£ã¦ããã¹ã¿ãã¨ãã¦ã®ã¹ãã¢ãããã·ã¼ã¸ã£ï¼ãã¡ã³ã¯ã·ã§ã³ï¼ã¯ä»¥ä¸ã®ããã«ãªãã¾ããç¹ã«Oracleã¯é·ããªãã¾ãããæ¬çªæã«æ¸ãæããã®ã¯èµ¤ãé¨åã ãã§ãã
Oracleã®å ´å
CREATEãORãREPLACEãPACKAGEãTEST_PKGãASã /* ã*ããã¹ãä½æ ã*/ ãã--ãTEST_FUNCãç¨ã®ãªãã¸ã§ã¯ãã¿ã¤ããä½æ ããTYPEãTEST_FUNC_ROWãISãRECORD ãã( ããããIDãNUMBERãã--ã主ãã¼ã§ã ãããã,ãNAMEãVARCHAR2(40)ãã--ãåå ãããã,ãBdateãDATEãã--ãèªçæ¥ ãããã,ãADDRESSãVARCHAR2(255)ãã--ãä½æ ãã); ãã--ãTEST_FUNCãç¨ã®ã¬ã³ã¼ãã»ãããå®ç¾©ã ããTYPEãTEST_FUNC_RSETãISãTABLEãOFãTEST_FUNC_ROW; ãã/*ãâ â¡â â¡ãTEST_FUNC ããã*ããã¹ã ããã*ãå¾æå ãæ¤ç´¢ãã ããã*/ ããFUNCTIONãTEST_FUNC ãããã( ããããPARM1ãINãNUMBERãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãããã,ãPARM2ãINãVARCHAR2ãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãã) ããRETURNãTEST_FUNC_RSETãPIPELINED; END; / CREATEãORãREPLACEãPACKAGEãBODYãTEST_PKGãASã /* ã*ããã¹ãä½æ ã*/ ãã/*ãâ â¡â â¡ãTEST_FUNC ããã*ããã¹ã ããã*ãå¾æå ãæ¤ç´¢ãã ããã*/ ããFUNCTIONãTEST_FUNC ãããã( ããããPARM1ãINãNUMBERãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãããã,ãPARM2ãINãVARCHAR2ãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãã) ããRETURNãTEST_FUNC_RSETãPIPELINED ããIS ããããCURSORãCur_MainãIS
ãããããã--ãæ¬çªæã¯ä»¥ä¸ã®SQLãä¿®æ£ãã
ãããããã--ããã®ã³ã¡ã³ããåé¤ããã
ããããããSELECTã*ã
ããããããFROMãxTEST_FUNC_VIEW
ããããããWHEREã
ãããããããã1ã=ã1
ããããããããANDãIDã=ãPARM1
ããããããããANDãNAMEãLIKEãPARM2
ãããããã;
ããããRow_MainãCur_Main%ROWTYPE; ããããReturnRowãTEST_FUNC_ROW; ããBEGIN ããããOPENãCur_Main; ããããLoop ããããããFETCHãCur_MainãINTOãRow_Main; ããããããEXITãWHENãCur_Main%NOTFOUND; ããããããReturnRow.IDã:=ãRow_Main.ID;ãã--ã主ãã¼ã§ã ããããããReturnRow.NAMEã:=ãRow_Main.NAME;ãã--ãåå ããããããReturnRow.Bdateã:=ãRow_Main.Bdate;ãã--ãèªçæ¥ ããããããReturnRow.ADDRESSã:=ãRow_Main.ADDRESS;--ãä½æ ããããããPIPEãROW(ReturnRow);ãã--ããã¼ã¿ãåºåããã ããããENDãLoop; ããããCLOSEãCur_Main; ããããRETURN; ããENDãTEST_FUNC; END;
SQLãServerã®å ´å
/* ã*ããã¹ãä½æ ã*/ ããIFãEXISTSã ãããã(SELECTã*ãFROMãsys.objectsã ããããWHEREãobject_idã=ãOBJECT_ID(N'[dbo].[TEST_FUNC]')ã ããããããANDãtypeãinã(N'P',ãN'PC')) ããDROPãPROCEDUREã[dbo].[TEST_FUNC] ããGO ãã ãã/*ãâ â¡â â¡ãTEST_FUNC ããã*ããã¹ã ããã*/ ããCREATEãPROCEDUREãTEST_FUNC ãããã( ãããã@PARM1ãINTãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãããã,ã@PARM2ãVARCHAR(40)ãã--ãï¼ã¤ç®ã®ãã©ã¡ã¼ã¿ ãã) ããAS ããããSETãNOCOUNTãON;
ãããã--ãæ¬çªæã¯ä»¥ä¸ã®SQLãä¿®æ£ãã
ãããã--ããã®ã³ã¡ã³ããåé¤ããã
ããããSELECTã*ã
ããããFROMãxTEST_FUNC_VIEW
ããããWHEREã
ãããããã1ã=ã1
ããããããANDãIDã=ã@PARM1
ããããããANDãNAMEãLIKEã@PARM2
ãããã;
GO
ã¹ãã¢ãããã·ã¼ã¸ã£ã¯ãããå°ç¨ã§ã¯ãªã
ãã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹ãä½æããããã«ããã©ã¡ã¼ã¿ã¨æ»ãã®åãä»æ§æ¸ã¨ãã¦ã¨ã¯ã»ã«ã«æ¸ãèµ·ããã°ããã¯ãã§ä¸ã®éãã¸ã§ãã¬ã¼ãããããã¼ãã¼ã¿ãåæã«ä½ããã¨ãã§ãã¾ãã
ãã¹ãã¢ãããã·ã¼ã¸ã£ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã¨ãããã¨ã«ããããã¼ã¿ãã¼ã¹ã¨å®å ¨ã«ççµåã«ããç¶æ ã§ã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹å´ã®ã³ã¼ãã£ã³ã°ãå¯è½ã«ãªãã¾ããIDEï¼çµ±åéçºç°å¢ï¼ãO/Rããããå«ãããã¬ã¼ã ã¯ã¼ã¯ã¯æ´ç·´ããã¦ãã¦ããã®ã§ãå¦çæ¸ã¿ã®ãã¼ã¿ãåç´ã«åºåããã ããªããããã°ã©ãã³ã°ã®7ã8å²ã¯ãã¦ã¹æä½ã§å¯è½ã«ãªãã§ãããã
ãã¤ã¾ããç¾å®ã«åãã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹ãå ã«ç´åã§ãã¾ãããã顧客ãæ±ãæçµææç©ã¨ã¤ã¡ã¼ã¸ã®ã®ã£ãããæå°éã«æããåæã®æ®µéã§ï¼ã¦ã¼ã¶ã¤ã³ã¿ãã§ã¼ã¹å´ã®è©³ç´°è¨è¨ãæ¸ãããã«ï¼ãã¼ã¿ãã¼ã¹è¨è¨ãç¡çã«è¡ãå¿ è¦ããªãã®ã§ãéçºã®ææ»ããæãããã¨ãã§ããããå¤§å¹ ãªå·¥æ°åæ¸ãå¯è½ã«ãªãã¾ãã
ã赤ãé¨åãæ¸ãç´ãã°éçºã¯çµäºã§ããã¹ãã¢ãããã·ã¼ã¸ã£ã¯ãããå¦çãããã®ã§ã¯ãªãSQLãã©ããããããã«å©ç¨ãã¾ãããã¡ãããæçµçã«ä¸æã®SQLã«ãªãããã¹ãã¢ãããã·ã¼ã¸ã£å ã§ã¯ã¼ã¯ãã¼ãã«ãªã©ãå©ç¨ãã¦ãããçãªå¦çããããã¨ãå¯è½ã§ãã
ããããçãªå¦çãããªãã¸ã§ã¯ãæåè¨èªå´ã§ã«ã¼ãå¦çãã¦ããã°ã大å¤é ãå¦çã«ãªã£ã¦ãã¾ãã
ãä¸æã®SQLã§ä¸æ¬å¦çã§ãã¦ããã§ããªãã¦ãããã©ã¼ãã³ã¹çã«ãã¡ãªããããããã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹ãéçºãã¦ããæç¹ã§ã¯ãå é¨å¦çããã¼ã¿ãã¼ã¹æ§é ãå ¨ãèæ ®ãã¦ãªãã®ã«ãããããããååãªããã©ã¼ãã³ã¹ãåºããã¨ãå¯è½ã«ãªãã¾ãã
ãSQLServerã¨Oracleãè¦æ¯ã¹ã¦åããããã«ãOracleã¯é常ã«æ¸ãã«ããã§ããã¨ã¯ã»ã«ã§ã¸ã§ãã¬ã¼ãããªãã£ããã¡ãã£ã¨ä½¿ããªããå®éãOracleã®PL/SQL表ï¼ãã¤ãã©ã¤ã³è¡¨ï¼ããã®ãããªä½¿ãæ¹ããã¦ããããã¸ã§ã¯ãã¯ã»ã¨ãã©ãªãã§ãããã
ãã§ããããSQLæã¯ãã¹ã¦ã¹ãã¢ãããã·ã¼ã¸ã£ã«å ¥ãã¦ãçã®SQLãæ¸ããªãã§ã·ã¹ãã ãæ§ç¯ããããããªãã¨ãã§ããããããªããã¨æãã人ã¯ãæ®å¿µãªãã大å¤å¤§å¢ãã¾ãããããªé¢¨ã«æè¦çã«ç解ã§ããªãã®ã¯ãOracleãæ¤ãä»ãããã¹ãã¢ãããã·ã¼ã¸ã£ã¯ãããå¦çã®ããã«ãããã¨ããééã£ãæåã®ããã§ãããã
ãããã¯è¿·ä¿¡ã¿ãããªãã®ã§ãã
ãããããæè¡è ãæ ¹æ ã®ãªãè¿·ä¿¡ãä¿¡ãã¦ã¯ããã¾ãããæ¢ææ¦å¿µãæã¡ç ´ã£ã¦ãããªãã¨æè¡è ã§ã¯ãªãä½æ¥è ã§ãã