SQLÓïÑÔµÄCASEʹÓÃ×ܽá
ת×Ôhttp://lavasoft.blog.51cto.com/62575/23373
SQLÓïÑÔµÄCASEÓï¾ä±¸Íü
¸ÅÊö£º
SQLÓï¾äÖеÄCASEÓï¾äÓë¸ß¼¶ÓïÑÔÖеÄswitchÓï¾ä£¬ÊDZê×¼SQLµÄÓï·¨£¬ÊÊÓÃÓëÒ»¸öÌõ¼þÅжÏÓжàÖÖÖµµÄÇé¿öÏ·ֱðÖ´Ðв»Í¬µÄ²Ù×÷¡£Áé»îÓ¦ÓÃCASEÓï¾ä¿ÉÒÔʹSQLÓï¾ä±äµÃ¼ò½àÒ׶Á£¬ÏÂÃæÔÚDB2»·¾³ÏÂͨ¹ýÒ»¸ö¼òµ¥µÄ²éѯÀ´Õ¹Ê¾SQL CASEÓï¾äµÄÇ¿´ó¹¦ÄÜ¡£
»·¾³£º
Windows XP Professional
DB2 V9.1
ÎÊÌ⣺
ÓÐÒ»¸öÐÐÒµ´úÂë±í£¬½¨±íSQLºÍÊý¾ÝÈçÏ£¬ÒªÇó²é³ö´úÂë±ðÃû¡¢´úÂëÃû¡¢ÐÐÒµÃû¡¢´úÂ볤¶È¡£´úÂë±ðÃûΪÊý×ÖÐòºÅÓë´óдӢÎÄ×ÖĸµÄÐòºÅµÄÓ³ÉäÖµ£¬±ÈÈç´úÂë '01'µÄ±ðÃû¾ÍÊÇ'A','02'µÄ±ðÃû¾ÍÊÇ'B',ÒÀ´ÎÀàÍÆ¡£
½¨±íSQLºÍ³õʼ»¯Êý¾ÝSQL
-------------------------------------
drop table DM_HYML;
create table DM_HYML
(
HYML_DM CHAR(2) not null,
HYML_MC VARCHAR(100) not null,
XYBZ CHAR(1) not null
);
alter table DM_HYML
add primary key (HYML_DM);
comment on table DM_HYML is
'ÐÐÒµÃÅÀà´úÂë±í';
comment on column DM_HYML.HYML_DM is
'ÐÐÒµÃÅÀà´úÂë';
comment on column DM_HYML.HYML_MC is
'ÐÐÒµÃÅÀàÃû³Æ';
comment on column DM_HYML.XYBZ is
'Ñ¡ÓñêÖ¾';
delete from DM_HYML;
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('01', 'Å©¡¢ÁÖ¡¢ÄÁ¡¢ÓæÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('03', 'ÖÆÔìÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('02', '²É¿óÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('04', 'µçÁ¦¡¢È¼Æø¼°Ë®µÄÉú²úºÍ¹©Ó¦Òµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('05', '½¨ÖþÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('06', '½»Í¨ÔËÊä¡¢²Ö´¢ºÍÓÊÕþÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('07', 'ÐÅÏ¢´«Êä¡¢¼ÆËã»ú·þÎñºÍÈí¼þÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('08', 'Åú·¢ºÍÁãÊÛÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('09', 'סË޺ͲÍÒûÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
Ïà¹ØÎĵµ£º
²Ù×÷·ûÓÅ»¯
IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģ¬´ÓORACLEÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃINµÄSQLÓë²»ÓÃINµÄSQLÓÐÒÔÏÂÇø±ð£º
ORACLEÊÔͼ½«Æäת»»³É¶à¸ö±íµÄÁ¬½Ó£¬Èç¹ûת»»²»³É¹¦ÔòÏÈÖ´ÐÐINÀïÃæµÄ×Ó²éѯ£¬ÔÙ²éѯÍâ²ãµÄ±í¼Ç¼£¬Èç¹ûת»»³ ......
¹ØÓÚSQL×¢Èë(SQL Injection)µÄ·½·¨Æäʵ¶¼ºÜÆÕ±éºÍʹÓ㬹éÄÉÆðÀ´Ò²ºÜ·½±ã¡£Ò»°ã“ºÚ¿Í”ʹÓõÄÊÇÏֳɵŤ¾ßÈç“WEBÅÔ×¢¡¢°¢DÍøÂ繤¾ß°ü¡¢½ÌÖ÷XXX”µÈÕâЩ¶¼ÊǼ¯³ÉÁË
һЩ³£ÓõÄsql×¢ÈëÓï¾ä¡£ÏÂÃæÎÒ½«½éÉÜÈçºÎʹÓÃÊÖ¹¤×¢ÈëMYSQL,MSSQLÊý¾Ý¿â.
Ò»°ã©¶´²ú ......
ΪÁËÑо¿Ò»ÏÂϵͳÔÚºǫ́¶¼¸ÉÁËʲô£¬µ±È»ÊÇÎÒÔÚ´úÂëÀïûÕÒµ½µÄÇé¿öÏ£¬Ñо¿ÁËÒ»ÏÂtrace£¬½á¹ûÓÐÒ»¶¨µÄ°ïÖú¡£oracleÖв»Ïñsql serverÖÐÄÇÑùÖ±½ÓÌṩͼÏñ»¯µÄ¹¤¾ß£¬ËùÒÔ»¹ÊǵÃ×Ô¼º¶¯ÊÖÀ´×ö£¬¹éÄÉÁËһϣ¬²½ÖèÈçÏ£º
²éѯsession£º
SQL> select sid, serial#, username from v$session where username='XXX';//ÕÒ³öÄãÒª¸ú ......
--»ù´¡Á˽⣺
1) select distinct name from table --´ò¿ªÖظ´¼Ç¼µÄµ¥¸ö×Ö¶Î
2) select * from table where fid in(Select min(fid) from table group by name)--´ò¿ªÖظ´¼Ç¼µÄËùÓÐ×Ö¶ÎÖµ
3) select * from table where name in(select name from table group by name having count(name)=1)--´ò¿ªÖظ´ÈÎÒâ´ÎÊýµ ......
¹«Ë¾Óиö±¨±íϵͳÏìÓ¦ËٶȲ»ÊǺÜÀíÏ룬µ÷Óŵ÷Á˺ü¸´Î£¬ÓеãЧ¹û£¬µ«²»ÊǺÜÈÃÈËÂúÒâ¡£×î½üÓÖ¿ªÊ¼µ÷ÓÅ£¬ÊÔÁËÊÔsql server 2008µÄ·ÖÇø±í¹¦ÄÜ£¬¿´¿´ÊDz»ÊÇ·ÖÇøÖ®ºóËٶȿÉÒÔ¿ìÒ»µã¡£
ÓÃÁËÒ»¸ö°ÙÍò¼¶Êý¾ÝµÄ»ã×ܱíÀ´×ö·ÖÇø£¬·ÖÇøµÄÏë·¨ÊÇ°´ÔÂÀ´·ÖÇø£¬Ò»¸ö·ÖÇø´æ´¢Ò»¸öÔµÄÊý¾Ý£¬Ò»¸ö·ÖÇøµ ......