Bo's Oracle Station

查看: 2563|回复: 0

课程第11次(2017-03-19星期日晚上)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-3-20 10:38:34 | 显示全部楼层 |阅读模式
上完1Z0-051第3章:单行函数
上完1Z0-051第4章:转换函数/nvl/nvl2/nullif/coalesce以及decode和case
1Z0-051共12章(上完5章),1Z0-052共19章(上完3章),1Z0-053共21章(上完0章)

总共上完全部52章中的8章

pl/sql developper里的内容:
  1. SELECT employee_id, last_name, department_id
  2. FROM   employees
  3. WHERE  lower(last_name) = 'higgins';

  4. create index myindx on employees ( lower(last_name)  );



  5. create table t05103_a( a varchar2(4)  ) ;

  6. SELECT employee_id, last_name, department_id
  7. FROM   employees
  8. WHERE  lower(last_name) = 'higgins';

  9. create index myindx on employees ( lower(last_name)  );



  10. create table t05103_a( a varchar2(4)  ) ;


  11. select  substr('HelloWorld' , -5,1 ) from dual;

  12. ----

  13. select  trunc(45.926,-2)  from dual;

  14. ---

  15. select  sysdate from dual;
  16. ---

  17. select
  18.   to_char( to_Date ('27-OCT-95','DD-MON-RR'), 'YYYY-MM-DD')

  19. from dual;


  20. SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS,
  21.     months_between( sysdate,  hire_date)  months_sal
  22.    
  23. FROM   employees
  24. WHERE  department_id = 90;

  25. select to_char( add_months(sysdate ,12 ) ,'YYYY-MM-DD:HH24:MI:SS') from dual;

  26. select  next_day(sysdate,7)  from dual;

  27. select  round ( to_date('2017-07-01','YYYY-MM-DD'),'YEAR'   )  from dual;


  28. select  to_char(sysdate,'fmYYYY-MM-DD:HH24:MI:SS  "The number of day"  ddspth')
  29.   from dual;
  30.   
  31.   SELECT TO_CHAR(salary, '$999,999,999,999.00') SALARY
  32. FROM   employees
  33. WHERE  last_name = 'Ernst';


  34. SELECT TO_CHAR(salary, 'L999,999,999,999.00') SALARY
  35. FROM   employees
  36. WHERE  last_name = 'Ernst';

  37. ---
  38. select  to_number ( '$6,000.00', 'L999,999,999,999.00')   from dual;
  39. ----
  40. SELECT         TO_CHAR(    123456.78     ,'999G999D99',
  41.         'NLS_NUMERIC_CHARACTERS = ''-#'' '   )
  42.         "Formatted Salary"
  43. FROM employees;

  44. ---

  45. select  * from employees
  46.   where employee_id not in (
  47.   select  nvl(manager_id,0)  from employees );
  48.   
  49.   
  50.   select   employee_id, salary*(1+ nvl(e.commission_pct,0))*12
  51.    from employees  e ;
  52.    ---
  53.    
  54.    SELECT last_name, job_id, salary,
  55.        CASE job_id WHEN 'IT_PROG'  THEN  1.10*salary
  56.                    WHEN 'ST_CLERK' THEN  1.15*salary
  57.                    WHEN 'SA_REP'   THEN  1.20*salary
  58.        ELSE      salary END     "REVISED_SALARY"
  59. FROM   employees;

  60. SELECT last_name, job_id, salary,
  61.       decode ( job_id ,'IT_PROG' , 1.10*salary,
  62.                     'ST_CLERK' , 1.15*salary,
  63.                    'SA_REP' ,1.20*salary,  salary )   "REVISED_SALARY"
  64. FROM   employees;



  65. SELECT last_name, job_id, salary,
  66.        CASE  
  67.                   WHEN job_id='IT_PROG'  THEN  1.10*salary
  68.                     when last_name ='Hunold' then 2*salary
  69.                    WHEN job_id='ST_CLERK' THEN  1.15*salary
  70.                    WHEN job_id='SA_REP'   THEN  1.20*salary
  71.        ELSE      salary END     "REVISED_SALARY"
  72. FROM   employees;
  73. ---
  74. select   department_id, count(commission_pct) from employees  group by department_id ;

  75. select   employee_id , hire_date  from employees
  76. order by 2  ;

  77.     Y2001  Y2003 Y2005 Y2007
  78.     3           12      15        6
  79.    
  80.     ---
  81.    
  82.    
  83.     select          sum(   decode( to_char(hire_date, 'YYYY'), 2001,  1,0)  )          Y2001,
  84.                          sum(   decode( to_char(hire_date, 'YYYY'),  2003,  1,0)  )          Y2003,
  85.                        sum(   decode( to_char(hire_date, 'YYYY'),  2005,  1,0)  )             Y2005,
  86.                      sum(   decode( to_char(hire_date, 'YYYY'),  2007,  1,0)  )             Y2007
  87.                      
  88.                      from employees;
  89.          
复制代码

