ã ãã¶åã«å¾³ä¸¸ããããæååããæ°å¤ã¸ã®æé»ã®åå¤æã«ã¤ãã¦ã¾ã¨ãã¦ãã¾ãã
数値リテラルをシングルクォートで囲むことの是非 - ockeghem's blog
徳丸ããã®æ¥è¨ã«ã¯ãOracle, MS SQL Server, MySQL, PostgreSQLã®4ã¤ã®DBMSã対象ã«ãæé»ã®åå¤æãèµ·ããããå®éã«èª¿ã¹ãçµæãæ¸ããã¦ãã¾ãã
ç§ãæãã¨ãããå²ã¨ã¡ã¸ã£ã¼ãªDBMSã§ç¶²ç¾ ããã¦ããªãã®ã¯DB2ã§ãã
ã¨ããããã§ãä»æ¥ã®æ¥è¨ã§ã¯DB2ã®æåã«ã¤ãã¦æ¸ãã¾ãã
ä¸ã¯ãDB2 V9.5ã§ã®åä½ã§ãã
[db2inst1@localhost ~]$ db2 "SELECT * FROM staff WHERE id=10" ID NAME DEPT JOB YEARS SALARY COMM ------ --------- ------ ----- ------ --------- --------- 10 Sanders 20 Mgr 7 98357.50 - 1 ã¬ã³ã¼ããé¸æããã¾ããã [db2inst1@localhost ~]$ db2 "SELECT * FROM staff WHERE id='10'" SQL0401N æ¼ç® "=" ã®ãªãã©ã³ãã®ãã¼ã¿ã»ã¿ã¤ãã«äºææ§ãããã¾ããã SQLSTATE=42818
DB2ã§ã¯ãæååããæ°å¤ã¸ã®ãæé»ã®åå¤æãã¯è¡ãªãããªãããã§ããæ°å¤ãã·ã³ã°ã«ã¯ã©ã¼ãã§å²ãã æååã¨ãæ°å¤ã¨ãæ¯è¼ãããªã©ããã¨ãSQLã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãã
SQLzooã¨ãããµã¤ãã«DB2 V8.2ã®ç°å¢ãããã¾ãããããã§è©¦ãã¦ãåããããªçµæã«ãªãã¾ãã
話ã¯ããã¾ãããSQLZooã«ã¯ãMySQL5ãPostgreSQL8ãSQL Server 2005ãOracle10gãDB2 V8ã®ç°å¢ãããé常ã«ä¾¿å©ã§ããæ¬å½ã¯ãã¼ã¿ãã¼ã¹åå¿è ã®ããã®SQLæã®å¦ç¿ãµã¤ããªã®ã§ãããå ¨ç¶éãç¨éã§æç¨ãã¦ãã¾ãã
ï¼ï¼ï¼ï¼
徳丸ããã®è¡¨ã«åæã«è¿½å ããã¦ãããã¨ã以ä¸ã®ããã«ãªãã¾ãï¼èµ¤åã®é¨åã¯ç§ã追å ããã¨ããã§ãï¼ã
å¤ | Oracle | MS SQL | MySQL | PostgreSQL | DB2 | |
insert | 1 | â | â | â | â | â |
1.0 | â | â | â | â | â | |
1.6 | åæ¨äºå ¥ | åæ¨ã¦ | åæ¨äºå ¥ | åæ¨äºå ¥ | åæ¨ã¦ | |
'1' | â | â | â | â | ã¨ã©ã¼(*7) | |
'1.0' | â | ã¨ã©ã¼(*3) | â | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*7) | |
'1.6' | åæ¨äºå ¥ | ã¨ã©ã¼(*3) | åæ¨äºå ¥ | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*7) | |
'1a' | ã¨ã©ã¼(*1) | ã¨ã©ã¼(*3) | ã¨ã©ã¼(*4) | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*7) | |
where | 1 | â | â | â | â | â |
1.0 | â | â | â | â | â | |
1.6 | â(*2) | â(*2) | â(*2) | â(*2) | â(*2) | |
'1' | â | â | â | â | ã¨ã©ã¼(*8) | |
'1.0' | â | ã¨ã©ã¼(*3) | â | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*8) | |
'1.6' | â(*2) | ã¨ã©ã¼(*3) | â(*2) | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*8) | |
'1a' | ã¨ã©ã¼(*1) | ã¨ã©ã¼(*3) | â(*5) | ã¨ã©ã¼(*6) | ã¨ã©ã¼(*8) |
*1 ORA-01722: æ°å¤ãç¡å¹ã§ãã
*2 1.6ã¨ä¸è´ããé
ç®ããªã
*3 varchar ã®å¤ '1.0' ããã¼ã¿å int ã«å¤æã§ãã¾ããã§ããã
*4 ERROR 1265 (01000): Data truncated for column 'num1' at row 1
*5 æ°å¤1ã¨è§£éããã
*6 invalid input syntax for integer: "1.0"
*7 SQL0408N å¤ã«ã¯ããã®å²ãå½ã¦ã¿ã¼ã²ããã®ãã¼ã¿ã»ã¿ã¤ãã¨ã®äºææ§ãããã¾ããã ã¿ã¼ã²ããå㯠"**" ã§ããSQLSTATE=42821
*8 SQL0401N æ¼ç® "="ã®ãªãã©ã³ãã®ãã¼ã¿ã»ã¿ã¤ãã«äºææ§ãããã¾ãããSQLSTATE=42818
ãã®æ©ä¼ã«sqliteã調ã¹ã¦ã¿ã¾ããããé常ã«å¥å¦ãªçµæã«ãªãã¾ãããä¾ãã°ãIntegerã§å®ç¾©ããã«ã©ã ã«ã1aãã¨ããå¤ãINSERTæã§çªã£è¾¼ãã¨ãã1aãã®ã¾ã¾å¤ãä¿åããã¦ãã¾ãã¾ãã
ï¼åèï¼http://www.tuyudaku.net/sqlite/datatype.html
sqliteã¯ãã©ããåããããããªç¡ããããªâ¦ 風å¤ãããªDBã®ããã§ãã