2016幎ã®ç§ã®åãã«ããªãŒããŒã·ããã¯ç§ã«SQLãªãªã³ãã¢ãŒãã®æè¡çãªéšåãæºåããã¿ã¹ã¯ãèšå®ããŸããã ç§ã®å ãå«ãååãšç¶æ³ã«ã€ããŠè©±ãåã£ãåŸãç§ã¯çªãããŸããïŒçªãããŸãããïŒïŒãSQLã®å®£èšçãªã¹ã¿ã€ã«ã§ãè¿·è·¯ããã®æçåºå£ãæ§ç¯ããã¿ã¹ã¯ã解決ãããèšäºã«ã èŠæ±ã®1ã€ã®ããŒãéšåã«éãŸãããããå®éã®ããŒã¹ã§å®è¡ããåŸããéæ³ïŒ..ããšãããããŠããªãªã³ããã¯ãããããšã«æ°ä»ããŸããã
ãªãªã³ããã¯ã§ã®Habrã®å žåçãªèªè ã¯å°ãªããšãäžåºŠã¯ãããšæããŸããããããäž»å¬è ã§ã¯ãªãåå è ã®åœ¹å²ã§ããã ç§ã¯ãŸãå¥ã®ãã®ã«è¡ããŸãããããªããããããã€ãã®ãªãªã³ãã¢ãŒãã§é¢çœãã®ãããããŠä»ã®äººã®å¿ æ»ã®æ§ããªã®ãã¯ãã€ãé©ãã§ããã ãã®åå Žãã«ãŒãã³ã®åããåŽã«ã©ã®ããã«èŠãããããããŠã©ã®ããã«ãã®ãªãªã³ãã¢ãŒããèå³æ·±ããã®ã«ããããšãããã瀺ãããšãã§ããŸãã é°è¬ãã¹ãã£ã³ãã«ã調æ»-ããã¯èµ·ãããŸããã ããããã¿ã¹ã¯ãã©ã®ããã«æºåããããããããã«äœãæåŸ ãããäœãçµæã§ãã£ããã説æããŸãã
å ¥é
2016/17ãªãªã³ãã㯠ããã¯èšå¿µæ¥ã®ããã«ã10åéå¬ãããŸããã ãªãªã³ãã¢ãŒãã¯åœéçã«å®£èšãããŠããŸããããã®äž»èŠèšèªã¯ãã·ã¢èªã§ãããããå人çã«ã¯ãªãŒã«ãŠããªã³ãšåŒãã§ããŸãã ç§ã¯ã³ã³ãã¹ãã®æè¡çãªéšåãSQLããã°ã©ãã³ã°èšèªã§æºåããŠããŸããïŒä»ã«ãããããŒãããããŸããïŒã çè«çã«ã¯ããã®æåã®2çªç®ã®äž»å¬è ã¯Oracleã§ããããç§ã¯åœŒãã®ä»£è¡šè ã«äŒã£ãããšããããŸããã ãããã£ãŠãOracleããã®å¯äžã®ãã¬ãŒã¹ã¯ãé¢é£ãããã¹ãŠã®SQLã®è©³çŽ°ãåããOracleããŒã¿ããŒã¹ã䜿çšããããšã§ãã
ãªãªã³ãã¢ãŒã2016/17決åã®å ¬åŒãŠã§ããµã€ãã§ã®ã¬ããŒãã¯æ¬¡ã®ãšããã§ããhttp ïŒ //world-it-planet.org/press/news/detail.phpïŒID = 323774
ããã«ã€ããŠã¯ãã¯ã¬ãžãããå®äºãããšã¿ãªããåµå¯ãæäŸããŸããã ããå°ãäžè¬çãªèšèãšç§ã¯è¡åã«ç§»ããŸãã
çµå¶é£ïŒãã«ã«ã«ããã©ã³ã·ã¥ïŒããè¿œå ã®æ瀺ã¯äžããããªãã£ãããããªãªã³ããã¯ã®äž»ãªç®æšã¯SQLèšèªãæ®åãããããšã§ããã ãšããã§ãããã¯å®éã«å®éã«äœ¿çšãããŠããæ°å°ãªã宣èšåããã°ã©ãã³ã°èšèªã®1ã€ã§ãã ãŸããããŒã¿ããŒã¹ãç¹ã«ãµãŒããŒãåããç£æ¥çšããŒã¿ããŒã¹ãå°å¹³ç·äžã«ç»å Žããå Žåã代æ¿æ段ã¯ãŸã£ãããããŸãããç£æ¥æšæºã¯äºå®äžã§ãã ããã«ãå€ãã®ããããœãªã¥ãŒã·ã§ã³ã§ã¯ãäœããéžæããŠã°ã«ãŒãåãŸãã¯äžŠã¹æ¿ããå¿ èŠãããå ŽåãSQLã®ãããªã¯ãšãªæ§æã䜿çšããŸãã ããšãã°ãJIRAã®JQLãŸãã¯Sphinx Search Engineã®ã¯ãšãªèšèªã
ã¯ããããã§ãäž»ãªç®æšãèšå®ãããŸãã-SQLãæ®åãããããšã ããå€ãã®äººãSQLãç¥ã£ãŠãããSQLãäžæã«æžãããšãã§ããããã«ã ãããããç§ãã¡ã®äººå¡äºåã§ããã¹ãŠã倧äžå€«ã§ãã éã«æ²¿ã£ãŠãç§ãã¡ã¯ç¢ºãã«èªåèªèº«ã宣äŒããæèœãæ±ããŸãã èšããŸã§ããªãã ããããäž»ãªããšã¯SQLã«æ³šæãåŒãããšã§ãã ãããŠäžåºŠæ®åããããããã¯èå³æ·±ãã¯ãã§ãã
äž»å¬è ã¯ã次ã®ã³ã³ãã¹ãã®ã¬ã€ã¢ãŠããçºè¡šããŸããã2ã€ã®éä¿¡ãã¢ãŒãšãã«ã¿ã€ã ã®æ±ºåã§ãã äžè¬çãªæŠå¿µã¯æ¬¡ã®ããã«å®çŸ©ãããŸãã æåã®ã©ãŠã³ãã¯äºéžã§ãããããã¯ã«åå ããŠããªã人ã®å€ããé€å€ããå¿ èŠããããŸãã 2åç®ã®ã©ãŠã³ãã¯æãèå³æ·±ããã®ã§ãã ããããã1ã€ã®SQLã¯ãšãªã§åŒ±ããŠãããããããšãããŸããïŒã æ¯ãè¿ãæ©äŒãããããã«ãããå€ãã®æéãäžããŸããã座ã£ãŠæéããªãããã«å¶éããŸãã åã粟ç¥ã§ãã«ã¿ã€ã ã®æ±ºåæŠãéå¬ããããšã¯ã§ããŸããã決åæŠã®3æéïŒããšã8æéã§ãã£ãŠãïŒã¯ãSQLã®ãããªãã®ãæãä»ãã®ã¯åé¡ã§ãã ã€ãŸããã©ãã«è¡ãã¹ãããé»æããããŸãã ããã¯ç¢ºãã«æã匷åãªããã°ã©ããŒã決å®ããããã®æè¯ã®æ¹æ³ã§ã¯ãããŸããããããã§ãä¹±æ°ãžã§ãã¬ãŒã¿ãŒã«å°ãããããå°ãè¯ãã§ãã
ãããŠãæºåäœæ¥ã沞隰ãå§ããŸããã
æåã®ã©ãŠã³ã修食åã 2016幎12æ
ããã§ã¯ããã¡ãããåãã³ã³ããã£ã·ã§ã³ã®ååã®æ¥çžŸã掻çšããŸããããå幎ã«ã¯ã圌ãã«åå¥ã«æè¬ããŠããŸãã IT Planetã«ã¯ããã¹ããå®è¡ããç¹å¥ãªãšã³ãžã³ããããŸãã 100ãè¶ ãã質åã®ããŒã¿ããŒã¹ããéžæããåçãªãã·ã§ã³ãšãšãã«åéãããŸããã åå è ã«ã¯30ã®è³ªåããããŸãã æšå¹Žåå è ãåå ãããšããŠãã1ã€ãŸãã¯2ã€ä»¥äžã®è³ªåãç¹°ãè¿ãããããšã¯ã»ãšãã©ãããŸããã ãããŠãããã¯èª°ã«ãšã£ãŠãããŸã倩æ°ãããŸããã
ãã®ããã質åãæ ¹æ¬çã«å€æŽããããæ¢åã®è³ªåãæºãã¶ã£ãããæ°ä»ããããã€ãã®ééããä¿®æ£ããããå°æ¥ã®äžä»£ãšé¢å©ããããã«äœããæ®ãããããŸããã ãã®ãããªè³ªåã¯ãå žåçãªããã¡ããªãã¯ãªã³ã©ã€ã³ãã¹ãã®ã¬ãã«ã§ããå æ°ãªãã®ã§ããããšãããããŸããã ããã«ãå質åã§ãã¹ãŠã®æ£ãããªãã·ã§ã³ãéžæããå¿ èŠããããŸãããããããã®ã©ãã ããæ£ãã瀺ãããªãã£ãããšããåé¡ãæå³çã«äœæãããŸããã ãã®å Žåããã¹ãŠã®æ£è§£ã瀺ãããŠãã質åã®ã¿ãã«ãŠã³ããããŸããã ã€ãŸããåã«ããŠã¹ã§ã€ã€ããŠãããã€ãã®ãã¹ãã®ããã«ãå¹³å25ïŒ ãäžåºŠã§ãããŸããããªããšããããšã§ãã ãã®çµæãç§èªèº«ã質å/åçã®èªã¿èŸŒã¿ã®æ£ç¢ºæ§ã確èªããªããããã¹ãŠã®è³ªåãå®å šã«ééããªãããå®æçã«ããã€ãã®è³ªåã«èª€ã£ãŠåçããŸããã
ãã®ãããªãµããã¯ãSQLå šè¬ãç¹ã«Oracle SQLã®ç¥èã¬ãã«ã«å¿ããŠåå è ãé©åã«åæ£ãããããšãæåŸ ãããŠãããããç¥èã®ãããã®ãããé«ãå°äœãå ããŸãã ååå è ã®30ã®è³ªåã¯ãåã ã®è³ªåã®ãæ©èœããçµ±èšçã«å¹³æºåããŸãã ããã«ããã¹ãŠãæ·±å»ã§ããã容赊ãªããšããåå è ãžã®æ²»çå¹æã
ç·Žç¿ã¯æåŸ ã®æ£ããã確èªããŸãã;å®éãåå è ã¯ãã¢ãœã³ïŒïŒïŒã«åŸã£ãŠããªãããååžããå¹³åã§7ã€ã®è³ªåã«æ£ããçããŸããã 1人ã®åå è ã30ã®è³ªåãã¹ãŠã«æ£ããçããããšããã§ããŸããïŒããã«å¹žéã§ããïŒïŒã4人ã®åå è ã¯ãã§ã«æ£ããçããæã£ãŠããŸãã äžåºŠãæšæž¬ããã«ã6人ããããã«åæ ŒããŸããã èŠããã«ãå¿ èŠãªãã®ã ãã®ã¢ãããŒãã«ããã2åç®ã®ã©ãŠã³ãã§å¿ èŠãªæ°ã®åå è ã圢æããããã«é©åãªåæ Œã¹ã³ã¢ãéžæããæé©ãªãã®ãéžæããããšãå¯èœã«ãªããŸããã äž»å¬è ã®èšç»ã«ãããšãçŽ200人ã®åå è ãããªãåççãªå¶éãæã£ãŠç¬¬2ã©ãŠã³ãã«åå ããå¿ èŠããããåœã倧åŠããšã®åå è ã®å€æ§æ§ãæ倧éã«é«ããŸããã
第2ã©ãŠã³ããã¡ã€ã³ã©ãŠã³ãã 2017幎3æ
2åç®ã®ã©ãŠã³ãã¯ãééããªããã®ãªãªã³ãã¢ãŒãå šäœã§æãèå³æ·±ãã€ãã³ãã§ããã ãã®äžã§ãããŒãã³ã¢ãªSQLããžãã¯ãè©Šãããšãã§ããŸããã
ãšã«ãããããã®ã¿ã¹ã¯ãåå©çšããããšã¯äžå¯èœãªã®ã§ããããã¯ãã§ã«ç¹ç¯ããŠããã®ã§ãããã«æã£ãŠããŸãã éšåçã«ããã®åºçç©ã¯SQLèšèªã®ãããªãæ®åã®ããã«æºåãããã¿ã¹ã¯ãå ±æããæ©äŒãšããŠèããããŸããã æ¯figçã«èšãã°ãåã¿ã¹ã¯ã¯ãInto one SQL query ...ããšããèšèã§å§ãŸãããã®åŸãäœããå®å šã«ç°ãªããŸã©Monty Pythonã æ®å¿µãªãããã¿ã¹ã¯ã1ã€ã®ãã¬ãŒãºã«ãŸãšããããšã¯äžå¯èœã§ãããæ¡ä»¶ã®æ£ããã¹ããŒãã¡ã³ãã«ã€ããŠè©³çŽ°ãªèª¬æãè¿œå ãããã¹ãããŒã¿ãšãããã®ãã¹ãããŒã¿ã®è§£æ±ºäŸãæ確ã«ããããã«æäŸããå¿ èŠããããŸããã
ãSQLã§ããã¯æ¬åœã«å¯èœãããªã©ã®ã¿ã¹ã¯ã«é¡èãªã¯ãŠå¹æãããããšã確èªããéåžžã«ç¹æ®ãªã¹ãã«ãå¿ èŠãšããåŸæ¥ã®ãªãªã³ãã¢ãŒãã®ãããã¯ããé¢ããããã«ãç§ã¯äžçæžåœåªåããŸããã åã¿ã¹ã¯ã®è€éãã¯ãæåã«ãåé¡ã®å€å žçãªããã°ã©ãã³ã°ã«å¯ŸããŠãå®å šã«ç¬ç«ããŠããŠèªæã§ã¯ãªã宣èšçã¡ãœããèªäœãæ³åããããšã§æ§æãããŠããŸããã ãŸããåå è ã«åã¿ã¹ã¯ã®èª¬ææãäœæããããèŠæ±ããŸããã äžæ¹ã§ãç§ãã¡ã¯èªåã®èããæ確ã«è¿°ã¹ãããšãã§ãã人ã ã«èå³ãããããã®ãããªäººã ã奚å±ãããã£ãã®ã§ãã äžæ¹ã第2ã©ãŠã³ãã®ã¿ã¹ã¯ã«å¯ŸããåçãæåŸ ããããã¹ãŠã®åå è ããéä¿¡ãããå Žåããã®ãããªèª¬æã¯æ€èšŒã«éåžžã«åœ¹ç«ã¡ãŸãã ä»åŸã第2ã©ãŠã³ãã®200人以äžã®åå è ã®ãã¡ãåçãéä¿¡ããã®ã¯34人ã ãã§ããã ããã¯ããã»ã©ã§ã¯ãããŸããããïŒé©ãã¹ãããšã«ïŒå幎ã®ç¬¬2ã©ãŠã³ãã®ã¢ã¯ãã£ããªåå è ã®æ°ãšã»ãŒåãã§ãã ããã«ããããã¹ãŠã®äœæ¥ã培åºçã«æåã§å確èªããæçµçã«æã䟡å€ã®ãããã®ãåŒã³åºãããšãã§ããŸããã
äž»å¬è ã®ã¹ã±ãžã¥ãŒã«ã«é¢ãã2åç®ã®ãã¢ãŒã¯ã3æ1æ¥ã«å§ãŸããŸããã 5ã€ã®åé¡ã解決ããããã«ã3æ12æ¥23æ59åãŸã§1é±éåãããã«ãã以äžãäžããŸããã ãã®ãããæéã®çµããã¯3æ8æ¥ä»¥éã®é±æ«ã«ãªããŸãã åå è ãæåŸã®2æ¥éã§äžçæžåœåãããšãã§ããåæã«å人ã®ç掻ãããŸãæãªãããšããªãããã«ããŸãã èªåãšååã®ãã¹ãã§ã¯ãåã¿ã¹ã¯ã«åæ¥ãã1æ¥ãããããšã瀺ãããŸããã ããã«ãèšèšã®ããã®æéãå ããŠã調æŽããŠã¹ã€ã³ã°ããŸãã ã€ãŸããååãªæéãããã¯ãã§ãããéå°ã§ã¯ãããŸããã
ãŸããç§ãã¡ã¯ã¿ã¹ã¯ã«ã€ããŠé転ããŸããã ã¹ãã€ã©ãŒã®äžã«é ããŠãã¹ããŒã¹ãåããŸããããã«ããŸãã
ãã±ããã«ã¬ã³ããŒãçæããåäžã®SQLã¯ãšãªãèšè¿°ããŸãã ã¿ã¹ã¯ã®ãã©ã¡ãŒã¿ãŒã«ã¯ãã«ã¬ã³ããŒã®å¹Žãšãæã®ãããªãã¯ã¹ã圢æããããã®è¡ãšåã®æ°ã瀺ãããŸãã ãã©ã¡ãŒã¿ã¯ã次ã®ã¯ãšãªã«ãã£ãŠèšå®ãããŸãã
with param(year, c, r) (âŠ)
ããã§ãããããã
- 幎-æŠå¹Ž
- cã¯ãã«ã¬ã³ããŒãããªãã¯ã¹ã®åæ°ã§ãã
- rã¯ãè¡åã®è¡æ°ã§ãã
æã¯ãã«ã¬ã³ããŒãããªãã¯ã¹ã®ã»ã«ã«å·Šããå³ãäžããäžã®é ã«é 眮ãããŸãã åæã®æ°åã¯ãææ¥ãæåã®åã®æåã®ææ¥ãªã©ã«ãããŸãã é±ã®åãã¯ããªã¯ãšã¹ããèµ·åãããæç¹ã®ããŒã¿ããŒã¹ããŒã«ãªãŒãŒã·ã§ã³èšå®ã«å¯Ÿå¿ããŠããå¿ èŠããããŸãã æã®ååãããŒã«ã©ã€ãºèšå®ããååŸãããæ°åã®äžã®äžå€®ã«è¡šç€ºãããŸãã é£æ¥ããæã®æ°ããäºãã«ãã£ã€ããªããããã«ãæã®éã«ã¯ã®ã£ãããæ®ãå¿ èŠããããŸãã æåã®è¡ã¯å¹Žã®äžå€®ã«è¡ãå¿ èŠããããŸãã 空è¡ããã£ãŠã¯ãªããŸããã
ããšãã°ã次ã®ãã©ã¡ãŒã¿ãŒã䜿çšããŸãã
with param(year, c, r) as (select 2016, 3, 4 from dual)
次ã®ã¯ãšãªåºåãååŸããå¿ èŠããããŸãã
2016 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 4 5 6 7 8 9 10 8 9 10 11 12 13 14 7 8 9 10 11 12 13 11 12 13 14 15 16 17 15 16 17 18 19 20 21 14 15 16 17 18 19 20 18 19 20 21 22 23 24 22 23 24 25 26 27 28 21 22 23 24 25 26 27 25 26 27 28 29 30 31 29 28 29 30 31 1 2 3 1 1 2 3 4 5 4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12 11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19 18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26 25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30 30 31 1 2 3 1 2 3 4 5 6 7 1 2 3 4 4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11 11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18 18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25 25 26 27 28 29 30 31 29 30 31 26 27 28 29 30 1 2 1 2 3 4 5 6 1 2 3 4 3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11 10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18 17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25 24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31 31
3ãªããã«ãš5ãªããã«ã®å®¹éãæã€2ã€ã®å®¹åšãšãæ°Žãå ¥ã£ãèå£ããããŸãã ãã容åšããå¥ã®å®¹åšã«æ°Žã移ãïŒãã®ãã¡ã®1ã€ããã£ã±ãã«ãªããã空ã«ãªããŸã§ïŒãæ°Žã泚ãïŒå®å šã«ã®ã¿ïŒãèå£ããäžéšãŸã§å®¹åšãæºãããŸãã æ£ç¢ºã«4ãªããã«ã枬å®ã§ãããã¹ãŠã®èŒžè¡ãªãã·ã§ã³ãèŠã€ããå¿ èŠããããŸãã ã«ãŒããåé¿ããããã«ãè¡ç®¡ã®å æºç¶æ ãç¹°ãè¿ããããªãã·ã§ã³ã¯ç Žæ£ãããŸãã
SQLã¯ãšãªã¯ãå¯èœãªãã¹ãŠã®èŒžè¡ãªãã·ã§ã³ã次ã®åœ¢åŒã§è¡šç€ºããå¿ èŠããããŸããåãªãã·ã§ã³ã«ã€ããŠãé©åãªã¹ãããã§å容åšã®æ°Žéã瀺ãæ°å€ã®ãã¢ã®åœ¢ã§èŒžè¡ãã§ãŒã³ãåºåããŸãã æ°åã¯ãã€ãã¹ã§åºåããããã¢ã¯ã³ã³ããšã¹ããŒã¹ã§åºåãããŸãã
äžè¬çãªæ¹æ³ã§åé¡ã解決ããå¿ èŠããããŸãããã©ã¡ãŒã¿ã¯ãæåã®v1ããã³2çªç®ã®v2è¡ç®¡ã®å®¹éãšã茞è¡ã®çµæãšããŠååŸããå¿ èŠãããresã®çµæãæå®ããŸãã æ¡ä»¶ã®äŸïŒ
with param(v1, v2, res) as (select 3, 5, 4 from dual)
åºåäŸïŒ
PATH --------------------------------------------------------------------------------- 0-0, 3-0, 3-5, 0-5, 3-2, 0-2, 2-0, 2-5, 3-4 0-0, 3-0, 0-3, 3-3, 3-5, 0-5, 3-2, 0-2, 2-0, 2-5, 3-4 0-0, 3-0, 0-3, 3-3, 1-5, 0-5, 3-2, 0-2, 2-0, 2-5, 3-4 ...
é ç¹ãšãšããžã§å®çŸ©ãããç¡åã°ã©ãããããŸãã ãšããžã®é·ããšéå§ããŒã¯ãšçµäºããŒã¯ã®ååãæå®ããŸãã 1ã€ã®SQLã¯ãšãªã§ã¯ãæåã®é ç¹ããæåŸã®é ç¹ãŸã§ã®æçè·é¢ã®ãã¹ãèŠã€ããå¿ èŠããããŸãã çµæã¯ã2ã€ã®å€ã®åœ¢åŒã§è¡šç€ºãããå¿ èŠããããŸãã
- ãã¹è¡ã§ã¯ãé ç¹ã®ååã¯ãã€ãã¹ã§ãªã¹ããããŸãã
- ãã¹ã®é·ãïŒãšããžã®é·ãã®åèšïŒã
æé ã®ãã¹é·ã§ãœãŒãããã3ã€ã®æçãªãã·ã§ã³ãå°åºããå¿ èŠããããŸãã åé¡ã®ç¶æ ã§ã¯ãé ç¹ã®ãã¢ãšãããã®éã®è·é¢ãèšå®ãããŸãïŒã°ã©ãã¯ç¡æåæ§ã§ãããè·é¢ã¯æåã®é ç¹ãã2çªç®ãžãããã³ãã®éã2çªç®ãã1çªç®ãžã®ç§»åã«ãæå¹ã§ãïŒãæçãã¹ãæ§ç¯ããããã®åæããã³æçµé ç¹ã
ã°ã©ãå ã®ãšããžã®æ°ã¯åççã«å¶éãããŠããã50ãšããžä»¥äžã§ãã
次ã®ãã¹ãããŒã¿ã«ã€ããŠïŒ
with edges (from_node, to_node, range) as ( select '', '-', 706 from dual union all select '', '', 516 from dual union all select '', '', 1793 from dual union all select '', '', 3956 from dual union all select '', '', 1345 from dual union all select '', '', 3356 from dual union all select '', ' ', 421 from dual union all select '', '', 6274 from dual union all select '', '', 856 from dual union all select '', '', 272 from dual union all select '', '', 3723 from dual union all select '', '', 4141 from dual union all select '', '', 666 from dual union all select '', '', 524 from dual union all select '', '', 9141 from dual union all select '', '', 237 from dual union all select '', '', 265 from dual union all select '', '', 146 from dual union all select '', ' ', 856 from dual union all select '', '', 1598 from dual union all select '', '', 2923 from dual union all select '', '', 790 from dual union all select '', '', 751 from dual union all select '', '', 2139 from dual union all select '', '', 2861 from dual ) , param(begin_node, end_node) as (select '', '' from dual)
次ã®çµæãåŸãããŸãã
PATH LEN -------------------------------------------------- ---------- --- 10480 ---- 10485 -- 10486
ç®è¡åŒã¯æååãšããŠæå®ãããŸãã åŒã®å€ãèšç®ããã«ã¯ã1ã€ã®SQLã¯ãšãªãå¿ èŠã§ãã ãã®åŒã«ã¯ãå ç®ãæžç®ãä¹ç®ãé€ç®ãã¹ãä¹ãåé ãã€ãã¹ãæ¬åŒ§ã®æŒç®ã®ç¬Šå·ãå«ãŸããŠããŸãã åé ãã€ãã¹ã¯ãåŒã®éå§æãŸãã¯éãæ¬åŒ§ã®åŸã«ã®ã¿çºçããŸãã æ°å€ã«ã¯å°æ°éšåãå«ãŸããå Žåãããã圢åŒã¯ããŒã¿ããŒã¹ã®çŸåšã®èšèªèšå®ã®NUMBERã¿ã€ãã«å®å šã«å¯Ÿå¿ããŸãã æ確ã«ããããã«ãåŒã«ã¯ã¹ããŒã¹æåãå«ããããšãã§ããŸãã åŒã®é·ãã¯åççã«å¶éãããŠããŸãã50ãªãã©ã³ã以äžãæ¬åŒ§ã®æ·±ãã¯20以äžã§ããåŒã¯åžžã«æ£ããã§ãã
èŠæ±ã¯ãNUMBER圢åŒã§åäžã®å€ãè¿ãå¿ èŠããããŸãã
ãµã³ãã«ãã¹ãããŒã¿ïŒ
with param(expr) as ( select '(-1 + 5^(1/2) ) / 2' from dual )
ãã®ããŒã¿ã«å¯Ÿããã¯ãšãªã®çµæã®äŸïŒ
VAL ------------------------------------------------- ,61803398874989484820458683436563811772
ã©ããªã³ã¹ã¯çªå·ä»ãã®è¡ã®åœ¢åŒã§èšå®ãããŸãã å£ã«ã¯ãïŒããå ¥å£ç¹ãsããåºå£ãeããä»ããŠããŸãã åœå¢ãè¶ããããšã¯äžå¯èœã§ãããè¡çªå·ã¯é çªã«é²ã¿ããã¹ãŠã®è¡ã®é·ãã¯åãã§ãã 1ã€ã®SQLã¯ãšãªã§ã¯ãæå "*"ã䜿çšããŠãå ¥åããåºåãžã®æçãã¹ïŒè€æ°ã®ãã¹ãããå Žåã¯ãã®ãã¡ã®1ã€ïŒãæç»ããå¿ èŠããããŸãã
è¿·è·¯ã®ãµã€ãºã¯å¶éãããŠãããããè¿·è·¯ãééããïŒå éšã«ãŒããªãïŒãªãã·ã§ã³ã®æ°ã¯10,000ãè¶ ããŸããã
ãµã³ãã«ãã¹ãããŒã¿ïŒ
with maze(linenum, line) as ( select 01,'## ### ######' from dual union all select 02,'s # # ' from dual union all select 03,'#### ### # ##### ' from dual union all select 04,' # # # ' from dual union all select 05,' # ### ######### ' from dual union all select 06,' # e' from dual )
ãã®ããŒã¿ã«å¯Ÿããã¯ãšãªã®çµæã®äŸïŒ
##***### ###### s**#* # ####*### # ##### #***# # # ###*######### # **********e
ãã¡ããããã£ãšæéãããã°ãã¿ã¹ã¯ãããã«æ¹åã§ããã ããã ããããããã¯ããªãããŸããããŸããã åã¿ã¹ã¯ã«ã¯ãç¬èªã®é©ããšèœãšãç©ŽããããŸããã
ããšãã°ãçªç¶ãã«ã¬ã³ããŒã«é¢ããæåã®ã¿ã¹ã¯ã¯éåžžã«éèŠã§ããã å°é£ã¯ãã§ã«åçã«çæããããããªãã¯ã¹ãåå ã§ãããçªç¶ãã¹ãŠã®äººããã®å¹Žã®ãã¹ãŠã®æ¥ãæ£ããçæã§ããããã§ã¯ãããŸããã ã¬ãã¬ããžãèæ ®ãããšãéåžžã¯365ãŸãã¯366ã§ãããããã1582幎ã«ã¯ãã°ã¬ãŽãªãªæŠã§10æ5æ¥ãã10æ14æ¥ãŸã§ã®æ¥ã¯ãããŸããã 1582幎ãæ£ããåŠçã§ããã®ã¯ããå°æ°ã§ãã ããã«ãç°ãªããã±ãŒã«ã®é±ã¯å¥ã®æ¥ã«å§ãŸããŸãã äºæ³å€ã®åŸ ã¡äŒããéåžžã«å€ãã£ããããæã®ååãæããŠã¬ãŒããèžã人ããããŸããã§ããã éäžã§æ éããããšãªãããã«å°éãããã¹ãŠã®äººã¯ãUTF8ãšã³ã³ãŒãã£ã³ã°ã§ééã£ãèªé·ãäžããé¢æ°ã䜿çšããŠããŸããã
ãé²è¡äžãã®åé¡çªå·3ã¯ãå·¡åã»ãŒã«ã¹ãã³åé¡ã®ããŒãã®ããªãšãŒã·ã§ã³ã§ãã æ®åœ±ãããéœåžã¯ãåœç€Ÿã®ä»£è¡šçãªãªãã£ã¹ãããéœåžã§ãããè·é¢ã¯ã¢ãã©ã¹ããã®éè·¯ã®é·ãã«å®éã«å¯Ÿå¿ããŠããŸãã ãã§ã«æ¡ä»¶ãéä¿¡ããã®ã§ããã¹ã®ãµã€ã¯ã«ã®æç¡ãæ瀺çã«èŠå®ããŠããªãããšãããããŸããã ã©ãããããããå·¡åã»ãŒã«ã¹ãã³ã®åé¡ã¯ãµã€ã¯ã«ã§è§£æ±ºã§ãããšèããããšã¯ããã«ã¯èµ·ãããŸããã§ããã æ€èšŒäžã«ãäž¡æ¹ã®ã¢ãããŒããæ£ãããšèŠãªãããå¿ èŠããããŸããã ãã ããåå è ããµã€ã¯ã«ãèš±å¯ããŠããå Žåã®ã¿ããã®ã¢ãããŒãã§é©åãªãœãªã¥ãŒã·ã§ã³ããã¹ãŠèŠã€ãããŸãã æ€èšŒãã¹ããå®äºããå¿ èŠããããŸããã äºæ³å€ã®ããšããããã¹ãŠã®åå è ãååž°ã®ãããªããã°ã©ãã³ã°ã®åºæ¬æŠå¿µã«ç²ŸéããŠããããã§ã¯ãªãããšãå€æããŸããã 1人ã®æ°žç¶çãªäººã®æ±ºå®ã§ã¯ãã¬ãã«11ãŸã§æ·±ããã¹ãããããšã«ãããååž°ãæåã§è¡ãããŸããã åé¡ã®ç¶æ ããã®ãã¹ãäŸãšããŠã¯ããã§ååã§ããããã¡ãããä»ã®ãã¹ãã¯äžåè¡ãããããããçš®é¡ã®ãšããŸããã¯ãªãã¹ããæ¡ç¹ããŸããã ãããèŠãã®ã¯é©ãã¹ãããšã§ãããSQLã§æžãåŠçãè¥ãå°é家ïŒãããŠããããæããã«æåã®ããã°ã©ãã³ã°èšèªã«ãªãããšã¯ã§ããŸããïŒã¯ãååž°ã«ã€ããŠç¥ã£ãŠããããå®è·µã§ãããšæããŸããã ããããªããã°ãããã°ã©ãã³ã°ã«ã¯ãŸã£ããæ¹æ³ããããŸããã
åé¡çªå·5ã®ãã©ããªã³ã¹ãã¯å人çã«ç§ã«ãšã£ãŠæãéæ³ã®ããã§ãããªãªã³ãã¢ãŒãã®ç¬¬2ã©ãŠã³ãå šäœããã€ã³ã¹ãã¬ãŒã·ã§ã³ãåããã®ã¯åœŒå¥³ã§ããã ãã ããæåã®4ã€ã®ã¿ã¹ã¯ã®åŸã§ãããããæ¢ã«ãã®çµæã¯çºçããŠããŸããã æ¡ä»¶ã§ã¯ããã¹ãŠã®ãªãã·ã§ã³ãåæããé¡ã®è§£æ±ºçãæ©èœããããšãæ確ã«èŠå®ããŸããã ãšããã§ãç§ãã¡ã¯ãã®å¶éãäžè¬ã«ã©ã®ããã«å®åŒåã§ããããé·ãéèããŠããŸããã å£ã®ãªã空ã®è¿·è·¯7x7ã¯ããããééããããã®ãªãã·ã§ã³ã®æ°ãå€ãããããã§ã«é·ãéèšç®ãããŠããŸãã äžæ¹ãå€æ°ã®å£ãæã€è¿·è·¯ïŒããã³ãããã«å¿ããŠå°æ°ã®éè·¯ãªãã·ã§ã³ïŒã¯ã60x60ã®ãµã€ãºã§ãã£ãŠãè¿ éã«è§£æ±ºãããŸãã ãã¡ããããã®åé¡ã解決ããããã«ãŠã§ãŒãã¢ã«ãŽãªãºã ã䜿çšããæ¹ãããé©åã§ãã ãã®æ¹æ³ã¯è¿ éã«æ©èœããæçãã¹ãæé©ã«èŠã€ããæããã«æªããªãã·ã§ã³ãç Žæ£ããŸãããå®è£ ã¯ããå°é£ã§ãã åå è ã®äžäººããã®ãã®ã¿ã¹ã¯ã®ä»éãã説æã§ãããã®èæ ®äºé ãèŠãã®ã¯éåžžã«æ¥œããã£ãã§ãã ããããWaveã¢ã«ãŽãªãºã ãå®è£ ãã人ã¯ããŸããã ããããç§ãã¡ãããããŸããã§ããã
ã¿ã¹ã¯çªå·4ã®ãèšç®æ©ãã¯ãæè¡çã«æãå°é£ãªãã®ã§ããã 2段éã®ã¢ãããŒããæ³å®ãããŠããŸããããŸããåŒãããæ¶åãããããã®ïŒPOLIZãŸãã¯ã¹ã¿ãã¯è¡šèšïŒã«å€æããŠãããçµæãèšç®ããŸãã å®éãããã決å®ããåå è
ã¯æãå°ãªãã£ãã äžéšã®äººã
ã¯ãæ£èŠè¡šçŸã䜿çšããŠè§£æ±ºãè©Šã¿ãæ°ããããå¥ã®éšååŒãé çªã«åãåºããŠèšç®å€ã«çœ®ãæããŸãããããã®ãããªå®è£
ã¯ãã¹ãŠèª€ã£ãŠã "(( (-(( ((((( - ( (-(-(-( ( - ((-,0-,0))) ) ))))) ) ) ))))) ) ) "
å®è£
ãäžå®å
šã§ãæååã䜿çšããŠSQLã¹ã¿ãã¯ãå®è£
ããå¿
èŠããããŸãããããã«ãããããŒã¿ããŒã¹å
ã®æååãã£ãŒã«ãã®é·ãã«é¢ããæè¡çãªå¶éã«ãããã¹ã¿ãã¯ã®ãã¹ãã®æ·±ããå¶éãããŸãã
茞è¡ã«é¢ããåé¡ïŒ2ã¯äŒæ¥ã®wikiããåã£ããã®ã§ãããã§ã¯ãã€ãŠç§ãã¡ã®ããã°ã©ããŒããç§ãã¡ã®ããã°ã©ããŒã«å¿ãæž©ããããã«æäŸãããŠããŸããã æåã«ããŸããŸãªå€å žçãªããã°ã©ãã³ã°èšèªã§è§£æ±ºãã次ã«ãšããŸããã¯ã§é£è§£ãªãã®ïŒããšãã°BrainfuckïŒã§è§£æ±ºããæåŸã«å®£èšçã«SQLã§è§£æ±ºããŸããã ãªãªã³ããã¯ã§ãã®ãããªããèããããä»äºã䜿ããªãã®ã¯çœªã ã£ãã
Brainfuckãšããã°ã ã¿ã¹ã¯ãæºåããéçšã§ãbrainfuckã€ã³ã¿ãŒããªã¿ãŒã¯åäžã®SQLã¯ãšãªã«å®è£ ãããŸããã ååã«é¢é£ãããããŸãããé¿ããŠãã¿ã¹ã¯ã§ãããæ瀺ãå§ããŸããã§ããã ããã§ãããããå®çŸå¯èœã§ãããšãã確èªãããäºå®ããããŸãã åžæãã人ã¯ç¹°ãè¿ãããšãã§ããŸãã
ã¿ã¹ã¯ãèãåºãããšã¯ã解決ããããšããããã£ãšæ¥œãããšæããŸãã çºæã®éçšã§ãããã解決ããããšãå¿ èŠã§ããã ãŸããåé¡ã®è§£æ±ºçãååšããããšã確èªããå¿ èŠããããŸããã 第äºã«ãé åçãªã³ã³ããŒãã³ããå¯èœãªéãæ®ããå¯èœã§ããã°äžèŠãªã«ãŒãã³ãåé€ããããã«ãæ¡ä»¶ã解決ããããã»ã¹ã§æå®ãããŸããã ãã®åŸãåå è ãå®å¹ŽãŸã§ç£æ¥çšããã°ã©ãã³ã°ã®ã«ãŒãã³ã«åå ã§ããããã«ããŸãã ããã«ãéäžã§ãããããçš®é¡ã®éèªææ§ãæµ®äžããŸããã ãããŠç¬¬äžã«ãæ€èšŒäžã«åå è ã®æ±ºå®ãæ¯èŒããããã®åç §ãœãªã¥ãŒã·ã§ã³ãå¿ èŠã§ããã
ã¿ã¹ã¯ã¯ãæ倧ã³ãŒãã§10ãã€ã³ããä»éãã説æã§10ãã€ã³ãã§è©äŸ¡ãããŸããã ã³ãŒãã¯æºåãããããŒã¿ã»ããã§å®è¡ãããæåã®ããŒã¿ã»ããã¯åžžã«ã¿ã¹ã¯ã®ç¶æ ã«ãã£ããã®ã§ããã ã€ãŸããåé¡ã®ç¶æ ããã®ããŒã¿ã«é¢ããæ£ããçµæã¯ãå°ãªããšã1ã€ã®ãã€ã³ããäžããŸããã ææžåã¯é£ããã客芳çã«ïŒå°ãªããšãæ£åŒã«å®¢èŠ³çã«ïŒè©äŸ¡ããããšã«ã¯åé¡ããããŸããã 2ã€ã®ç°ãªããœãªã¥ãŒã·ã§ã³ãæ¯èŒãããšãã«ãããå€ãã®ãã€ã³ãã§ããè¯ãããã¥ã¡ã³ããè©äŸ¡ãããããã«è©Šã¿ãŸããã
æåºãããäœåã§ã¯ãåäžã®ãœãªã¥ãŒã·ã§ã³ã®2ã€ã®ã¯ã©ã¹ã¿ãŒãèŠã€ãããŸããã ããã¯ãã¡ããããããã¯åã ã®ã·ã³ãã«ãšã©ããå¥ã®åèªã§ããç°ãªã£ãŠããŸããã ãããŠãå°ãæžåŒèšå®ããŸãã ããããããããåäžã§ããããšãæããã§ããã å®éãåå è ã¯ãäºããçžæ®ºãããåã«åé¡ãäžç·ã«è§£æ±ºãããšæããŸãã ããããç§ãã¡ã¯ããããã®ãã°ã«ç«ã£ãŠãããããœãªã¥ãŒã·ã§ã³ã®æ¬åœã®äœè ã誰ã§ã誰ãåã«æžãçŽããã®ãããããªãã£ãã®ã§ãçäœã®çè·¡ã§ãã¹ãŠã®äœåãå€±æ Œã«ããªããã°ãªããŸããã§ããã ãªã圌ãã¯ããã€ãã®çãã§åã解決çãéã£ãã®ã§ããïŒ èª°ãæ°ä»ããªããšæ¬åœã«æã£ãïŒ äººãæ¹å€çã«èããèœåãå®å šã«å€±ããšãã«ã人ã ã«ãã®ãããªå¥åŠãªè¡åã«åºäŒã£ãã®ã¯ãããåããŠã§ã¯ãããŸããã ããŠã圌ã®è©å€ã確èªãã責任ããããªãªã³ãã¢ãŒãã®äž»å¬è ã¯ã圌ãåãèŠæ±ã«çŽé¢ããŠããããšãç解ã§ããªãã§ããããïŒ ããŠã2人ã®ç°ãªã人ããã¹ãŠã®äžéããŒãã«ãšãã®äžã®ãã£ãŒã«ããåãååã§èŠã€ããããšã¯ã§ããŸããã ãããŠãåæ§ã®ãã®ã§ãã£ãŠãã§ããªãã
æè¡èšèšã«é¢ããããã€ãã®èšèã åå è ã¯ãèªåãã¹ãã®ããã«ã¹ã¯ãªããã®äžããSQL * PLUSã§å®è¡ãããã¡ã€ã«ãæºåããå¿ èŠããããŸããã ã«ããã®äžã®è©³çŽ°ããããã誰ããèå³ãããããã§ã¯ãããŸããã
ãœãªã¥ãŒã·ã§ã³ã¯ãå€éšã©ãããŒã¹ã¯ãªããããèµ·åãããå¥ã®ãã¡ã€ã«ã§å®è¡ããããšã§ããã ããã¯ãã¿ã¹ã¯ãã©ã¡ãŒã¿ãŒãšãœãªã¥ãŒã·ã§ã³ãåé¢ããããã«è¡ãããŸããã "with params as (select 1,2,3 from dial)"
ãšãã圢åŒã®ãã©ã¡ãŒã¿ã¯ãå€éšã¹ã¯ãªããã«ãããŸããã 次ã«ã©ãããŒã¹ã¯ãªããã®äŸã瀺ããŸãã
set pagesize 999 linesize 999 numwidth 50 trimspool on trimout on set heading off verify off feedback off set serveroutput on size 999999 whenever sqlerror exit spool taskX.log -- test dataset here with param(num) as (select 10 from dual) @taskX.sql / exit
次ã«ã taskX.sqlã¹ã¯ãªãããå®è¡ãããåºåãtaskX.logãã¡ã€ã«ã«èšé²ãããŸãã
param.numã§æå®ãããæ°å€ã®éä¹ãèæ ®ããtaskX.sqlãœãªã¥ãŒã·ã§ã³ã¹ã¯ãªããã®å 容ã¯æ¬¡ã®ãšãã ã§ã ã
-- = IT Planet, SQL 2016/17 = -- = Task X (Sample) = -- -- with param(num) as (select 10 from dual) , seq(n, fact) as ( select 1, 1 from dual union all select n+1, fact*(n+1) from seq, param where n < param.num ) select fact as factorial from seq, param where n = num
ãã®ããã«ç¹å¥ã«æºåããããã¹ãŠã®ãã¹ãããŒã¿ã§å®è¡ãããã¹ã¯ãªãããäœæããããçµæãèŠãŠããåç §ããœãªã¥ãŒã·ã§ã³ãšæ¯èŒã§ããŸãã
ç»é²æã®ãšã©ãŒã®æ°ãæžããããã«ããã¹ãŠã®ã¿ã¹ã¯ã®ãã³ãã¬ãŒããã¡ã€ã«ïŒ ã¿ã¹ã¯[1,2,3,4,5] .sqlãã¡ã€ã« ïŒããã³ãããã«å¯Ÿå¿ããã ã©ã³ãã£ãŒ ããšã¿ã¹ã¯æ¡ä»¶ããã®ãã¹ãããŒã¿ãæºåãããåå è ã«éä¿¡ãããŸããã åé¡ã解決ããããã®ãã¹ãã±ãŒã¹ãäœæãããéä¿¡ãããŠããã¹ãŠãã©ã®ããã«èŠãããã瀺ãããŸããã ããã¯åãéä¹ã§ãããããé«ãã§ãã
åè¿°ããããã«ã2å確èªããŸããã æåã®ãã¹ãå®è¡ãšçµæã®åæã®åŸãã¿ã¹ã¯ã®ãã¹ãã®ããã€ããæ確ã«ããå¿ èŠãããããšãå€æããŸããã ãããŠãç§ãã¡ãäžããªãã£ã決å®ã®åæäžã«æããã«ãªã£ãããã€ãã®é©ããã«ããŒããããã«ãæ°ãããã®ãäœãããšã®äžéšã ãã®åŸã2人ãç¬ç«ããŠææ決å®ã®å®å šãªãã§ãã¯ãè¡ãããã®åŸããã¹ãŠã®äžäžèŽã®åæãšå®å šã«èª¿æŽããŸããã
æçµãããã³ã«ã¯é·ãéæ€èšŒãããŸããããç§ã®æèŠã§ã¯ãåå è ã®æ£ããã©ã³ãã³ã°ãå®å šã«åæ ããŠããŸããã æ¬åœã«å·šå€§ãªäººéã決åã«é²åºããŸããã
ç¶ãïŒ èšäºã®ããªã¥ãŒã ã¯å€§ãããªãã第2éšã§ç¶ããŸãã ã
PSãã®æ©äŒãå©çšããŠããã®ãªãªã³ãã¢ãŒãã®äœæãèšèšãããã³è¡åã«åå ããŠãããååã«æè¬ããŸãã ãšãŽãŒã«ãæ å ããã·ã£ãã¢ã«ãã§ãŒã -ããªããæåã