SQLν´Ê
1¡¢Î½´Ê ν´ÊÔÊÐíÄú¹¹ÔìÌõ¼þ£¬ÒÔ±ãÖ»´¦ÀíÂú×ãÕâЩÌõ¼þµÄÄÇЩÐС£
2¡¢Ê¹Óà IN ν´Ê
ʹÓà IN ν´Ê½«Ò»¸öÖµÓëÆäËû¼¸¸öÖµ½øÐбȽϡ£ÀýÈ磺
SELECT NAME from STAFF WHERE DEPT IN (20, 15)
´ËʾÀýÏ൱ÓÚ£º
SELECT NAME from STAFF WHERE DEPT = 20 OR DEPT = 15
µ±×Ó²éѯ·µ»ØÒ»×éֵʱ£¬¿ÉʹÓà IN ºÍ NOT IN ÔËËã·û¡£ÀýÈ磬ÏÂÁвéѯÁгö¸ºÔðÏîÄ¿ MA2100 ºÍ OP2012 µÄ¹ÍÔ±µÄÐÕ£º
SELECT LASTNAME from EMPLOYEE WHERE EMPNO IN (SELECT RESPEMP from PROJECT WHERE PROJNO='MA2100' OR PROJNO='OP2012')
¼ÆËãÒ»´Î×Ó²éѯ£¬²¢½«½á¹ûÁбíÖ±½Ó´úÈëÍâ²ã²éѯ¡£ÀýÈ磬ÉÏÃæµÄ×Ó²éѯѡÔñ¹ÍÔ±±àºÅ 10 ºÍ 330£¬¶ÔÍâ²ã²éѯ½øÐмÆË㣬¾ÍºÃÏó WHERE ×Ó¾äÈçÏ£º
WHERE EMPNO IN (10, 330)
×Ó²éѯ·µ»ØµÄÖµÁбí¿É°üº¬Áã¸ö¡¢Ò»¸ö»ò¶à¸öÖµ¡£
3¡¢Ê¹Óà BETWEEN ν´Ê
ʹÓà BETWEEN ν´Ê½«Ò»¸öÖµÓëij¸ö·¶Î§ÄÚµÄÖµ½øÐбȽϡ£·¶Î§Á½±ßµÄÖµÊÇ°üÀ¨ÔÚÄڵģ¬²¢¿¼ÂÇ BETWEEN ν´ÊÖÐÓÃÓڱȽϵÄÁ½¸ö±í´ïʽ¡£
ÏÂһʾÀýÑ°ÕÒÊÕÈëÔÚ $10,000 ºÍ $20,000 Ö®¼äµÄ¹ÍÔ±µÄÐÕÃû£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY BETWEEN 10000 AND 20000
ÕâÏ൱ÓÚ£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY >= 10000 AND SALARY <= 20000
ÏÂÒ»¸öʾÀýÑ°ÕÒÊÕÈëÉÙÓÚ $10,000 »ò³¬¹ý $20,000 µÄ¹ÍÔ±µÄÐÕÃû£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY NOT BETWEEN 10000 AND 20000
4¡¢Ê¹Óà LIKE ν´Ê
ʹÓà LIKE ν´ÊËÑË÷¾ßÓÐijЩģʽµÄ×Ö·û´®¡£Í¨¹ý°Ù·ÖºÅºÍÏ»®ÏßÖ¸¶¨Ä£Ê½¡£
Ï»®Ïß×Ö·û(_)±íʾÈκε¥¸ö×Ö·û£¬°Ù·ÖºÅ(%)±íʾÁã»ò¶à¸ö×Ö·ûµÄ×Ö·û´®¡£
ÈκÎÆäËû±íʾ±¾ÉíµÄ×Ö·û¡£
ÏÂÁÐʾÀýÑ¡ÔñÒÔ×Öĸ\'S\'¿ªÍ·³¤¶ÈΪ 7 ¸ö×ÖĸµÄ¹ÍÔ±Ãû£º
SELECT NAME from STAFF WHERE NAME LIKE \'S_ _ _ _ _ _\'
ÏÂÒ»¸öʾÀýÑ¡Ôñ²»ÒÔ×Öĸ\'S\'¿ªÍ·µÄ¹ÍÔ±Ãû£º
SELECT NAME from STAFF WHERE NAME NOT LIKE \'S%\'
5¡¢Ê¹Óà EXISTS ν´Ê
¿ÉʹÓÃ×Ó²éѯÀ´²âÊÔÂú×ãij¸öÌõ¼þµÄÐеĴæÔÚÐÔ¡£ÔÚ´ËÇé¿öÏ£¬Î½´Ê EXISTS »ò NOT EXISTS ½«×Ó²éѯÁ´½Óµ½Íâ²ã²éѯ¡£
µ±Óà EXISTS ν´Ê½«×Ó²éѯÁ´½Óµ½Íâ²ã²éѯʱ£¬¸Ã×Ó²éѯ²»·µ»ØÖµ¡£Ïà·´£¬Èç¹û×Ó²éѯµÄ»Ø´ð¼¯°üº¬Ò»¸ö»ò¸ü¶à¸öÐУ¬Ôò EXISTS ν´ÊΪÕ棻Èç¹û»Ø´ð¼¯²»°üº¬ÈκÎÐУ¬Ôò EXISTS ν´ÊΪ¼Ù¡£
ͨ³£½« EXISTS ν´ÊÓëÏà¹Ø×Ó²éѯһÆðʹÓá£ÏÂÃæʾÀýÁгöµ±Ç°ÔÚÏîÄ¿(PROJECT) ±íÖÐûÓÐÏîµÄ²¿ÃÅ£º
SELECT DEPTNO, DEPTNAME from DEPARTMENT X WHERE NOT
Ïà¹ØÎĵµ£º
ÏÖÒªÇó²éѯ½çÃ棺²»ÂÛ15λ»òÕß18λÉí·ÝÖ¤ºÅ¶¼Äܲéѯ³öÊý¾Ý¿âÖÐËùÓе±Ç°Óû§ÐÅÏ¢¡£
·½°¸1£º
create or replace function CONVERT_ID_15 (/*ת»»Éí·ÝÖ¤ºÅΪ15λ*/
p_id2 in varchar2
) return varchar2
is
p_id varchar2(20);
id varchar2(15);
begin
p_id:=ltrim(p_id2);
p_id ......
»ùÓÚSQL Server ·ÖÒ³´æ´¢¹ý³ÌµÄÑݽø ÊÕ²Ø
Õë¶ÔÊý¾Ý¿âÊý¾ÝÔÚUI½çÃæÉϵķÖÒ³ÊÇÀÏÉú³£Ì¸µÄÎÊÌâÁË£¬ÍøÉϺÜÈÝÒ×ÕÒµ½¸÷Ö֓ͨÓô洢¹ý³Ì”´úÂ룬¶øÇÒÓÐЩ»¹¶¨ÖƲéѯÌõ¼þ£¬¿´ÉÏȥʹÓúܷ½±ã¡£±ÊÕß´òËãͨ¹ý±¾ÎÄÒ²À´¼òµ¥Ì¸Ò»Ï»ùÓÚSQL SERVER 2000µÄ·ÖÒ³´æ´¢¹ý³Ì£¬Í¬Ê±Ì¸Ì¸SQL SERVER 2005Ï·ÖÒ³´æ´¢¹ý³ÌµÄÑ ......
Ò»Ö±¶¼ÏëÕÒ¸öʱ¼äÑо¿Ò»Ï£¬½ñÌ컨ÁËÒ»Ììʱ¼äȥʵ¼ùÁËһϣ¬·Ç³£ÓÐÓ᣿ÉÒÔ˵ÊÇÊý¾Ý¿âÀïÃæµÄ¾«»ª°É¡£»¹ºÃÎÒ½ñÌìȥŪÁ˼¸Ï£¬Ëä˵¶¼ÊÇЩ¼òµ¥µÄÓï¾ä£¬µ«ÊÇ×îÆðÂëÖªµÀÒÔºóÔÚÏîÄ¿¸ÃÔõôȥ×öÁË¡£ Ïл°ÉÙ˵¡£½øÈëÕýÌâ¡£
1.´´½¨SQL´æ´¢¹ý³Ì:
CREATE PROCEDURE stu_proc1//Ö¸¶¨¹ý³ÌÃû
@Sno varc ......