锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲人成网站色在线入口,精品亚洲一区二区,亚洲国产情侣一区二区三区http://m.tkk7.com/rosen/category/3474.html楠勫偛銆佽椽濠佽糠鑹層佸靠鎬掋佸珘濡掋佽椽楗曘佹噿鎯扳斺斾竷瀹楃姜<br> 鏈?Blog 鏄粠錛歨ttp://blog.csdn.net/rosen 鎼潵銆?/description>zh-cnTue, 27 Feb 2007 18:37:13 GMTTue, 27 Feb 2007 18:37:13 GMT60Oracle 9i 涓殑 SQL錛堣漿璐達級http://m.tkk7.com/rosen/articles/13558.htmlRosenRosenTue, 20 Sep 2005 12:05:00 GMThttp://m.tkk7.com/rosen/articles/13558.htmlhttp://m.tkk7.com/rosen/comments/13558.htmlhttp://m.tkk7.com/rosen/articles/13558.html#Feedback0http://m.tkk7.com/rosen/comments/commentRss/13558.htmlhttp://m.tkk7.com/rosen/services/trackbacks/13558.html絎竴绔?nbsp;       鍩烘湰SELECT 璇彞

ORACLE鏁版嵁搴撶殑浣撶郴緇撴瀯銆?BR>SYS鍜孲YSTEM鐢ㄦ埛銆?/P>

SQL璇彞涓嶅尯鍒嗗ぇ灝忓啓銆?BR>鈥樷欏拰鈥濃濈殑鍖哄埆銆?BR>瀛楃涓插尯鍒嗗ぇ灝忓啓銆?/P>

NULL鍊箋?BR>鑱旀帴榪愮畻絎︼細   ||
鏃墮棿鐨勯粯璁ゆ牸寮忎負DD-MON-YY銆?/P>

SELECT * FROM TAB;

瀛楁鍒悕
SELECT job_title AS Title, min_salary AS 鈥淢inimum Salary鈥?FROM jobs;

淇濊瘉鍞竴鎬?BR>SELECT DISTINCT department_id,job_id FROM employees;

DUAL琛?BR>SELECT SYSDATE, USER FROM DUAL;

涓嶇瓑浜?!=銆?lt;>鎴朸=)
SELECT first_name || 鈥?鈥?|| last_name 鈥淣ame鈥?commission_pct FROM employees
WHERE commission_pct != 0.35 ;

<=(灝忎簬絳変簬)
SELECT first_name || 鈥?鈥?|| last_name 鈥淣ame鈥?commission_pct FROM employees
WHERE commission_pct <= 0.35 ;

>=(澶т簬絳変簬)
SELECT first_name || 鈥?鈥?|| last_name 鈥淣ame鈥?commission_pct FROM employees
WHERE commission_pct >= 0.35 ;

ANY(鐩稿綋浜嶰R)
SELECT first_name || 鈥?鈥?|| last_name 鈥淣ame鈥?department_id FROM employees
WHERE department_id <= ANY (10,15,20,25);

ALL(鐩稿綋浜嶢ND)
SELECT first_name || 鈥?鈥?|| last_name 鈥淣ame鈥?department_id FROM employees
WHERE department_id >= ALL (80,90,100);


IN 鍜?NOT IN
SELECT first_name,last_name,department_id FROM employees
WHERE department_id IN (10,20,90);

IN 鐩稿綋浜?=ANY銆?/P>

SELECT first_name,last_name,department_id FROM employees
WHERE department_id NOT IN
(10,30,40,50,60,80,90,110,100);

NOT IN 鐩稿綋浜?!=ALL銆?/P>

娉ㄦ剰錛歭ast_name NOT IN(鈥楽mith鈥?鈥橳homas鈥?NULL)
涓嶈繑鍥炰換浣曡褰曘?BR>浠諱綍涓嶯ULL鍊肩殑姣旇緝閮芥槸NULL鍊箋?/P>

BETWEEN
SELECT first_name,last_name,salary FROM employees WHERE salary BETWEEN 5000 AND 6000;

EXISTS
SELECT last_name,first_name,department_id FROM employees e
WHERE EXISTS (SELECT 1 FROM departments d
WHERE d.department_id = e.department_id
   AND d.department_name=鈥橝dministration鈥?;

IS NULL鍜孖S NOT NULL
SELECT last_name,department_id FROM employees WHERE department_id IS NULL;

LIKE
SELECT first_name,last_name FROM employees WHERE first_name LIKE 鈥楽u%鈥?
AND last_name NOT LIKE 鈥楽%鈥?
%銆乢鐨勫惈涔夈?/P>

SELECT job_id,job_title FROM jobs WHERE job_id LIKE 鈥楢C\_%鈥?ESCAPE 鈥榎鈥?

緇撴灉闆嗙殑鎺掑簭
SELECT first_name || 鈥?鈥?|| last_name 鈥淓mployee Name鈥?FROM employees WHERE department_id =90 ORDER BY last_name;
ASC銆丏ESC銆?BR>SELECT first_name,hire_date,salary,manager_id mid FROM employees WHERE department_id IN (110,100) ORDER BY mid ASC,salary DESC, hire_date;

閿欒錛歋ELECT DISTINCT 鈥楻egion 鈥?|| region_id FROM countries ORDER BY region_id;
姝g‘錛歋ELECT DISTINCT 鈥楻egion 鈥?|| region_id FROM countries
ORDER BY 鈥楻egion 鈥?||region_id;

SELECT first_name,hire_date,salary,manager_id mid FROM employees WHERE department_id IN (110,100) ORDER BY 4,2,3;

NULL鐨勬帓搴?BR>榛樿鎯呭喌涓?鍗囧簭鎺掑垪涓璑ULL鍊兼帓鍦ㄦ渶鍚庛?BR>SELECT last_name,commission_pct FROM employees WHERE last_name LIKE 鈥楻%鈥?BR>ORDER BY commission_pct ASC, last_name DESC;

SELECT last_name,commission_pct FROM employees WHERE last_name LIKE 鈥楻%鈥?BR>ORDER BY commission_pct ASC NULLS FIRST, last_name DESC;

CASE 琛ㄨ揪寮?9i鏂板)
SELECT country_name,region_id,
        CASE region_id WHEN 1 THEN 鈥楨urope鈥?BR>                   WHEN 2 THEN  鈥楢merica鈥?BR>WHEN 3 THEN 鈥楢sia鈥?BR>ELSE 鈥極ther鈥?END Continent
