Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ORACLE CASEº¯Êý

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
 
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà¶Ô±È½Ï¼ò½à£¬µ«ÊǺÍCaseËÑË÷º¯ÊýÏà±È£¬¹¦ÄÜ·½Ãæ»áÓÐЩÏÞÖÆ£¬±ÈÈçдÅжÏʽ¡£
»¹ÓÐÒ»¸öÐèҪעÒâµÄÎÊÌ⣬Caseº¯ÊýÖ»·µ»ØµÚÒ»¸ö·ûºÏÌõ¼þµÄÖµ£¬Ê£ÏµÄCase²¿·Ö½«»á±»×Ô¶¯ºöÂÔ¡£
±ÈÈç˵£¬ÏÂÃæÕâ¶ÎSQL£¬ÄãÓÀÔ¶ÎÞ·¨µÃµ½“µÚ¶þÀà”Õâ¸ö½á¹û
CASE WHEN col_1 IN ( 'a', 'b') THEN 'µÚÒ»Àà'
WHEN col_1 IN ('a')       THEN 'µÚ¶þÀà'
ELSE'ÆäËû' END
ÏÂÃæÎÒÃÇÀ´¿´Ò»Ï£¬Ê¹ÓÃCaseº¯Êý¶¼ÄÜ×öЩʲôÊÂÇé¡£
Ò»£¬ÒÑÖªÊý¾Ý°´ÕÕÁíÍâÒ»ÖÖ·½Ê½½øÐзÖ×飬·ÖÎö¡£
ÓÐÈçÏÂÊý¾Ý:(ΪÁË¿´µÃ¸üÇå³þ£¬ÎÒ²¢Ã»ÓÐʹÓùú¼Ò´úÂ룬¶øÊÇÖ±½ÓÓùú¼ÒÃû×÷ΪPrimary Key)
¹ú¼Ò£¨country£© ÈË¿Ú£¨population£©
Öйú 600
ÃÀ¹ú 100
¼ÓÄôó 100
Ó¢¹ú 200
·¨¹ú 300
ÈÕ±¾ 250
µÂ¹ú 200
Ä«Î÷¸ç 50
Ó¡¶È 250
¸ù¾ÝÕâ¸ö¹ú¼ÒÈË¿ÚÊý¾Ý£¬Í³¼ÆÑÇÖ޺ͱ±ÃÀÖÞµÄÈË¿ÚÊýÁ¿¡£Ó¦¸ÃµÃµ½ÏÂÃæÕâ¸ö½á¹û¡£
ÖÞ ÈË¿Ú
ÑÇÖÞ 1100
±±ÃÀÖÞ 250
ÆäËû 700
ÏëÒª½â¾öÕâ¸öÎÊÌ⣬Äã»áÔõô×ö£¿Éú³ÉÒ»¸ö´øÓÐÖÞCodeµÄView£¬ÊÇÒ»¸ö½â¾ö·½·¨£¬µ«ÊÇÕâÑùºÜÄѶ¯Ì¬µÄ¸Ä±äͳ¼ÆµÄ·½Ê½¡£
Èç¹ûʹÓÃCaseº¯Êý£¬SQL´úÂëÈçÏÂ
SELECT SUM(population),
CASE country
WHEN 'Öйú'     THEN 'ÑÇÖÞ'
WHEN 'Ó¡¶È'     THEN 'ÑÇÖÞ'
WHEN 'ÈÕ±¾'     THEN 'ÑÇÖÞ'
WHEN 'ÃÀ¹ú'     THEN '±±ÃÀÖÞ'
WHEN '¼ÓÄôó' THEN '±±ÃÀÖÞ'
WHEN 'Ä«Î÷¸ç' THEN '±±ÃÀÖÞ'
ELSE 'ÆäËû' END
from    Table_A
GROUP BY CASE country
WHEN 'Öйú'     THEN 'ÑÇÖÞ'
WHEN 'Ó¡¶È'     THEN 'ÑÇÖÞ'
WHEN 'ÈÕ±¾'     THEN 'ÑÇÖÞ'
WHEN 'ÃÀ¹ú'     THEN '±±ÃÀÖÞ'
WHEN '¼ÓÄôó' THEN '±±ÃÀÖÞ'
WHEN 'Ä«Î÷¸ç' THEN '±±ÃÀÖÞ'
ELSE 'ÆäËû' END;
ͬÑùµÄ£¬ÎÒÃÇÒ²¿ÉÒÔÓÃÕâ¸ö·½·¨À´ÅжϹ¤×ʵĵȼ¶£¬²¢Í³¼ÆÿһµÈ¼¶µÄÈËÊý¡£SQL´úÂëÈçÏÂ
SELECT
CASE WHEN sal


