Bo's Oracle Station

查看: 1770|回复: 0

课程第44次:2016-07-06星期三

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2016-7-7 10:06:18 | 显示全部楼层 |阅读模式
本帖最后由 botang 于 2016-7-7 10:09 编辑

【上完1Z0-051的第10章】DDL和表以及约束
【开始1Z0-051的第11章】其他Oracle Schema对象
【1Z0-051】:共11章0 1 2 3 4 5 6 7 8 9 10 11)这本书快上完了
【1Z0-052】:共13章(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
【1Z0-053】:共15章(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
表示已经上过的,表示还没上的。
完全按照上课顺序:
https://www.botangdb.com/mytrain/201601/00000028.html
  1. create table t05110_a ( a  number default 999 , b varchar2(20)  default 'AAA' ) ;

  2. select  * from user_Tab_columns t where t.TABLE_NAME='T05110_A';

  3. alter table t05110_a modify ( b default 'BBB') ;

  4. insert into t05110_a values (default, default);

  5. select * from t05110_a;

  6. ----

  7. create table t05110_clob( a  number , b clob ) ;

  8. insert into t05110_clob  values (1,'AAAAAA') ;


  9. select  * from t05110_clob ;

  10. select  * from user_objects o where o.OBJECT_NAME='T05110_CLOB';

  11. 80630

  12. select  * from user_objects o where o.OBJECT_NAME  like '%80630%';

  13. select  * from user_lobs;


  14. create table t05110_blob ( a  varchar2(20)  , b blob )  ;


  15. CREATE OR REPLACE PROCEDURE  procblob
  16.    ( p_dir  VARCHAR2, p_file  VARCHAR2)
  17. IS
  18.    v_f  BFILE;
  19.    v_b blob;
  20. BEGIN
  21.     INSERT INTO t05110_blob values( p_file,   EMPTY_BLOB ()) RETURN   b    into v_b;
  22.     v_f := BFILENAME (p_dir, p_file);
  23.    DBMS_LOB.FILEOPEN  (v_f, DBMS_LOB.FILE_READONLY);
  24.    DBMS_LOB.LOADFROMFILE (v_b, v_f,   DBMS_LOB.GETLENGTH (v_f));
  25.    DBMS_LOB.FILECLOSE (v_f);
  26.    commit;
  27. end;
  28.    
  29. select  * from user_errors;

  30.   

  31. begin
  32.     procblob ('PHOTODIR','computer.jpg');
  33.   end;
  34.   
  35.   
  36.   select  * from t05110_blob;

  37. ----

  38. create table t05110_time1(  a  INTERVAL YEAR(3) TO MONTH );

  39. insert into t05110_time1  values ( INTERVAL  '123-4'  YEAR(3) TO MONTH );

  40. select * from t05110_time1 ;

  41. select sysdate+a  from t05110_time1 ;

  42. create table t05110_time2 (  a  INTERVAL  DAY(3) to second(3) );

  43. insert into  t05110_time2 values (  INTERVAL '4 13:50:6.333' DAY(3) to second(3)  ) ;

  44. select  * from t05110_time2;

  45. select sysdate+a  from t05110_time2 ;

  46. -----


  47. create table t05110_nn(  a  number not null );

  48. insert into t05110_nn values  (1 );
  49. commit;

  50. select * from user_constraints c where c.TABLE_NAME='T05110_NN';

  51. create table t05110_nn2(  a  number   constraint  c_t05110_nn  not null );
  52. insert into t05110_nn2 values  (1);

  53. commit;
  54. select * from user_constraints c where c.TABLE_NAME='T05110_NN2';

  55. create table t1 as select * from t05110_nn;

  56. create table t2 as select  * from t05110_nn2;



  57. select * from user_constraints c where c.TABLE_NAME  in ('T1','T2');

  58. create table t05110_nn3(  a  number  , constraint  c_t05110_nn3   check( a is  not null) );

  59. insert into t05110_nn3 values  (1);

  60. select * from user_constraints c where c.TABLE_NAME='T05110_NN3';

  61. create table t3 as select  * from t05110_nn3;

  62. select  * from t3;

  63. select  * from t05110_nn4;

  64. select * from user_constraints c where c.TABLE_NAME  in ('T1','T2','T3');

  65. create table t05110_nn4 ( a  number )  ;

  66. select * from user_constraints c where c.TABLE_NAME='T05110_NN4';

  67. insert into t05110_nn4 values (null);

  68. select  * from t05110_nn4;

  69. alter table t05110_nn4 add constraint c_t05110_nn4 check ( a is not null) enable novalidate;

  70. select * from user_constraints c where c.TABLE_NAME='T05110_NN4';

  71. create table t05110_nn5( a number ,
  72.            constraint c_t05110_nn5 check ( a is not null )  disable  validate ) ;
  73.            
  74.      insert into t05110_nn5  values (1) ;
  75.      
  76.      ---
  77.      
  78.      select * from exceptions;
  79.      
  80.      alter table t05110_nn4 modify constraint c_t05110_nn4
  81.          enable validate exceptions  into exceptions;
  82.          
  83.             select * from exceptions;
  84.             
  85.             select  * from t05110_nn4 where rowid='AAATsJAAEAAAAPMAAA';
  86.             
  87.             update  t05110_nn4   set a=1  where rowid='AAATsJAAEAAAAPMAAA';
  88.             
  89.             ----
  90.             
  91.             create table t05110_unique1 ( a  number
  92.                            constraint c_t05110_unique1 unique );
  93.                            
  94.                            select  * from user_indexes i where i.TABLE_NAME='T05110_UNIQUE1';
  95.                 select  * from user_constraints c where c.TABLE_NAME='T05110_UNIQUE1';
  96.                
  97.                insert into  t05110_unique1 values (1) ;
  98.                
  99.                select  * from t05110_unique1 ;
  100.                
  101.                insert into t05110_unique1 values (null);
  102.             
  103.               insert into t05110_unique1 values (null);
  104.               
  105.               create table t05110_unique2 (a  number
  106.                            constraint c_t05110_unique2 unique    deferrable  initially  deferred ) ;
  107.                            
  108.               select  * from user_indexes i where i.TABLE_NAME='T05110_UNIQUE2';
  109.                 select  * from user_constraints c where c.TABLE_NAME='T05110_UNIQUE2';
  110.                
  111.                 insert into      t05110_unique2      values ( 1 ) ;  
  112.                
  113.                      insert into      t05110_unique2      values ( 1 ) ;  
  114.                      
  115.                            insert into      t05110_unique2      values ( 1 ) ;  
  116.                            
  117.                            select * from    t05110_unique2   ;
  118.                            
  119.                            commit;
  120.                            -----
  121.             create table t05110_unique3 ( a  number ) ;  
  122.             
  123.             create  unique index  i05110_unique3  on      t05110_unique3 ( a);      
  124.             
  125.            alter table    t05110_unique3 add constraint c_t05110_unique3  
  126.               unique( a )  not deferrable initially  immediate  ;
  127.               
  128.               
  129.               ---
  130.               
  131.     create table t05110_parent ( a   number   constraint c_t05110_parent primary key ) ;
  132.    
  133.     insert into t05110_parent values (1) ;
  134.    
  135.     create table
  136.        t05110_son ( b number constraint c_t05110_son referencing t05110_parent
  137.                             on delete set null )  ;
  138.                            
  139.        insert into  t05110_son values (1) ;
  140.       
  141.        select  * from t05110_parent;
  142.        select  * from t05110_son ;
  143.                            
  144.       delete from t05110_parent where a=1;
  145.       commit;
  146.    
  147.     ----
  148.     create table t05110_check ( a   number  constraint  c_t05110_check  
  149.       check ( a >7 )) ;
  150.       
  151.      insert into t05110_check values (8) ;
  152.      
  153.      update  t05110_check set a=9 where a=88;
  154.      
  155.      ---
  156.      create or replace trigger trgvalue
  157.       after update  or insert  on t05110_check
  158. referencing old as old new as new
  159. for each row
  160. begin
  161.    if  :old.a  >=  :new.a
  162.    then
  163.       raise_application_error(-20999,'Must biger');
  164.    end if;
  165. end ;

  166. select  * from t05110_check;
  167.      
  168.      select * from user_triggers;
  169.      
  170.      
  171.      update  t05110_check set a=9 ;
  172.       
  173.      insert into t05110_check  values ( 8 ) ;
  174.      
  175.      select  * from t05110_check;
  176.      
  177.      update  t05110_check set a=9  where a=8;
  178.      
  179.      ---
  180.      
  181.      create  or replace view  v05110_a  
  182.       as ( select   employee_id ,  department_id  
  183.          from employees  where department_id=10 ) ;   
  184.          
  185.         select  * from v05110_a;
  186.         
  187.         update  v05110_a set department_id=20  where employee_id=200;
  188.         
  189.         
  190.      create  or replace view  v05110_a  
  191.       as ( select   employee_id ,  department_id  
  192.          from employees  where department_id=20 )   with check option  ;  
  193.          
  194.          select  * from   v05110_a;
  195.          
  196.          update v05110_a set department_id=10 where employee_id=200;
  197.                          ---
  198.                         
  199.                          create table t05311_a ( a  number ) ;
  200.                         
  201.                          insert into t05311_a values (1) ;
  202.                         
  203.                          create view  v05311_a as ( select a*2  b    from
  204.                              t05311_a ) ;
  205.                              
  206.                              select  * from v05311_a;
  207.                              update v05311_a  set b=4 where b=2;
  208.                              
  209.                              ---
  210.                              delete from v05311_a;
  211.                              
  212.                              select  * from t05311_a;
  213.                              ---
  214.                              
  215.                              create sequence seq1 ;
  216.       select  * from user_sequences  where sequence_name='SEQ1';
  217.       
  218.       
  219.       select  seq1.nextval  from  dual;
  220.                              
复制代码



回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-20 00:50 , Processed in 0.039131 second(s), 24 queries .

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