sqlplus里的内容:

  1. SQL> startup
  2. ORACLE instance started.

  3. Total System Global Area 6680915968 bytes
  4. Fixed Size                    2213936 bytes
  5. Variable Size                 3556771792 bytes
  6. Database Buffers         3087007744 bytes
  7. Redo Buffers                   34922496 bytes
  8. Database mounted.
  9. Database opened.
  10. SQL> select  * from dual;

  11. D
  12. -
  13. X

  14. SQL> conn hr/oracle_4U
  15. Connected.
  16. SQL> insert into t05103_a values ('中国');
  17. insert into t05103_a values ('中国')
  18.                              *
  19. ERROR at line 1:
  20. ORA-12899: value too large for column "HR"."T05103_A"."A" (actual: 6, maximum: 4)


  21. SQL> alter table t05103_a modify ( a  varchar2(6))  ;

  22. Table altered.

  23. SQL> insert into t05103_a values ('中国');

  24. 1 row created.

  25. SQL> commit;

  26. Commit complete.

  27. SQL> select  length(a)  from t05103_a;

  28. LENGTH(A)
  29. ----------
  30.          2

  31. SQL> select  lengthb(a)  from t05103_a;

  32. LENGTHB(A)
  33. ----------
  34.          6

  35. SQL> select  sysdate from dual;

  36. SYSDATE
  37. ------------------
  38. 19-MAR-17

  39. SQL> select  to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS')   from dual;

  40. TO_CHAR(SYSDATE,'YY
  41. -------------------
  42. 2017-03-19:20:03:21

  43. SQL> exit
  44. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  45. With the Partitioning, Automatic Storage Management, OLAP, Data Mining
  46. and Real Application Testing options
  47. [oracle@station90 ~]$ sqlplus /nolog

  48. SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 19 20:05:30 1999

  49. Copyright (c) 1982, 2009, Oracle.  All rights reserved.

  50. SQL> conn hr/oracle_4U
  51. Connected.
  52. SQL>  select  to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS')   from dual;

  53. TO_CHAR(SYSDATE,'YY
  54. -------------------
  55. 1999-03-19:20:05:49

  56. SQL> exit
  57. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  58. With the Partitioning, Automatic Storage Management, OLAP, Data Mining
  59. and Real Application Testing options
  60. [oracle@station90 ~]$ sqlplus /nolog

  61. SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 19 20:08:36 2017

  62. Copyright (c) 1982, 2009, Oracle.  All rights reserved.

  63. SQL> conn hr/oracle_$U
  64. ERROR:
  65. ORA-01017: invalid username/password; logon denied


  66. SQL> conn hr/oracle_4U
  67. Connected.
  68. SQL> select  sysdate from dual;

  69. SYSDATE
  70. ------------------
  71. 19-MAR-17

  72. SQL>  select  to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS')   from dual;

  73. TO_CHAR(SYSDATE,'YY
  74. -------------------
  75. 2017-03-19:20:08:53

  76. SQL> select  next_day(sysdate,7)  from dual;

  77. NEXT_DAY(SYSDATE,7
  78. ------------------
  79. 25-MAR-17

  80. SQL> select  to_char(next_day(sysdate,7),'YYYY-MM-DD:HH24:MI:SS')   from dual;

  81. TO_CHAR(NEXT_DAY(SY
  82. -------------------
  83. 2017-03-25:20:26:05

  84. SQL> alter session set nls_territory='australia';

  85. Session altered.

  86. SQL> select  to_char(next_day(sysdate,7),'YYYY-MM-DD:HH24:MI:SS')   from dual;

  87. TO_CHAR(NEXT_DAY(SY
  88. -------------------
  89. 2017-03-26:20:27:03

  90. SQL> select  to_char(next_day(sysdate,'Sunday'),'YYYY-MM-DD:HH24:MI:SS')  from dual;

  91. TO_CHAR(NEXT_DAY(SY
  92. -------------------
  93. 2017-03-26:20:29:11

  94. SQL> select  to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS')  from dual;

  95. TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
  96. -----------------------------------------------------
  97. 2017-MARCH    -19:20:51:46

  98. SQL> alter session set nls_language='simplified chinese';

  99. Session altered.

  100. SQL> select  to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS')  from dual;

  101. TO_CHAR(SYSDATE,'YYYY-MON
  102. -------------------------
  103. 2017-3月 -19:20:53:19

  104. SQL> alter session set nls_language='korean';

  105. Session altered.

  106. SQL> select  to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS')  from dual;

  107. TO_CHAR(SYSDATE,'YYYY-MON
  108. -------------------------
  109. 2017-3월 -19:20:53:34

  110. SQL> alter session set nls_language='german';

  111. Session altered.

  112. SQL> select  to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS')  from dual;

  113. TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
  114. -----------------------------------------------------
  115. 2017-MÄRZ     -19:20:54:16

  116. SQL>  alter session set nls_language='italian' ;

  117. Session altered.

  118. SQL> select  to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS')  from dual;

  119. TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
  120. -----------------------------------------------------
  121. 2017-MARZO    -19:20:55:58

  122. SQL> alter session set nls_territory='australia';

  123. Session altered.

  124. SQL> select  to_char(sysdate,'fmYYYY-MM-DD:HH24:MI:SS  D')  from dual;

  125. TO_CHAR(SYSDATE,'FMYYY
  126. ----------------------
  127. 2017-3-19:20:58:32  7

  128. SQL>
复制代码


回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-12-5 09:45 , Processed in 0.041028 second(s), 24 queries .

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