Bo's Oracle Station

查看: 2863|回复: 0

课程第13/14次(2017-03-26星期日上下午)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-3-26 10:37:10 | 显示全部楼层 |阅读模式
本帖最后由 botang 于 2017-3-26 17:44 编辑

上完1Z0-051第7章:子查询和关联子查询
上完1Z0-051第8章:集操作符
上完1Z0-051第9章:DML
上完1Z0-052第9章:锁
1Z0-051共12章(上完10章),1Z0-052共19章(上完4章),1Z0-053共21章(上完0章)
总共上完全部52章中的14章
  1. select  distinct department_id, last_name from employees;

  2. select   department_id, last_name , count(*)
  3. from employees
  4. group by department_id, last_name;

  5. create table t05107 ( a  number , b varchar2(20),   id number ) ;
  6. /*
  7. 1 A 100
  8. 1 B 200
  9. 2 A 300
  10. --2 B 400
  11. */

  12. select  * from t05107  where
  13. a   in (select  a from   t05107 where id in (100,200,300))
  14. and b  in ( select  b from   t05107 where id in (100, 200,300));


  15. select  * from t05107  where
  16. (a,b)   in (  select  a,b  from   t05107 where id in (100,200,300))
  17. ;

  18. ---
  19. SELECT * FROM departments
  20. WHERE NOT EXISTS
  21. (SELECT 'X' FROM employees
  22. WHERE employees.department_id=departments.department_id);
  23.   

  24. SELECT * FROM departments
  25. WHERE   manager_id  NOT in
  26. (SELECT   employees.employee_id   FROM employees
  27. WHERE employees.department_id=departments.department_id);

  28. SELECT * FROM departments
  29.   where manager_id   is null;
  30.   
  31.   
  32.    
  33. SELECT last_name, salary, department_id
  34. FROM   employees outer
  35. WHERE  salary >
  36.     (SELECT AVG(salary)
  37. FROM   employees
  38. WHERE  department_id =  
  39.         outer.department_id) ;
  40.         
  41.      SELECT e.last_name, e.salary,   a.avgsal   ,e.department_id
  42. FROM   employees e ,  (SELECT AVG(salary) avgsal ,  department_id
  43.                                       FROM   employees
  44.                                         group by  department_id )   a        
  45.         
  46. WHERE     e.department_id=a.department_id  and    e.salary > a.avgsal
  47.     ;   
  48.         
  49. ----

  50. create table  t05107_a ( a number) ;
  51.   insert into t05107_a  values (1) ;
  52.   insert into t05107_a  values (2) ;
  53.   insert into t05107_a  values (3) ;
  54.   insert into t05107_a  values (4) ;
  55. commit;

  56. select  * from t05107_a;
  57.   create table  t05107_b ( a number) ;
  58.     insert into t05107_b  values (1) ;
  59.   insert into t05107_b  values (2) ;
  60.   commit;
  61.   select * from t05107_b;
  62.   insert into t05107_b  values (3);
  63.   
  64.    commit;



  65. delete from t05107_a  a  where exists ( select  'X' from t05107_b  b
  66.    where  a.a=b.a) ;
  67.    
  68.    delete from t05107_a  a  where a in  ( select  a  from t05107_b  b
  69.    where  a.a=b.a) ;

  70. ----


  71. select  * from job_history
  72.   order by 1,2;
  73.   
  74.   select   job_id from employees where employee_id=102;
  75.   
  76.   
  77.   SELECT employee_id, job_id
  78. FROM   employees where employee_id in (101,176,200)
  79. intersect
  80. SELECT employee_id, job_id
  81. FROM   job_history  where employee_id in (101,176,200)
  82. ;


  83. ---
  84. SELECT employee_id
  85. FROM   employees
  86. MINUS
  87. SELECT employee_id
  88. FROM   job_history;

  89. ----
  90. SELECT employee_id, job_id
  91. FROM    job_history
  92. MINUS
  93. SELECT employee_id, job_id
  94. FROM employees ;
  95. ---
  96. SELECT location_id, department_name "Department",
  97.    NULL   "Warehouse location"  
  98. FROM departments
  99. UNION
  100. SELECT location_id, NULL   "Department",
  101.    state_province
  102. FROM locations;

  103. ---
  104. create table t05108_i ( a number ) ;

  105. insert into t05108_i(a)  values ( 1);

  106. insert into t05108_i select  * from t05108_i;

  107. select  count(*) from t05108_i;


复制代码

  1. insert into t05108_i select  * from t05108_i;

  2. select  count(*) from t05108_i;

  3. select  bytes/1024/1024  from user_segments s
  4. where s.segment_name='T05108_I';

  5. select  salary from employees where employee_id=100;
  6. create table t05108_d as select  * from  t05108_i;

  7. select  count(*) from t05108_d;

  8. select  bytes/1024/1024  from user_segments s
  9. where s.segment_name='T05108_D';

  10. ----

  11. select  salary from employees where employee_id=100;

  12. ---poor
  13. select   s.SID ,s.SERIAL#, s.BLOCKING_SESSION,status, s.SQL_HASH_VALUE , s.SQL_ID
  14. from v_$session s
  15.   where s.blocking_session  is not null;

  16. --killer
  17.   select SID, SERIAL#, USERNAME
  18.                 from V$SESSION where SID in
  19.                 (select BLOCKING_SESSION from V$SESSION);


  20. alter system kill session '17,21598' immediate;
  21.   
  22. select  sid, serial# from v$session where sid =198;
  23.   
  24.   select * from v_$session  s where s.TERMINAL='pts/2';
  25.   
  26.   
  27.   select  * from v_$sql s where s.SQL_ID='64516t36mp029';
  28.   
  29.   select  * from (
  30.     select  * from v_$sql s  order by s.APPLICATION_WAIT_TIME  desc )
  31.      where rownum  <=5;
  32.      
  33.      select  * from v$lock where sid in (17, 198);
  34.      
  35.      
  36.      
  37.   
复制代码
  1. SQL> conn hr/oracle_4U
  2. Connected.
  3. SQL> create table t_dead (id number , sal number(8,2) ,mgr number     );

  4. Table created.

  5. SQL> insert into t_dead  values (100,  1000.00 ,  101 );

  6. 1 row created.

  7. SQL> insert into t_dead  values (200,  2000.00 ,  201 );

  8. 1 row created.

  9. SQL>
  10. SQL> commit;

  11. Commit complete.

  12. SQL> update t_dead set sal=1000.01 where id=100;

  13. 1 row updated.

  14. SQL> update t_dead set sal=2000.01 where id=200;
  15. update t_dead set sal=2000.01 where id=200
  16.        *
  17. ERROR at line 1:
  18. ORA-00060: deadlock detected while waiting for resource


  19. SQL> select  * from t_dead;

  20.         ID          SAL             MGR
  21. ---------- ---------- ----------
  22.        100    1000.01             101
  23.        200         2000             201

  24. SQL> commit;

  25. Commit complete.

  26. SQL> update t_dead set sal=2000.01 where id=200;

  27. 1 row updated.

  28. SQL> commit;

  29. Commit complete.

  30. SQL> select  * from t_dead;

  31.         ID          SAL             MGR
  32. ---------- ---------- ----------
  33.        100    1000.01             102
  34.        200    2000.01             202

  35. SQL>
复制代码






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-25 15:55 , Processed in 0.034652 second(s), 24 queries .

快速回复 返回顶部 返回列表