Ïà¹ØÎĵµ£º

OracleÓÃimpºÍexpʵÏÖÊý¾ÝµÄµ¼ÈëºÍµ¼³ö

 ImpºÍExp
ÃüÁîÏê½â:
Exp
µ¼³ö
ģʽ:
Fullģʽ---µ¼³ö
Õû¸öÊý¾Ý¿â
Userģʽ---µ¼³ö
Ö¸¶¨µÄÓû§
Tableģʽ—µ¼³ö
Ö¸¶¨µÄ±í
Tablespaceģʽ—µ¼³ö
±í
¿Õ¼ä
Exp
µ¼³ö
²ÎÊý:
OWNERÖ¸¶¨Òªµ¼³ö
µÄÓû§Áбí
FULL=y±íʾҪµ¼³ö
Õû¸öÊý¾Ý¿â
TablesÖ¸¶¨Òªµ¼³ö
µÄ±í
TablepacesÖ¸¶¨Òªµ¼³ö
µÄ±í ......

OracleÊý¾Ý¿â±¸·Ý¼¼ÇÉ

¡¡¡¡oracle% sqlplus /nolog
¡¡¡¡SQL> conn / as sysdba
¡¡¡¡Êý¾Ý¿âµÄÎïÀíÎļþ
¡¡¡¡Êý¾ÝÎļþ
¡¡¡¡select file_name from dba_data_files;
¡¡¡¡¿ØÖÆÎļþ
¡¡¡¡select name from v$controlfile;
¡¡¡¡ÈÕÖ¾Îļþ
¡¡¡¡select member from v$logfile;
¡¡¡¡---------------------------------------------------------
......

ORACLE PL/SQL ¼Ç¼(Record)ѧϰ±Ê¼Ç(¶þ)

¶þ¡¢ÒÔÐβεÄÐÎʽ¶¨ÒåºÍʹÓüǼ¡¢¶ÔÏóÀàÐÍ
ÔÚÓÃ×÷ÐÎʽ²ÎÊýʱ£¬¼Ç¼ÀàÐͺͶÔÏóÀàÐÍÓкܶàÏà֮ͬ´¦¡£ÔÚ½«ËüÃÇ×÷ΪÓαꡢº¯Êý»ò¹ý³ÌµÄÐÎʽ²ÎÊýÒÔÇ°£¬ÊÂÏȶ¼±ØÐ붨ÒåÒ»¸ö¼Ç¼ÀàÐÍ»òÕ߶ÔÏóÀàÐÍ¡£
ÈçÏÂÀýËùʾ£º
 
¼Ç¼
DECLARE

-- Define a record type.
TYPE individual_record IS RECORD
(individual_id ......

ORACLE PL/SQL ¼¯ºÏѧϰ±Ê¼Ç(¶þ)

Èý¡¢Ç¶Ì×±íµÄʹÓ÷½·¨
 
1¡¢½«Ç¶Ì×±í¶¨ÒåΪPL/SQLµÄ³ÌÐò¹¹Ôì¿é
 
TYPE type_name IS TABLE OF element_type[NOT NULL];
 
ÈçÏÂÀýËùʾ£º
DECLARE

-- Define a nested table of variable length strings.
TYPE card_table IS TABLE OF VARCHAR2(5 CHAR);

-- Declare and initialize a n ......

OracleÊý¾Ý¿âÃæÊÔÎÊÌ⼯ºÏ¼°¼¼ÇÉ

 
ÕâƪÎÄÕÂÊÇORACLEÃæÊÔµÄÎÊÌâ½õ¼¯£¬ËäÈ»²»È«Ã棬µ«ÊÇÕâƪÎÄÕ»áÈÃÄãÖªµÀÈçºÎÈÃÃæÊÔ¿¼¹ÙÁ˽âÄã¶ÔORACLE¸ÅÄîµÄÊìϤ³Ì¶È¡£
 
1.½âÊÍÀ䱸·ÝºÍÈȱ¸·ÝµÄ²»Í¬µãÒÔ¼°¸÷×ÔµÄÓŵã
 
½â´ð£ºÈȱ¸·ÝÕë¶Ô¹éµµÄ£Ê½µÄÊý¾Ý¿â£¬ÔÚÊý¾Ý¿âÈԾɴ¦ÓÚ¹¤×÷״̬ʱ½øÐб¸·Ý¡£¶øÀ䱸·ÝÖ¸ÔÚÊý¾Ý¿â¹Ø±Õºó£¬½øÐб¸·Ý£¬ÊÊÓÃÓÚËùÓÐÄ£Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