FROM countries WHERE country_name LIKE 鈥業%鈥?

SELECT first_name,department_id,salary,
        CASE WHEN salary < 6000 THEN 鈥楲ow鈥?BR>         WHEN salary < 10000 THEN 鈥楳edium鈥?BR>         WHEN salary >= 10000 THEN  鈥楬igh鈥?END Category
FROM employees WHERE department_id <=30 ORDER BY first_name;

絎簩绔?nbsp;       SQL * Plus鐨勪嬌鐢?/FONT>
SQL * Plus鐨勫父鐢ㄥ懡浠ゃ?BR>

絎笁绔?nbsp;       Oracle 9i 涓殑鍑芥暟

NVL
SELECT first_name,last_name,salary,bonus,salary + bonus total_comp FROM employees;

SELECT first_name,last_name,salary,bonus,salary + NVL(bonus,0)
total_comp FROM employees;

NVL2(9i鏂板)
SELECT first_name,last_name,salary,bonus, NVL2(bonus,salary + bonus,salary)
total_comp FROM employees;

瀛楃涓插嚱鏁?BR>SELECT ASCII(鈥楢鈥? Big_A,ASCII(鈥榸鈥? Little_z FROM dual;
SELECT CHR(65),CHR(223) FROM dual;
SELECT CONCAT(鈥楶eter鈥?鈥橫ackovicky鈥? FROM dual;
SELECT INITCAP(鈥榯he three musketeers鈥? book_title FROM dual;
SELECT INSTR(鈥楳ississippi鈥?鈥檌鈥?3,3) test1, INSTR(鈥楳ississippi鈥?鈥檌鈥?1,3) test2
       INSTR(鈥楳ississippi鈥?鈥檌鈥?-2,3) test3 FROM dual;

瑙f瀽鏁版嵁
text_string =鈥橲unday|Monday|Tuesday鈥?BR>SELECT text_string,SUBSTR(text_string,INSTR(text_string,鈥檤鈥?1,1) + 1,
INSTR(text_string,鈥檤鈥?1,2) - INSTR(text_string,鈥檤鈥?1,1) 鈥?1 ) FROM dual;

INSTRB
SELECT LENGTH(鈥榯he three musketeers鈥? title_length FROM dual;
LENGTHB
LOWER
SELECT LPAD(鈥榊es鈥?7,鈥?鈥? FROM dual;
SELECT LTRIM(鈥楳ississippi鈥?鈥橫is鈥? test1, LTRIM(鈥楻Padded        鈥? test2,
       LTRIM(鈥?nbsp;    RPadded鈥? test3, LTRIM(鈥?nbsp;    RPadded鈥?鈥橺鈥? test4 FROM dual;

鏁板鍑芥暟
ABS銆丄COS銆丄SIN銆丄TAN銆丄TAN2銆丅ITAND銆丆EIL銆丆OS銆丆OSH銆丒XP銆丗LOOR銆丩N銆丩OG銆丮OD銆丳OWER銆丼IGN銆丼IN銆丼INH銆丼QRT銆乀AN銆乀ANH銆?BR>ROUND=TRUNC
SELECT TRUNC(123.456,2) pos, TRUNC(123.456,-1) neg FROM dual;

鏃ユ湡鍑芥暟
ADD_MONTHS銆丩AST_DAY銆丮ONTH_BETWEEN銆丯EXT_TIME銆丯EXT_DAY銆丷OUND銆丼YSDATE銆?/P>

杞崲鍑芥暟
CHARTOROWID銆丆ONVERT銆丠EXTORAW銆丯LS_CHARSET_ID銆丯LS_CHARSET_NAME銆?BR>RAWTOHEX銆丷OWIDTOCHAR銆乀O_CHAR銆?TO_DATE銆?TO_ LABEL銆?TO_MULTI_BYTE銆?BR>TO_NUMBER銆乀O_SINGLE_BYTE銆?/P>

SELECT TO_CHAR(SYSDATE,鈥檡yyy-mm-dd hh24:mi:ss鈥? FROM dual;
SELECT TO_CHAR(SYSDATE,鈥檓onth鈥? FROM dual;
SELECT TO_CHAR(SYSDATE,鈥橲SSSS鈥? FROM dual;

INSERT INTO demo(demo_key,date_col)
   VALUES (1,TO_DATE(鈥?004-7-1鈥?鈥檡yyy-mm-dd鈥?);

鍏跺畠鍑芥暟
SELECT COALESCE(NULL,鈥橭racle鈥?鈥?4鈥? string_type,
       COALESCE(3,14,COS(0)) bnr_type FROM dual;
榪斿洖絎竴涓潪NULL鍊箋?/P>

SELECT DECODE(rating,null,1000,鈥機鈥?2000,鈥橞鈥?3000.鈥橠鈥?4000,5000) FROM accts;

SELECT USER,UID FROM dual;

GREATEST銆丩EAST銆?/P>

SELECT ename,mgr,comm,NULLIF(comm,0) test1 FROM scott.emp
       WHERE empno IN(7844,7839,7654,7369); (9i鏂板)
濡傛灉x1=x2,榪斿洖NULL銆傚惁鍒檟1銆?/P>

SELECT SYS_CONTEXT(鈥楿SERENV鈥?鈥橧P_ADDRESS鈥? FROM dual; (9i鏂板)


USERENV鍑芥暟鍦?i涓仠鐢紝寤鴻鐢⊿YS_CONTEXT鍑芥暟銆?/P>

SELECT VSIZE(user),user FROM dual;

絎洓绔?nbsp;       鍒嗙粍姹囨昏鍙?/STRONG>

GROUP BY 璇彞
SELECT cust_state_province, count(*) customer_count
        FROM sh.customers GROUP BY cust_state_province;
閲嶇偣錛欸ROUP BY 璇彞涓璖ELECT鍚庡瓧孌電殑闄愬埗錛氬彧鑳芥槸鍒嗙粍瀛楁鍜岄泦鍚堝嚱鏁般?BR>GROUP BY鐨勭粨鏋滈泦鎺掑簭銆?/P>

SELECT deptno,MIN(sal),MAX(sal)  FROM emp  WHERE job=鈥機LERK鈥?BR>GROUP  BY deptno; (娉ㄦ剰姝ゅ涓嶴QL Server涓嶅悓!)

SELECT cust_state_province, count(*) customer_count
        FROM sh.customers GROUP BY cust_state_province ORDER BY COUNT(*) DESC;
鎴栵細SELECT cust_state_province, count(*) customer_count
        FROM sh.customers GROUP BY cust_state_province ORDER BY 2 DESC;

緙哄畾琛ㄧ殑涓涓暟鎹潡涓鉤鍧囨湁澶氬皯琛屾暟鎹細
SELECT AVG(row_count ),MAX(row_count),MIN(row_count)
FROM (SELECT count(*) row_count FROM employees GROUP BY SUBSTR(rowid,1,15));

HAVING
SELECT t.fiscal_month_desc,s.channel_id,SUM(s.quantity_sold),SUM(s.amount_sold)
FROM sh.times t,sh.sales s WHERE t.time_id = s.time_id AND s.promo_id <> 9999
GROUP BY t.fiscal_month_desc,s.channel_id HAVING SUM(s.amount_sold) > 2000000;
HAVING=WHERE銆?/P>

閿欒錛?BR>SELECT t.fiscal_month_desc,s.channel_id,SUM(s.quantity_sold),SUM(s.amount_sold)
FROM sh.times t,sh.sales s WHERE t.time_id = s.time_id AND s.promo_id <> 9999 AND SUM(s.amount_sold) > 2000000  GROUP BY t.fiscal_month_desc,s.channel_id;


CUBE鍜孯OLLUP
SELECT cust_gender gender,NVL(cust_marital_status,鈥檜nknown鈥? marital_status,COUNT(*)
FROM sh.customers GROUP BY cust_gender, NVL(cust_marital_status,鈥檜nknown鈥?;

SELECT cust_gender gender,NVL(cust_marital_status,鈥檜nknown鈥? marital_status,COUNT(*)
FROM sh.customers GROUP BY cust_gender, ROLLUP(NVL(cust_marital_status,鈥檜nknown鈥?));

SELECT cust_gender gender,NVL(cust_marital_status,鈥檜nknown鈥? marital_status,COUNT(*)
FROM sh.customers GROUP BY ROLLUP(cust_gender, NVL(cust_marital_status,鈥檜nknown鈥?));

SELECT cust_gender gender,NVL(cust_marital_status,鈥檜nknown鈥? marital_status,COUNT(*)
FROM sh.customers GROUP BY CUBE(cust_gender, NVL(cust_marital_status,鈥檜nknown鈥?));

宓屽鍑芥暟
SELECT deptno,GREATEST(COUNT(DISTINCT job),COUNT(DISTINCT mgr)) cnt,
       COUNT(DISTINCT job ) jobs,   COUNT(DISTINCT mgr) mgrs
FROM emp GROUP BY deptno;

SELECT MAX(COUNT(DISTINCT job)) FROM emp GROUP BY deptno;

闆嗗悎鍑芥暟
SELECT empno,sal FROM scott.emp WHERE deptno=20 ORDER BY sal;

DISTINCT鍜孉LL鐨勫尯鍒?BR>SELECT AVG(sal) avg, AVG(ALL sal) avg_all,AVG(DISTINCT sal) avg_dist,
COUNT(sal) cnt, COUNT(DISTINCT sal) cnt_dist,SUM(sal) sum_all,SUM(DISTINCT sal ) sum_dist FROM scott.emp WHERE deptno=20;

榛樿鏄疉LL銆?/P>

SELECT job_id,AVG(salary) FROM hr.employees WHERE job_id LIKE 鈥楢C%鈥?GROUP BY job_id;

SELECT COUNT(*) emp_count,
       COUNT(DISTINCT department_id) dept_count,
       COUNT(ALL department_id) not_null_dept_count FROM hr.employees;

SELECT cust_gender gender, NVL(cust_marital_status,鈥檜nknown鈥? marital_status,
COUNT(*) emp_count, GROUPING(cust_gender) gender_superagg,
GROUPING(NVL(cust_marital_status,鈥檜nknown鈥?) martial_superagg
FROM sh.customers GROUP BY CUBE(cust_gender, NVL(cust_marital_status,鈥檜nknown鈥?);

Create table tmp as
SELECT cust_gender gender, NVL(cust_marital_status,鈥檜nknown鈥? marital_status,
COUNT(*) emp_count, GROUPING(cust_gender) gender_superagg,
GROUPING(NVL(cust_marital_status,鈥檜nknown鈥?) martial_superagg
FROM sh.customers GROUP BY CUBE(cust_gender, NVL(cust_marital_status,鈥檜nknown鈥?);

絎簲绔?nbsp;       鑱旀帴璇彞

Oracle 9i涓柊澧炲姞浜咼OIN瀛愬彞錛屼互絎﹀悎 ANSI SQL 1999鏍囧噯銆?/P>

瀵圭瓑鑱旀帴(鍐呰仈鎺?
Oracle璇硶錛?BR>SELECT locations.location_id,city,department_name FROM locations,departments
WHERE locations.location_id = departments.location_id;

SELECT locations.location_id,city,department_name FROM locations,departments
WHERE locations.location_id = departments.location_id AND country_id != 鈥楿S鈥?

浣跨敤琛ㄧ殑鍒悕
SELECT l.location_id,city,department_name FROM
locations l,departments d WHERE l.location_id = d.location_id AND country_id != 鈥楿S鈥?

褰撲嬌鐢ㄨ〃鐨勫埆鍚嶆椂錛屽彧鑳界敤鍒悕鏉ラ檺瀹氳〃鍚嶃?BR>閿欒錛歋ELECT locations.location_id,city,department_name FROM
locations l,departments d WHERE locations.location_id = d.location_id;

ANSI璇硶錛?BR>NATURAL JOIN
SELECT location_id,city,department_name FROM locations NATURAL JOIN departments;
鑷姩浣跨敤涓や釜琛ㄧ殑鍚屽悕瀛楁榪涜鑱旀帴銆?BR>涓嶈鐢ㄨ〃鍚嶆垨琛ㄧ殑鍒悕鏉ラ檺瀹氬垪鍚嶃?/P>

SELECT * FROM regions NATURAL JOIN countries;

SELECT region_name,country_name,city FROM regions NATURAL JOIN countries
NATURAL JOIN locations;
絳変環浜庯細SELECT region_name,country_name,city FROM regions,countries,locations
WHERE regions.region_id = countries.region_id AND
countries.country_id= locations.country_id;

JOIN 鈥?USING
褰撲袱涓〃鐨勫叡鍚屽瓧孌墊暟鎹被鍨嬩笉鍚屾椂銆?BR>SELECT location_id,city,department_name FROM locations  JOIN departments USING(location_id);

SELECT region_name,country_name,city FROM regions
JOIN countries USING(region_id)
JOIN locations USING(country_id);

SELECT region_name,country_name,city FROM regions
JOIN countries USING(region_id)
JOIN locations USING(country_id)
WHERE country_id = 鈥楿S鈥?
ORDER BY 1;

JOIN ON
SELECT region_name,country_name,city FROM regions r
JOIN countries c ON r.region_id = c.region_id 
JOIN locations l ON c.country_id= l.country_id
WHERE country_id = 鈥楿S鈥?

SELECT first_name,department_name,city
FROM employees e JOIN departments d ON (e.department_id = d.department_id)
JOIN locations l ON (d.location_id = l.location_id);

絎涘崱灝斾箻縐?浜ゅ弶鑱旀帴)
Oracle璇硶錛?BR>SELECT region_name,country_name FROM regions,countries WHERE countries.country_id LIKE 鈥業%鈥?
ANSI 璇硶錛?BR>SELECT region_name,country_name FROM regions CROSS JOIN countries
WHERE countries.country_id LIKE 鈥業%鈥?

澶栬仈鎺?闈炲絳夎仈鎺?
Oracle璇硶錛?BR>SELECT c.country_name,l.city FROM countries c ,locations l WHERE c.country_id = l.country_id(+);

select ename,emp.deptno,dname from emp,dept where emp.deptno(+)=dept.deptno(+);

澶栬仈鎺ョ(+)瑕佺敤浜庢墍鏈夌殑鏉′歡銆?BR>SELECT c.country_name,l.city FROM countries c ,locations l WHERE c.country_id = l.country_id(+) AND l.city LIKE 鈥楤%鈥?

SELECT c.country_name,l.city FROM countries c ,locations l WHERE c.country_id = l.country_id(+) AND l.city(+) LIKE 鈥楤%鈥?

澶栬仈鎺ョ(+)涓嶈兘鐢ㄤ簬OR鍜孖N銆?BR>閿欒錛歋ELECT c.country_name,l.city FROM countries c ,locations l WHERE c.country_id = l.country_id(+) OR l.city(+) LIKE 鈥楤%鈥?

姝g‘錛歋ELECT c.country_name,l.city FROM countries c ,locations l WHERE c.country_id = l.country_id(+) AND c.country_name IN (鈥業ndia鈥?鈥橧srael鈥?;

ANSI璇硶錛?BR>宸﹀鑱旀帴
SELECT c.country_name,l.city FROM countries c LEFT OUTER JOIN locations l ON
c.country_id = l.country_id;

select ename,emp.deptno,dname from emp LEFT OUTER JOIN dept ON emp.deptno=dept.deptno;
OUTER鏄彲閫夌殑銆?BR>SELECT country_name,city FROM countries  LEFT JOIN locations USING(country_id);
SELECT country_name,city FROM countries  NATURAL LEFT JOIN locations;

鍙沖鑱旀帴
SELECT country_name,city FROM locations  NATURAL RIGHT OUTER JOIN countries;

SELECT c.country_name,l.city FROM locations l RIGHT JOIN countries c ON
c.country_id = l.country_id;

瀹屽叏澶栬仈鎺?9i鏂板)
SELECT e.employee_id,e.last_name,d.department_id,d.department_name
FROM employees e FULL OUTER JOIN departments d ON (e.department_id = d.department_id)

閿欒錛歴elect ename,emp.deptno,dname from emp,dept where emp.deptno(+)=dept.deptno(+);

鑷仈鎺?BR>鐢ㄤ簬灞傛鍨嬫暟鎹簱銆?BR>SELECT e.last_name Employee, m.last_name Manager FROM employees e ,employees m
WHERE m.employee_id = e.manager_id;

SELECT e.last_name Employee, m.last_name Manager FROM employees e INNER JOIN
employees m ON m.employee_id = e.manager_id;


絎叚绔?nbsp;       闆嗗悎璇彞鍜屽瓙鏌ヨ

闆嗗悎璇彞錛氭妸澶氫釜SELECT璇彞鐨勭粨鏋滈泦鍚堝茍鎴愪竴涓粨鏋滈泦銆?BR>UNION ALL 鍚堝茍澶氫釜緇撴灉闆嗭紝涓嶆秷闄ら噸澶嶅箋?BR>UNION     鍚堝茍澶氫釜緇撴灉闆嗭紝娑堥櫎閲嶅鍊箋?BR>INTERSECT
MINUS

SELECT last_name, hire_date FROM employees WHERE department_id = 90;
SELECT last_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?

SELECT last_name, hire_date FROM employees WHERE department_id = 90
UNION ALL
SELECT last_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?

SELECT last_name, hire_date FROM employees WHERE department_id = 90
UNION
SELECT last_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?

SELECT last_name, hire_date FROM employees WHERE department_id = 90
INTERSECT
SELECT last_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?

SELECT last_name, hire_date FROM employees WHERE department_id = 90
MINUS
SELECT last_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?

閿欒錛?BR>SELECT last_name, hire_date FROM employees WHERE department_id = 90 ORDER BY last_name
MINUS
SELECT first_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?ORDER BY first_name;

SELECT last_name, hire_date 鈥淛oin Date鈥?FROM employees WHERE department_id = 90 MINUS
SELECT first_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?ORDER BY last_name,  鈥淛oin Date鈥?

SELECT last_name, hire_date 鈥淛oin Date鈥?FROM employees WHERE department_id = 90 MINUS
SELECT first_name, hire_date FROM employees WHERE last_name LIKE 鈥楰%鈥?ORDER BY 1,2;

瀛愭煡璇?BR>瀛愭煡璇㈢殑鐗瑰緛錛?nbsp;  瀛愭煡璇㈣鍔犳嫭鍙楓?BR>             鍒嗕負宓屽瀛愭煡璇㈠拰鐩稿叧瀛愭煡璇€?鍖哄埆錛氬瓙鏌ヨ閲屾槸鍚﹀寘鍚仈鎺ャ?
             鍒嗕負鍗曞煎拰澶氬箋?BR>             鐩稿叧瀛愭煡璇㈠彲鐢ㄨ仈鎺ヨ鍙ヤ唬鏇褲?/P>

鍗曞煎祵濂楀瓙鏌ヨ鐨勪緥瀛愶細
SELECT lastname,firstname,salary FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);

SELECT lastname,firstname,salary FROM employees
WHERE department_id = (SELECT department_id FROM departments WHERE department_name=鈥橝ccounting鈥?;

澶氬煎祵濂楀瓙鏌ヨ鐨勪緥瀛愶細
SELECT lastname,firstname,salary FROM employees
WHERE department_id = (SELECT department_id FROM departments WHERE first_name=鈥橨ohn鈥?;

鐩稿叧瀛愭煡璇㈢殑渚嬪瓙錛?BR>SELECT department_id,last_name,salary FROM employees e1 WHERE salary =
        (SELECT MAX(salary) FROM employees e2 WHERE e1.department_id = e2.department_id);

姣旇緝錛歋ELECT department_id,last_name,salary FROM employees WHERE salary =
        (SELECT MAX(salary) FROM employees );

SELECT last_name,first_name, department_id FROM employees e1 WHERE EXISTS
        (SELECT 鈥榵鈥?FROM employees e2 WHERE first_name= 鈥楯ohn鈥?AND e1.department_id = e2.department_id);

瀛愭煡璇㈢敤鍦╟ase琛ㄨ揪寮忎腑錛?BR>SELECT city,country_id,(CASE
      WHEN country_id IN
(SELECT country_id FROM countries WHERE country_name = 鈥業ndia鈥? THEN 鈥業ndian鈥?BR>ELSE 鈥楴on_Indian鈥?BR>END) 鈥淚NDIA?鈥?BR>FROM locations WHERE city LIKE 鈥樷橞%;

瀛愭煡璇㈢敤鍦⊿ELECT瀛愬彞涓細
SELECT last_name,department_id,
     (SELECT MAX(salary) FROM employees sq WHERE sq.ddepartment_id = e.department_id) HSAL FROM employees e WHERE last_name LIKE 鈥楻%鈥?

UPDATE employees e1
SET salary = (SELECT MAX(salary) FROM employees e2 WHERE e1.department_id= e2.department_id);

DELETE FROM employees e WHERE salary <(SELECT AVG(salary) FROM employees WHERE department_id= e.department_id);

INSERT INTO employee_archive SELECT * FROM employees;

INSERT INTO departments(department_id,department_name) VALUES
((SELECT MAX(department_id) + 10 FROM departments),鈥橢DP鈥?;

鍙互鍦↖NSERT銆乁PDATE銆丏ELETE璇彞涓嬌鐢ㄤ竴涓瓙鏌ヨ鏉ヤ唬鏇胯〃鍚嶃?BR>DELETE FROM (SELECT * FROM departments WHERE department_id < 20) WHERE department_id =10;

DELETE FROM (SELECT * FROM department WHERE department_id < 20) WHERE department_id =10;

INSERT INTO (SELECT department_id,department_name FROM department WHERE department_id < 20) VALUES (35, 鈥楳ARKETING鈥?;

WITH READ ONLY銆?WITH CHECK OPTION銆?/P>

INSERT INTO (SELECT department_id,department_name FROM departments WHERE department_id < 20 WITH CHECK OPTION) VALUES (45, 鈥楳ARKETING鈥?;

絎竷绔?nbsp;       淇敼鏁版嵁(INSERT銆乁PDATE銆丏ELETE璇彞)

INSERT璇彞
INSERT INTO checking(account_id,create_date,balance)
VALUES(鈥楰iesha鈥?SYSDATE,5000);

INSERT INTO brokerage(account_id,create_date,balance)
SELECT account_id, SYSDATE,0 FROM checking WHERE account_type =鈥機鈥?

INSERT INTO e_checking
SELECT * FROM checking WHERE account_type =鈥機鈥?

UPDATE璇彞
UPDATE order_rollup SET (qty,price) = (SELECT SUM(qty),SUM(price) FROM order_lines
       WHERE customer_id=鈥橩HOL鈥? WHERE customer_id =鈥橩HOL鈥?AND order_period= TO_DATE(鈥?1-Oct-2001鈥?;

UPDATE order_rollup SET phone = 鈥?23456鈥?fax=鈥?34567鈥?WHERE customer_id=鈥橩HOL鈥?/P>

DELETE璇彞
DELETE FROM customers WHERE customer_id = 鈥楪OMEZ鈥?
DELETE FROM order_staging;
DML
TRUNCATE璇彞
TRUNCATE TABLE order_staging;
TRUNCATE璇彞鏄竴涓狣DL璇彞銆?/P>

SELECT 鈥?FOR UPDATE 璇彞

浜嬪姟璇彞
COMMIT銆丆OMMIT WORK銆?BR>ROLLBACK銆?BR>SAVEPOINT銆?/P>

DDL涓庤鍙ヤ笉闇瑕佹彁浜ゃ?/P>

RENAME璇彞
rename T1 to T2;

CREATE TABLE 鈥?AS SELECT 鈥﹁鍙?BR>CREATE TABLE emp_tmp AS SELECT*FROM emp WHERE deptno=10;
澶嶅埗琛細create table t2 as select * from t1;
澶嶅埗琛ㄧ殑緇撴瀯錛歝reate table t2 as select*from t1 where 1=2;

Top n 璇彞
SELECT last_name,salary FROM employees WHERE rownum <=5 ORDER BY salary DESC;

.........................................................................................................................
useraccount琛紝涓婚敭涓簎serid錛屾湁涓涓瓧孌典負鎵嬫満鍙風爜mobilephone

濡傛灉閲嶅鐨勮褰曠殑姣斾緥涓嶆槸寰堝ぇ

delete useraccount where rowid in (
select rid from
(select rowid rid,row_number() over(partition by mobilephone order by userid desc) rn from useraccount )
where rn > 1) ;



Rosen 2005-09-20 20:05 鍙戣〃璇勮
]]>
JSP 涓殑鏃ユ湡闂鍙婂叾瀹冿紙杞創錛?/title><link>http://m.tkk7.com/rosen/articles/13557.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Tue, 20 Sep 2005 12:04:00 GMT</pubDate><guid>http://m.tkk7.com/rosen/articles/13557.html</guid><wfw:comment>http://m.tkk7.com/rosen/comments/13557.html</wfw:comment><comments>http://m.tkk7.com/rosen/articles/13557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/rosen/comments/commentRss/13557.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/rosen/services/trackbacks/13557.html</trackback:ping><description><![CDATA[/**<BR>* <STRONG>@author imagebear</STRONG><BR>*/<BR><BR>鏃ユ湡闂<BR>1銆佽幏鍙栨湇鍔″櫒绔綋鍓嶆棩鏈燂細<BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><%<BR> Date myDate = new Date();<BR>%><BR></PRE><BR>2銆佽幏鍙栧綋鍓嶅勾銆佹湀銆佹棩錛?BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><BR><%<BR> Date myDate = new Date();<BR> int thisYear = myDate.getYear() + 1900;//thisYear = 2003<BR> int thisMonth = myDate.getMonth() + 1;//thisMonth = 5<BR> int thisDate = myDate.getDate();//thisDate = 30<BR>%><BR></PRE><BR>3銆佹寜鏈湴鏃跺尯杈撳嚭褰撳墠鏃ユ湡<BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><%<BR> Date myDate = new Date();<BR> out.println(myDate.toLocaleString());<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>2003-5-30 <BR>4銆佽幏鍙栨暟鎹簱涓瓧孌靛悕涓衡漰ublish_time鈥溿佺被鍨嬩負Datetime鐨勫?BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><%<BR> ...榪炴帴鏁版嵁搴?..<BR> ResultSet rs = ...<BR> Date sDate = rs.getDate("publish_time");<BR>%><BR>[code]<BR>5銆佹寜鐓ф寚瀹氭牸寮忔墦鍗版棩鏈?BR>[code]<BR><%@ page import="java.util.Date"%><BR><%@ page import="java.text.DateFormat"%><BR><%<BR> Date dNow = new Date();<BR><BR> SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");<BR> out.println("It is " + formatter.format(dNow));<BR>%><BR></PRE><BR>杈撳嚭鐨勭粨鏋滀負錛?BR>It is 鏄熸湡浜?2003.05.30 at 11:30:46 涓婂崍 CST <BR>(鏇翠負璇﹀敖鐨勬牸寮忕鍙瘋鍙傜湅SimpleDateFormat綾?<BR>6銆佸皢瀛楃涓茶漿鎹負鏃ユ湡<BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><%@ page import="java.text.DateFormat"%><BR><%<BR> String input = "1222-11-11";<BR> SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");<BR> Date t = null;<BR> try{<BR> t = formatter.parse(input);<BR> out.println(t);<BR> }catch(ParseException e){<BR> out.println("unparseable using " + formatter);<BR> }<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>Fri Nov 11 00:00:00 CST 1222 <BR>7銆佽綆楁棩鏈熶箣闂寸殑闂撮殧<BR><PRE class=CodeSamp><BR><%@ page import="java.util.Date"%><BR><%@ page import="java.text.DateFormat"%><BR><%<BR> String input = "2003-05-01";<BR> SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");<BR> Date d1 = null;<BR> try{<BR> d1 = formatter.parse(input);<BR> }catch(ParseException e){<BR> out.println("unparseable using " + formatter);<BR> }<BR> <BR> Date d2 = new Date();<BR> <BR> long diff = d2.getTime() - d1.getTime();<BR> out.println("Difference is " + (diff/(1000*60*60*24)) + " days.");<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>Difference is 29 days. <BR>8銆佹棩鏈熺殑鍔犲噺榪愮畻<BR>鏂規硶錛氱敤Calendar綾葷殑add()鏂規硶<BR><PRE class=CodeSamp><BR><%@ page import="java.util.*"%><BR><%@ page import="java.text.*"%><BR><%<BR> Calendar now = Calendar.getInstance();<BR> SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");<BR> out.println("It is now " + formatter.format(now.getTime()));<BR> now.add(Calendar.DAY_OF_YEAR,-(365*2));<BR> out.println("<br>");<BR> out.println("Two years ago was " + formatter.format(now.getTime()));<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>It is now 鏄熸湡浜?2003.05.30 at 01:45:32 涓嬪崍 CST <BR>Two years ago was 鏄熸湡涓?2001.05.30 at 01:45:32 涓嬪崍 CST <BR>9銆佹瘮杈冩棩鏈?BR>鏂規硶錛氱敤equals()銆乥efore()銆乤fter()鏂規硶<BR><PRE class=CodeSamp><BR><%@ page import="java.util.*"%><BR><%@ page import="java.text.*"%><BR><%<BR> DateFormat df = new SimpleDateFormat("yyy-MM-dd");<BR> Date d1 = df.parse("2000-01-01");<BR> Date d2 = df.parse("1999-12-31");<BR> <BR> String relation = null;<BR> if(d1.equals(d2))<BR> relation = "the same date as";<BR> else if(d1.before(d2))<BR> relation = "before";<BR> else<BR> relation = "after";<BR> out.println(d1 +" is " + relation + ' ' + d2);<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>Sat Jan 01 00:00:00 CST 2000 is after Fri Dec 31 00:00:00 CST 1999 <BR>10銆佽褰曚竴浠朵簨鎵鑺辮垂鐨勬椂闂?BR>鏂規硶錛氳皟鐢ㄤ袱嬈ystem.getTimeMillis()鏂規硶錛屾眰宸?BR><PRE class=CodeSamp><BR><%@ page import="java.text.*"%><BR><%<BR> long t0,t1;<BR> t0 = System.currentTimeMillis();<BR> out.println("Cyc starts at " + t0);<BR> int k = 0;<BR> for(int i =0;i<100000;i++){<BR> k += i;<BR> }<BR> t1 = System.currentTimeMillis();<BR> out.println("<br>");<BR> out.println("Cyc ends at " + t1);<BR> out.println("<br>");<BR> out.println("This run took " + (t1-t0) + "ms.");<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>Cyc starts at 1054275312432 <BR>Cyc ends at 1054275312442 <BR>This run took 10ms. <BR><BR>鍏跺畠錛氬浣曟牸寮忓寲灝忔暟<BR><PRE class=CodeSamp><BR><%@ page import="java.text.*"%><BR><%<BR> DecimalFormat df = new DecimalFormat(",###.00");<BR> double aNumber = 33665448856.6568975;<BR> String result = df.format(aNumber);<BR> out.println(result);<BR>%><BR></PRE><BR>杈撳嚭緇撴灉涓猴細<BR>33,665,448,856.66<img src ="http://m.tkk7.com/rosen/aggbug/13557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/rosen/" target="_blank">Rosen</a> 2005-09-20 20:04 <a href="http://m.tkk7.com/rosen/articles/13557.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://zgxxx.com" target="_blank">久久亚洲精品无码AV红樱桃</a>| <a href="http://www66913.com" target="_blank">亚洲毛片在线免费观看</a>| <a href="http://wusongtv.com" target="_blank">色屁屁www影院免费观看视频 </a>| <a href="http://gift1town.com" target="_blank">男女拍拍拍免费视频网站</a>| <a href="http://bxd888.com" target="_blank">www.亚洲精品.com</a>| <a href="http://aaaaa123.com" target="_blank">久久成人18免费网站</a>| <a href="http://wxyz2.com" target="_blank">亚洲AV无码不卡在线播放</a>| <a href="http://jmdehong.com" target="_blank">99久久精品免费精品国产</a>| <a href="http://hqwgg.com" target="_blank">亚洲啪啪免费视频</a>| <a href="http://020iws.com" target="_blank">日韩电影免费在线观看视频</a>| <a href="http://sdsupuchem.com" target="_blank">亚洲AV无码一区二区三区电影 </a>| <a href="http://8b22.com" target="_blank">久草免费福利资源站</a>| <a href="http://by8847.com" target="_blank">亚洲视频在线观看地址</a>| <a href="http://dddd20.com" target="_blank">在线看片v免费观看视频777</a>| <a href="http://0755szyxcm.com" target="_blank">亚洲人成人网毛片在线播放</a>| <a href="http://www44xixi.com" target="_blank">国内一级一级毛片a免费</a>| <a href="http://papapa97.com" target="_blank">免费人成视频在线观看免费</a>| <a href="http://653349.com" target="_blank">亚洲人成无码网站</a>| <a href="http://zibochanglong.com" target="_blank">最近最好最新2019中文字幕免费</a>| <a href="http://a8g8.com" target="_blank">亚洲免费视频网址</a>| <a href="http://lwjiheng.com" target="_blank">国产免费看插插插视频</a>| <a href="http://zzhjnmzp.com" target="_blank">aa在线免费观看</a>| <a href="http://dehaichem.com" target="_blank">亚洲黄色网站视频</a>| <a href="http://jsky163.com" target="_blank">日韩免费三级电影</a>| <a href="http://yw756.com" target="_blank">三年在线观看免费观看完整版中文</a>| <a href="http://gzmkqp.com" target="_blank">亚洲一区二区三区夜色</a>| <a href="http://wwwxue1888.com" target="_blank">性色av免费观看</a>| <a href="http://hmjx-tape.com" target="_blank">久久精品成人免费观看97</a>| <a href="http://cykj-tech.com" target="_blank">久久精品国产亚洲av高清漫画</a>| <a href="http://4001120002.com" target="_blank">女人18毛片特级一级免费视频</a>| <a href="http://vip98888.com" target="_blank">午夜肉伦伦影院久久精品免费看国产一区二区三区 </a>| <a href="http://baizhengsh.com" target="_blank">亚洲综合亚洲国产尤物</a>| <a href="http://www6yg6yg.com" target="_blank">午夜无遮挡羞羞漫画免费</a>| <a href="http://senimei9.com" target="_blank">g0g0人体全免费高清大胆视频</a>| <a href="http://webgame86.com" target="_blank">亚洲伦另类中文字幕</a>| <a href="http://dqcjlb.com" target="_blank">日日夜夜精品免费视频</a>| <a href="http://wwwhaole10.com" target="_blank">成全动漫视频在线观看免费高清版下载 </a>| <a href="http://bz600.com" target="_blank">韩国免费一级成人毛片</a>| <a href="http://siqingsizu.com" target="_blank">五月天国产成人AV免费观看</a>| <a href="http://zqsplc.com" target="_blank">久久久久久久亚洲Av无码</a>| <a href="http://dyj696.com" target="_blank">国产最新凸凹视频免费</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>