oracle ±Ê¼Ç II Ö®DML:Êý¾Ý²Ù×÷ÓïÑÔ
DML:Data Manipulation Language Êý¾Ý²Ù×÷ÓïÑÔ
°üÀ¨£ºCRUD
1. insertÓï¾ä
(1) ´ÓÆäËü±íÖи´ÖÆÊý¾Ý,ʵÏÖ·½·¨:ÔÚinsert Óï¾äÖмÓÈë²éѯÓï¾ä
insert into sales_reps(id,name,salary,commission_pct) select employee_id,last_name,salary,commission_pct
from employees where job_id like '%rep';
(2) updateÖÐʹÓÃ×Ó²éѯ
update employees set job_id = (select job_id from employees where employee_id = 205),
salary = (select salary from employees where employee_id = 205)
where employee_id = 114;
È磺¸üÐÂ114ºÅÔ±¹¤µÄ¹¤×÷ºÍ¹¤×ÊʹÆäÓë205ºÅÔ±¹¤Ïàͬ
update employees set job_id = (select job_id from employees where employee_id = 205),
salary = (select salary from employees where employee_id = 205)
where employee_id = 114
ÔÙ¿´Ò»¸öÎÊÌ⣬×ÐϸÌå»á½â¾ö²½Ö裺
¸ü¸Ä 108 Ô±¹¤µÄÐÅÏ¢: ʹÆä ¹¤×ʱäΪËùÔÚ²¿ÃÅÖеÄ×î¸ß¹¤×Ê£¬job±äΪ¹«Ë¾ÖÐƽ¾ù¹¤×Ê×îµÍµÄjob
·ÖÎö£º
µÚ1 ²½ Ê×ÏȲéѯ 108 ËùÔÚ²¿ÃŵÄ×î¸ß¹¤×ÊÊǶàÉÙ
select max(salary) from employees where department_id =
( select department_id from employees where employee_id = 108)
µÚ 2 ²½ ²éѯ¹«Ë¾ÖÐƽ¾ù¹¤×Ê×îµÍµÄ job_id
select job_id from employees group by job_id having avg(salary) =
(select min(avg_sal) from(select avg(salary) avg_sal from employees group by job_id) )
µÚ 3 ²½ ʵÏÖ¸üÐÂ
update employees set salary = ( select max(salary) from employees
where department_id =
Ïà¹ØÎĵµ£º
¡¡¡¡Ò»¡¢Ê²Ã´ÊÇMTS
¡¡¡¡MTS = Multi-Threaded ServerMTSÊÇORACLE SERVERµÄÒ»¸ö¿ÉÑ¡µÄÅäÖÃÑ¡Ôñ£¬ÊÇÏà¶ÔDEDICATE·½Ê½¶øÑÔ£¬Ëü×î´óµÄÓŵãÊÇÔÚÒÔ²»ÓÃÔö¼ÓÎïÀí×ÊÔ´(ÄÚ´æ)µÄÇ°ÌáÏÂÖ§³Ö¸ü¶àµÄ²¢·¢µÄÁ¬½Ó¡£Joseph C.JohnsonÒԲ͹ݸø³öÒ»¸öMTSµÄÐÎÏóµÄ±ÈÓ÷
¡¡¡¡¼ÙÉèORACLEÊÇÒ»¼Ò²Í¹Ý£¬µ±Äã×ß½øÒ»¼Ò²Í¹ÝʱÄã¸Ð¾õ×îÊæ·þµÄ·þÎñ·½Ê½¾ÍÊ ......
ORACLE SQLÓï¾äÓÅ»¯×ܽá
1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, Ä ......
(1) v$sql
¡¡¡¡Ò»ÌõÓï¾ä¿ÉÒÔÓ³Éä¶à¸öcursor,ÒòΪ¶ÔÏóËùÖ¸µÄcursor¿ÉÒÔÓв»Í¬Óû§(ÈçÀý1)¡£Èç¹ûÓжà¸öcursor(×ÓÓαê)´æÔÚ£¬ÔÚV$SQLAREAΪËùÓÐcursorÌṩ¼¯ºÏÐÅÏ¢¡£
Àý1£º
ÕâÀï½éÉÜÒÔÏÂchild cursor
user A: select * from tbl
user B: select * from tbl
´ó¼ÒÈÏΪÕâÁ½ÌõÓï¾äÊDz»ÊÇÒ»ÑùµÄ°¡£¬¿ÉÄÜ»áÓкܶàÈË»á˵ÊÇÒ»Ñù ......
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º¯ÊýµÄд·¨Ïà¶Ô±È½Ï¼ò½à ......
Êý¾Ý×Öµädict×ÜÊÇÊôÓÚOracleÓû§sysµÄ¡£
1¡¢Óû§£º
¡¡select username from dba_users;
¸Ä¿ÚÁî
¡¡alter user spgroup identified by spgtest;
2¡¢±í¿Õ¼ä£º
¡¡select * from dba_data_files;
¡¡select * from dba_tablespaces;//±í¿Õ¼ä
¡¡select tablespace_name,sum(bytes), sum(blocks)
from dba_ ......