ÔõÑùÓÃSQLÓï¾äÅжÏÒ»¸öÊý¾Ý±íÖÐÖÁÉÙNÏΪ¿Õ£¿£¿£¿
ǰÁ½ÌìÒ»¸öѧ½ãÎÊÎÒ¸öSQLÓï¾äµÄÎÊÌ⣬ÏÖÔڰѽâ¾ö·½°¸Ìù³öÀ´£¬Ò²Ëã×ܽáһϰɡ£
ËýµÄÎÊÌâÊÇ£º“Ò»¸ö±íÖÐÓÐ15¸ö×ֶΣ¬ÓÃSQLÓï¾äÅÐ¶ÏÆäÖÐ5Ïî»òÒÔÉϲ»Îª¿Õ£¬ÔõôÅжϣ¬ºÜ¼±……”¡£
µ±Ê±Î񼆾£¬Ã»¶à¿´£¬ºÇºÇ£¬²»¹»Òâ˼À²¡£µ«ÎÒÇëͬʰïËýдÁ˸ö£¬ÒÔ½âȼü֮¼±£¬ÔÚ´ËҲллСÃס£
½ñÌìÔÙ°ÑQQÁÄÌì¼Ç¼·³öÀ´£¬Óñ¾µØÊý¾Ý¿âÊý¾Ý±íÊÔÑéÁËÏ£¬ ÓеãÎÊÌ⣬ÓÚÊÇ×Ô¼ºÐ޸ġ£
¡¾ÏêϸÇé¿ö£¬Çë²Î¿¼SQL Server Áª»ú´ÔÊé:Ë÷Òý“CASE‘£»
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.zh-CHS/s10de_6tsql/html/658039ec-8dc2-4251-bc82-30ea23708cee.htm¡¿
¡¾
select distinct (case bulletinId when bulletinId then 1 else 0 end) +
(case title when title then 1 else 0 end) +
(case body when body then 1 else 0 end) +
(case bulletinType when bulletinType then 1 else 0 end) +
(case bulletinState when bulletinState then 1 else 0 end) +
(case companyId when companyId then 1 else 0 end) +
(case userId when userId then 1 else 0 end) +
(case createtime when createtime then 1 else 0 end) as '²»Îª¿Õ×Ö¶ÎÊý' from bulletin
¡¿
µ±Êý¾Ý±íbulletinÖÐÖÁÉÙÓÐÒ»Ìõ¼Ç¼ʱ£¬Ò²¿ÉÒÔ²ÉÈ¡ÏÂÃæµÄ·½·¨¡£
¡¾
1¡¢¼òµ¥ CASE º¯Êý
select * from bulletin where
(case bulletinId when bulletinId then 1 else 0 end) +
(case title when title then 1 else 0 end) +
(case body when body then 1 else 0 end) +
(case bulletinType when bulletinType then 1 else 0 end) +
(case bulletinState when bulletinState then 1 else 0 end) +
(case companyId when companyId then 1 else 0 end) +
(case userId when userId then 1 else 0 end) +
(case createtime when createtime then 1 else 0 end) >= 5
2¡¢CASE ËÑË÷º¯Êý
select * from bulletin where
(case when bulletinId is not null or bulletinId!='' then 1 else 0 end) +
(case when title is not null or title!='' then 1 else 0 end) +
(case when body is not null or body!='' then 1 else 0 end) +
(case when bulletinType is not null or bulletinType!='' then 1 else 0 end) +
(case when bulletinState is not null or bulletinState!='' then 1 else 0 end) +
(case when companyId is not
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......
create or replace procedure c
(
v_deptno in emp.deptno%type,
v_max out emp.sal%type
)
as
begin
select max(sal+nvl(comm,0)) into v_max from emp where deptno=v_deptno;
end;
create or replace procedure cc
(
v_empno in emp.empno%type,
v_sal out emp.sal%type,
v_comm out emp.comm% ......
ÔÚ½øÐÐÊý¾Ý¿â²Ù×÷ʱ£¬Î޷ǾÍÊÇÌí¼Ó¡¢É¾³ý¡¢Ð޸ģ¬ÕâµÃÉè¼Æµ½Ò»Ð©³£ÓõÄSQLÓï¾ä£¬ÈçÏ£º
SQL³£ÓÃÃüÁîʹÓ÷½·¨£º
(1) Êý¾Ý¼Ç¼ɸѡ£º
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû=×Ö¶ÎÖµ order by ×Ö¶ÎÃû [desc]"
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû like %×Ö¶ÎÖµ% order by ×Ö¶ÎÃû [desc]"
sql="select top 10 * fro ......
--Óï ¾ä¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT¡¡¡¡¡¡--´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT¡¡¡¡¡¡--ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE¡¡¡¡¡¡--´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE¡¡¡¡¡¡--¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE¡¡¡¡--´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE¡¡¡¡ --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER ......
----start
SQL(Structured Query Language)£¬Ò²¾ÍÊǽṹ»¯²éѯÓïÑÔ£¬Ëü±»Éè¼ÆÓÃÀ´²Ù×÷¼¯ºÏµÄ£¬ÊǷǹý³Ì»¯µÄÓïÑÔ¡£Ëæ×ÅÓ¦ÓóÌÐòµÄ·¢Õ¹£¬ÒµÎñÂß¼Ô½À´Ô½¸´ÔÓ£¬´«Í³µÄSQLÒѾ²»ÄÜÂú×ãÈËÃǵÄÒªÇó£¬ÓÚÊÇÈËÃǶÔSQL½øÐÐÁËÀ©Õ¹£¬Ê¹Ëü¾ßÓÐÁ˹ý³Ì»¯µÄÂß¼£¬¼´£ºSQL PL¡£SQL PLµÄÈ«³ÆÊÇ SQL Procedural Language£ ......