|
上完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里的内容:
- SELECT employee_id, last_name, department_id
- FROM employees
- WHERE lower(last_name) = 'higgins';
- create index myindx on employees ( lower(last_name) );
- create table t05103_a( a varchar2(4) ) ;
- SELECT employee_id, last_name, department_id
- FROM employees
- WHERE lower(last_name) = 'higgins';
- create index myindx on employees ( lower(last_name) );
- create table t05103_a( a varchar2(4) ) ;
- select substr('HelloWorld' , -5,1 ) from dual;
- ----
- select trunc(45.926,-2) from dual;
- ---
- select sysdate from dual;
- ---
- select
- to_char( to_Date ('27-OCT-95','DD-MON-RR'), 'YYYY-MM-DD')
- from dual;
- SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS,
- months_between( sysdate, hire_date) months_sal
-
- FROM employees
- WHERE department_id = 90;
- select to_char( add_months(sysdate ,12 ) ,'YYYY-MM-DD:HH24:MI:SS') from dual;
- select next_day(sysdate,7) from dual;
- select round ( to_date('2017-07-01','YYYY-MM-DD'),'YEAR' ) from dual;
- select to_char(sysdate,'fmYYYY-MM-DD:HH24:MI:SS "The number of day" ddspth')
- from dual;
-
- SELECT TO_CHAR(salary, '$999,999,999,999.00') SALARY
- FROM employees
- WHERE last_name = 'Ernst';
- SELECT TO_CHAR(salary, 'L999,999,999,999.00') SALARY
- FROM employees
- WHERE last_name = 'Ernst';
- ---
- select to_number ( '$6,000.00', 'L999,999,999,999.00') from dual;
- ----
- SELECT TO_CHAR( 123456.78 ,'999G999D99',
- 'NLS_NUMERIC_CHARACTERS = ''-#'' ' )
- "Formatted Salary"
- FROM employees;
- ---
- select * from employees
- where employee_id not in (
- select nvl(manager_id,0) from employees );
-
-
- select employee_id, salary*(1+ nvl(e.commission_pct,0))*12
- from employees e ;
- ---
-
- SELECT last_name, job_id, salary,
- CASE job_id WHEN 'IT_PROG' THEN 1.10*salary
- WHEN 'ST_CLERK' THEN 1.15*salary
- WHEN 'SA_REP' THEN 1.20*salary
- ELSE salary END "REVISED_SALARY"
- FROM employees;
- SELECT last_name, job_id, salary,
- decode ( job_id ,'IT_PROG' , 1.10*salary,
- 'ST_CLERK' , 1.15*salary,
- 'SA_REP' ,1.20*salary, salary ) "REVISED_SALARY"
- FROM employees;
- SELECT last_name, job_id, salary,
- CASE
- WHEN job_id='IT_PROG' THEN 1.10*salary
- when last_name ='Hunold' then 2*salary
- WHEN job_id='ST_CLERK' THEN 1.15*salary
- WHEN job_id='SA_REP' THEN 1.20*salary
- ELSE salary END "REVISED_SALARY"
- FROM employees;
- ---
- select department_id, count(commission_pct) from employees group by department_id ;
- select employee_id , hire_date from employees
- order by 2 ;
- Y2001 Y2003 Y2005 Y2007
- 3 12 15 6
-
- ---
-
-
- select sum( decode( to_char(hire_date, 'YYYY'), 2001, 1,0) ) Y2001,
- sum( decode( to_char(hire_date, 'YYYY'), 2003, 1,0) ) Y2003,
- sum( decode( to_char(hire_date, 'YYYY'), 2005, 1,0) ) Y2005,
- sum( decode( to_char(hire_date, 'YYYY'), 2007, 1,0) ) Y2007
-
- from employees;
-
复制代码
sqlplus里的内容:
- SQL> startup
- ORACLE instance started.
- Total System Global Area 6680915968 bytes
- Fixed Size 2213936 bytes
- Variable Size 3556771792 bytes
- Database Buffers 3087007744 bytes
- Redo Buffers 34922496 bytes
- Database mounted.
- Database opened.
- SQL> select * from dual;
- D
- -
- X
- SQL> conn hr/oracle_4U
- Connected.
- SQL> insert into t05103_a values ('中国');
- insert into t05103_a values ('中国')
- *
- ERROR at line 1:
- ORA-12899: value too large for column "HR"."T05103_A"."A" (actual: 6, maximum: 4)
- SQL> alter table t05103_a modify ( a varchar2(6)) ;
- Table altered.
- SQL> insert into t05103_a values ('中国');
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select length(a) from t05103_a;
- LENGTH(A)
- ----------
- 2
- SQL> select lengthb(a) from t05103_a;
- LENGTHB(A)
- ----------
- 6
- SQL> select sysdate from dual;
- SYSDATE
- ------------------
- 19-MAR-17
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2017-03-19:20:03:21
- SQL> exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
- With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- and Real Application Testing options
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 19 20:05:30 1999
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 1999-03-19:20:05:49
- SQL> exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
- With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- and Real Application Testing options
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Sun Mar 19 20:08:36 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_$U
- ERROR:
- ORA-01017: invalid username/password; logon denied
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select sysdate from dual;
- SYSDATE
- ------------------
- 19-MAR-17
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2017-03-19:20:08:53
- SQL> select next_day(sysdate,7) from dual;
- NEXT_DAY(SYSDATE,7
- ------------------
- 25-MAR-17
- SQL> select to_char(next_day(sysdate,7),'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(NEXT_DAY(SY
- -------------------
- 2017-03-25:20:26:05
- SQL> alter session set nls_territory='australia';
- Session altered.
- SQL> select to_char(next_day(sysdate,7),'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(NEXT_DAY(SY
- -------------------
- 2017-03-26:20:27:03
- SQL> select to_char(next_day(sysdate,'Sunday'),'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(NEXT_DAY(SY
- -------------------
- 2017-03-26:20:29:11
- SQL> select to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
- -----------------------------------------------------
- 2017-MARCH -19:20:51:46
- SQL> alter session set nls_language='simplified chinese';
- Session altered.
- SQL> select to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YYYY-MON
- -------------------------
- 2017-3月 -19:20:53:19
- SQL> alter session set nls_language='korean';
- Session altered.
- SQL> select to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YYYY-MON
- -------------------------
- 2017-3월 -19:20:53:34
- SQL> alter session set nls_language='german';
- Session altered.
- SQL> select to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
- -----------------------------------------------------
- 2017-MÄRZ -19:20:54:16
- SQL> alter session set nls_language='italian' ;
- Session altered.
- SQL> select to_char(sysdate,'YYYY-MONTH-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YYYY-MONTH-DD:HH24:MI:SS')
- -----------------------------------------------------
- 2017-MARZO -19:20:55:58
- SQL> alter session set nls_territory='australia';
- Session altered.
- SQL> select to_char(sysdate,'fmYYYY-MM-DD:HH24:MI:SS D') from dual;
- TO_CHAR(SYSDATE,'FMYYY
- ----------------------
- 2017-3-19:20:58:32 7
- SQL>
复制代码
|
|