Chapter 4 : 单行函数

SELECT LOWER('SQL: Structural Query Language')
from dual;

//dual 是一个虚表(伪表)。
UPPER(列名|表达式)

SELECT UPPER('sql is used exclusively in rdbmses')
from dual;

SELECT INITCAP('sql is an ENGLISH LIKE language')
from dual;
Output: Sql Is An English Like Language

select concat('SQL allows you to manipulate the data in DB',
              ' without any programming knowledge')
from dual;

select substr('',14)
from dual;


4-4
//TODO


Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as SYS


SQL> select Lower('SQL:Structural Quary Languae')
  2  from dual;

LOWER('SQL:STRUCTURALQUARYLANG
------------------------------
sql:structural quary languae

SQL>
SQL> select uper('sql is used exclusively inrdbmses')
  2  from dual;

select uper('sql is used exclusively inrdbmses')
from dual

ORA-00904: "UPER": 标识符无效

SQL>
SQL> select upper('sql is used exclusively inrdbmses')
  2  from dual;

UPPER('SQLISUSEDEXCLUSIVELYINR
---------------------------------
SQL IS USED EXCLUSIVELY INRDBMSES

SQL>
SQL> select initcap('sql is used exclusively inrdbmses')
  2  from dual;

INITCAP('SQLISUSEDEXCLUSIVELYI
---------------------------------
Sql Is Used Exclusively Inrdbmses

SQL> select concat('i love','baobao')
  2  from dual;

CONCAT('ILOVE','BAOBAO')
------------------------
i lovebaobao

SQL> select substr('i need a job',2,5)
  2  from dual;

SUBSTR('INEEDAJOB',2,5)
-----------------------
 need

SQL> select length('i need a job')
  2  from dual;

LENGTH('INEEDAJOB')
-------------------
                 12

SQL> select instr('i need a job','e')
  2  from dual;

INSTR('INEEDAJOB','E')
----------------------
                     4

SQL> select instr('i need a job','a')
  2  from dual;

INSTR('INEEDAJOB','A')
----------------------
                     8

SQL> select instr('i need a job','z')
  2  from dual
  3  ;

INSTR('INEEDAJOB','Z')
----------------------
                     0

SQL> select instr('i need a job','a')
  2  from dual
  3  ;

INSTR('INEEDAJOB','A')
----------------------
                     8

SQL> select instr('i need a job','a',7)
  2  from dual;

INSTR('INEEDAJOB','A',7)
------------------------
                       8

SQL> select instr('i need a job','a',11)
  2  from dual;

INSTR('INEEDAJOB','A',11)
-------------------------
                        0

SQL> trim('?'FROM'?SQL*PLUSISTHESQLIMPLEMENTATIONUSEDINANORACLERDBMSORORDBMS.');

trim('?'FROM'?SQL*PLUSISTHESQLIMPLEMENTATIONUSEDINANORACLERDBMSORORDBMS.')

ORA-00900: 无效 SQL 语句

SQL> select trim('?'FROM'?SQL*PLUSISTHESQLIMPLEMENTATIONUSEDINANORACLERDBMSORORDBMS.')
  2  from dual;

TRIM('?'FROM'?SQL*PLUSISTHESQL
----------------------------------------------------------
SQL*PLUSISTHESQLIMPLEMENTATIONUSEDINANORACLERDBMSORORDBMS.

SQL> select trim('?' from 'It can process data insetsof rows??')
  2  from dual
  3  ;

TRIM('?'FROM'ITCANPROCESSDATAI
---------------------------------
It can process data insetsof rows

SQL> select trim('s' from 'It can process data insetsof rows??')
  2  from dual;

TRIM('S'FROM'ITCANPROCESSDATAI
-----------------------------------
It can process data insetsof rows??

SQL> select trim('s' from 'It can process data insetsof rows??')
  2  from dual;

TRIM('S'FROM'ITCANPROCESSDATAI
-----------------------------------
It can process data insetsof rows??

SQL> select trim(trailing's' from 'It can process data insetsof rows??')
  2  from dual;

TRIM(TRAILING'S'FROM'ITCANPROC
-----------------------------------
It can process data insetsof rows??

SQL>
SQL> select trim(trailing's' from 'sIt can process data insetsof rows??')
  2  from dual;

TRIM(TRAILING'S'FROM'SITCANPRO
------------------------------------
sIt can process data insetsof rows??

SQL> select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
  2  from dual;
  3  ;
  4  select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
  5  from dual;

select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
from dual;
;
select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
from dual

ORA-00907: 缺失右括号

SQL>
SQL> select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
  2  from dual;
  3  select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
  4  from dual;

select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
from dual;
select replace('sql*plus supports loops or if statements','suppoerts','doesn't support')
from dual

ORA-00907: 缺失右括号

SQL> select replace('sql*plus supports loops or if statements','suppoerts','does not support')
  2  from dual;

REPLACE('SQL*PLUSSUPPORTSLOOPS
----------------------------------------
sql*plus supports loops or if statements

SQL> select replace('sql*plus supports loops or if statements','suppoerts','does not support')
  2  from dual;

REPLACE('SQL*PLUSSUPPORTSLOOPS
----------------------------------------
sql*plus supports loops or if statements

SQL>
SQL> select replace('sql*plus supports loops or if statements','supports','does not support')
  2  from dual
  3  ;

REPLACE('SQL*PLUSSUPPORTSLOOPS
------------------------------------------------
sql*plus does not support loops or if statements

SQL> select * from emp;

EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
 7369 SMITH      CLERK      7902 1980-12-17     800.00               20
 7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30
 7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30
 7566 JONES      MANAGER    7839 1981-4-2      2975.00               20
 7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30
 7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30
 7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10
 7839 KING       PRESIDENT       1981-11-17    5000.00               10
 7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30
 7900 JAMES      CLERK      7698 1981-12-3      950.00               30
 7902 FORD       ANALYST    7566 1981-12-3     3000.00               20
 7934 MILLER     CLERK      7782 1982-1-23     1300.00               10

12 rows selected

SQL> select empno,ename,job
  2  from emp
  3  where job='salesman';

EMPNO ENAME      JOB
----- ---------- ---------

SQL> select empno,ename,job
  2  where job='salesman';

select empno,ename,job
where job='salesman'

ORA-00923: 未找到要求的 FROM 关键字

SQL> select empno,ename,job
  2  from emp
  3  where job='SALESMAN';

EMPNO ENAME      JOB
----- ---------- ---------
 7499 ALLEN      SALESMAN
 7521 WARD       SALESMAN
 7654 MARTIN     SALESMAN
 7844 TURNER     SALESMAN

SQL> select concat(ename,job)"Employee",substr(job,1,5)"Title",length(ename)"Length",instr(job,'M')
  2  from emp
  3  where lower(job)="SALESMAN";

select concat(ename,job)"Employee",substr(job,1,5)"Title",length(ename)"Length",instr(job,'M')
from emp
where lower(job)="SALESMAN"

ORA-00904: "SALESMAN": 标识符无效

SQL> select concat(ename,job)"Employee",substr(job,1,5)"Title",length(ename)"Length",instr(job,'M')
  2  from emp
  3  where lower(job)="salesman";

select concat(ename,job)"Employee",substr(job,1,5)"Title",length(ename)"Length",instr(job,'M')
from emp
where lower(job)="salesman"

ORA-00904: "salesman": 标识符无效

SQL> select concat(ename,job)"Employee",substr(job,1,5)"Title",length(ename)"Length",instr(job,'M')
  2  from emp
  3  where lower(job)='salesman';

Employee            Title          Length INSTR(JOB,'M')
------------------- ---------- ---------- --------------
ALLENSALESMAN       SALES               5              6
WARDSALESMAN        SALES               4              6
MARTINSALESMAN      SALES               6              6
TURNERSALESMAN      SALES               6              6

SQL> select round(166.888,1),trunc(166.88,1)
  2  from dual;

ROUND(166.888,1) TRUNC(166.88,1)
---------------- ---------------
           166.9           166.8

SQL> select round(166.888,2),trunc(166.88,2)
  2  from dual;

ROUND(166.888,2) TRUNC(166.88,2)
---------------- ---------------
          166.89          166.88

SQL> select round(166.448,2),trunc(166.448,2)
  2  from dual;

ROUND(166.448,2) TRUNC(166.448,2)
---------------- ----------------
          166.45           166.44

SQL> select round(166.444,2),trunc(166.444,2)
  2  from dual;

ROUND(166.444,2) TRUNC(166.444,2)
---------------- ----------------
          166.44           166.44

SQL> select round(166.888),trunc(166.888)
  2  from dual;

ROUND(166.888) TRUNC(166.888)
-------------- --------------
           167            166

SQL> select round(166.888,-1),trunc(166.888,-1)
  2  from dual;

ROUND(166.888,-1) TRUNC(166.888,-1)
----------------- -----------------
              170               160

SQL> select mod(1900,400)
  2  from dual;

MOD(1900,400)
-------------
          300

SQL> select mod(200,400)
  2  from dual;

MOD(200,400)
------------
         200

SQL> alter session set NLS_DATE_LANGUAGE='AMERICAN';

Session altered

SQL> COMMIT;

Commit complete

SQL> select sysdate
  2  from dual;

SYSDATE
-----------
2009-8-24 1

SQL> select sysdate - 10
  2  from dual;

SYSDATE-10
-----------
2009-8-14 1

SQL> select sysdate + 10
  2  from dual;

SYSDATE+10
-----------
2009-9-3 14

SQL> select TO_DATE('2009-10-1')-sysdate
  2  from dual;

select TO_DATE('2009-10-1')-sysdate
from dual

ORA-01861: 文字与格式字符串不匹配

SQL> select TO_DATE('15-jul-2010')-sysdate
  2  from dual;

TO_DATE('15-JUL-2010')-SYSDATE
------------------------------
              324.378356481481

SQL> select sysdate - 1/24
  2  from dual;

SYSDATE-1/24
------------
2009-8-24 13

SQL> select sysdate - 24/24
  2  from dual;

SYSDATE-24/24
-------------
2009-8-23 14:

SQL> select empno,ename,job,sal,(sysdate-hiredate)/365 "years"
  2  from emp
  3  where job like'SAL%';

EMPNO ENAME      JOB             SAL      years
----- ---------- --------- --------- ----------
 7499 ALLEN      SALESMAN    1600.00 28.5277370
 7521 WARD       SALESMAN    1250.00 28.5222576
 7654 MARTIN     SALESMAN    1250.00 27.9249973
 7844 TURNER     SALESMAN    1500.00 27.9797918

SQL> select months_between('01-jul-99','03-feb-98')
  2  from dual;

MONTHS_BETWEEN('01-JUL-99','03
------------------------------
              16.9354838709677

SQL> select add_months('15-oct-01',8)
  2  from dual;

ADD_MONTHS('15-OCT-01',8)
-------------------------
2002-6-15

SQL> select add_months('15-oct-01',2)
  2  from dual;

ADD_MONTHS('15-OCT-01',2)
-------------------------
2001-12-15

SQL> select next_day(sysdate,'monday')
  2  from dual;

NEXT_DAY(SYSDATE,'MONDAY')
--------------------------
2009-8-31 15:01:14

SQL> select last-day(sysdate)
  2  from dual;

select last-day(sysdate)
from dual

ORA-00904: "DAY": 标识符无效

SQL> select last_day(sysdate)
  2  from dual;

LAST_DAY(SYSDATE)
-----------------
2009-8-31 15:02:2

SQL> select ename,hiredate,last_day(hiredate),next_day(hiredate,'sunday'),months_between(sysdate,hiredate)"months",add_months(hiredate , 3)"review"
  2  from emp;

ENAME      HIREDATE    LAST_DAY(HIREDATE) NEXT_DAY(HIREDATE,'SUNDAY')     months review
---------- ----------- ------------------ --------------------------- ---------- -----------
SMITH      1980-12-17  1980-12-31         1980-12-21                  344.246053 1981-3-17
ALLEN      1981-2-20   1981-2-28          1981-2-22                   342.149279 1981-5-20
WARD       1981-2-22   1981-2-28          1981-3-1                    342.084762 1981-5-22
JONES      1981-4-2    1981-4-30          1981-4-5                    340.729924 1981-7-2
MARTIN     1981-9-28   1981-9-30          1981-10-4                   334.891214 1981-12-28
BLAKE      1981-5-1    1981-5-31          1981-5-3                    339.762182 1981-8-1
CLARK      1981-6-9    1981-6-30          1981-6-14                   338.504117 1981-9-9
KING       1981-11-17  1981-11-30         1981-11-22                  333.246053 1982-2-17
TURNER     1981-9-8    1981-9-30          1981-9-13                   335.536375 1981-12-8
JAMES      1981-12-3   1981-12-31         1981-12-6                   332.697666 1982-3-3
FORD       1981-12-3   1981-12-31         1981-12-6                   332.697666 1982-3-3
MILLER     1982-1-23   1982-1-31          1982-1-24                   331.052504 1982-4-23

12 rows selected

SQL> select ename,hiredate,last_day(hiredate),next_day(hiredate,'星期日'),months_between(sysdate,hiredate)"months",add_months(hiredate , 3)"review"
  2  from emp;

select ename,hiredate,last_day(hiredate),next_day(hiredate,'星期日'),months_between(sysdate,hiredate)"months",add_months(hiredate , 3)"review"
from emp

ORA-01846: 周中的日无效

SQL> select round('28-oct-01','month')
  2  from dual;

select round('28-oct-01','month')
from dual

ORA-01722: 无效数字

SQL> select round(to_date('28-oct-01'),'month')
  2  from dua;

select round(to_date('28-oct-01'),'month')
from dua

ORA-00942: 表或视图不存在

SQL> select round(to_date('28-oct-01'),'month')
  2  from dual;

ROUND(TO_DATE('28-OCT-01'),'MO
------------------------------
2001-11-1

SQL> select round(to_date('28-oct-01'),'year')
  2  from dual;

ROUND(TO_DATE('28-OCT-01'),'YE
------------------------------
2002-1-1

SQL> select round(to_date('28-may-01'),'year')
  2  from dual;

ROUND(TO_DATE('28-MAY-01'),'YE
------------------------------
2001-1-1

SQL> select round(to_date('28-june-01'),'year')
  2  from dual;

ROUND(TO_DATE('28-JUNE-01'),'Y
------------------------------
2001-1-1

SQL> select round(to_date('28-step-01'),'year')
  2  from dual;

select round(to_date('28-step-01'),'year')
from dual

ORA-01843: 无效的月份

SQL> select round(to_date('28-july-01'),'year')
  2  from dual;

ROUND(TO_DATE('28-JULY-01'),'Y
------------------------------
2002-1-1

SQL> select trunc(to_date('28-step-01'),'year')
  2  from dual;

select trunc(to_date('28-step-01'),'year')
from dual

ORA-01843: 无效的月份

SQL> select round(to_date('28-july-01'),'year')
  2  select trunc(to_date('28-step-01'),'year')
  3  
SQL> select trunc(to_date('28-july-01'),'year')
  2  from dual;

TRUNC(TO_DATE('28-JULY-01'),'Y
------------------------------
2001-1-1

SQL> select trunc(to_date('28-feb-01'),'year')
  2  from dual;

TRUNC(TO_DATE('28-FEB-01'),'YE
------------------------------
2001-1-1

SQL> select trunc(to_date('28-oct-01'),'year')
  2  from dual;

TRUNC(TO_DATE('28-OCT-01'),'YE
------------------------------
2001-1-1

SQL> select ename,hiredate,round(hiredate,'year'),trunc(hiredate,'year'),round(hiredate,'month'),turnc(hiredate,'month')
  2  from emp
  3  where hiredate like"%81";

select ename,hiredate,round(hiredate,'year'),trunc(hiredate,'year'),round(hiredate,'month'),turnc(hiredate,'month')
from emp
where hiredate like"%81"

ORA-00904: "%81": 标识符无效

SQL> select ename,hiredate,round(hiredate,'year'),trunc(hiredate,'year'),round(hiredate,'month'),turnc(hiredate,'month')
  2  from emp
  3  where hiredate like'%81';

select ename,hiredate,round(hiredate,'year'),trunc(hiredate,'year'),round(hiredate,'month'),turnc(hiredate,'month')
from emp
where hiredate like'%81'

ORA-00904: "TURNC": 标识符无效

SQL> select ename,hiredate,round(hiredate,'year'),trunc(hiredate,'year'),round(hiredate,'month'),trunc(hiredate,'month')
  2  from emp
  3  where hiredate like'%81';

ENAME      HIREDATE    ROUND(HIREDATE,'YEAR') TRUNC(HIREDATE,'YEAR') ROUND(HIREDATE,'MONTH') TRUNC(HIREDATE,'MONTH')
---------- ----------- ---------------------- ---------------------- ----------------------- -----------------------
ALLEN      1981-2-20   1981-1-1               1981-1-1               1981-3-1                1981-2-1
WARD       1981-2-22   1981-1-1               1981-1-1               1981-3-1                1981-2-1
JONES      1981-4-2    1981-1-1               1981-1-1               1981-4-1                1981-4-1
MARTIN     1981-9-28   1982-1-1               1981-1-1               1981-10-1               1981-9-1
BLAKE      1981-5-1    1981-1-1               1981-1-1               1981-5-1                1981-5-1
CLARK      1981-6-9    1981-1-1               1981-1-1               1981-6-1                1981-6-1
KING       1981-11-17  1982-1-1               1981-1-1               1981-12-1               1981-11-1
TURNER     1981-9-8    1982-1-1               1981-1-1               1981-9-1                1981-9-1
JAMES      1981-12-3   1982-1-1               1981-1-1               1981-12-1               1981-12-1
FORD       1981-12-3   1982-1-1               1981-1-1               1981-12-1               1981-12-1

10 rows selected

SQL> select ename,to_char(hiredate,'dd/mm/yy')
  2  from emp
  3  where hiredate like'%82';

ENAME      TO_CHAR(HIREDATE,'DD/MM/YY')
---------- ----------------------------
MILLER     23/01/82

SQL> select ename,to_char(hiredate,'mm/dd/yy')
  2  form emp
  3  where hiredate like '%82';

select ename,to_char(hiredate,'mm/dd/yy')
form emp
where hiredate like '%82'

ORA-00923: 未找到要求的 FROM 关键字

SQL> select ename,to_char(hiredate,'mm/dd/yy')
  2  from emp
  3  where hiredate like '%82';

ENAME      TO_CHAR(HIREDATE,'MM/DD/YY')
---------- ----------------------------
MILLER     01/23/82

SQL>
SQL> select to_char(sysdate,'fmdd month year')
  2  from dual;

TO_CHAR(SYSDATE,'FMDDMONTHYEAR
-----------------------------------------------------------
24 august two thousand nine

SQL> select ename"name",sal"salary",
  2  to_char(hiredate,'fmDdspth "of" Month year fmHH:MI:SS AM') hiredate
  3  from emp;

name          salary HIREDATE
---------- --------- --------------------------------------------------------------------------------
SMITH         800.00 Seventeenth of December nineteen eighty 12:00:00 AM
ALLEN        1600.00 Twentieth of February nineteen eighty-one 12:00:00 AM
WARD         1250.00 Twenty-Second of February nineteen eighty-one 12:00:00 AM
JONES        2975.00 Second of April nineteen eighty-one 12:00:00 AM
MARTIN       1250.00 Twenty-Eighth of September nineteen eighty-one 12:00:00 AM
BLAKE        2850.00 First of May nineteen eighty-one 12:00:00 AM
CLARK        2450.00 Ninth of June nineteen eighty-one 12:00:00 AM
KING         5000.00 Seventeenth of November nineteen eighty-one 12:00:00 AM
TURNER       1500.00 Eighth of September nineteen eighty-one 12:00:00 AM
JAMES         950.00 Third of December nineteen eighty-one 12:00:00 AM
FORD         3000.00 Third of December nineteen eighty-one 12:00:00 AM
MILLER       1300.00 Twenty-Third of January nineteen eighty-two 12:00:00 AM

12 rows selected

SQL> select ename "Name",to_char(sal*12,'$99,999.00') "Annual Salary"
  2  from emp;

Name       Annual Salary
---------- -------------
SMITH        $9,600.00
ALLEN       $19,200.00
WARD        $15,000.00
JONES       $35,700.00
MARTIN      $15,000.00
BLAKE       $34,200.00
CLARK       $29,400.00
KING        $60,000.00
TURNER      $18,000.00
JAMES       $11,400.00
FORD        $36,000.00
MILLER      $15,600.00

12 rows selected

SQL> select ename "Name",to_char(sal*12,'L99,999.00') "Annual Salary"
  2  from emp;

Name       Annual Salary
---------- --------------------
SMITH                ¥9,600.00
ALLEN               ¥19,200.00
WARD                ¥15,000.00
JONES               ¥35,700.00
MARTIN              ¥15,000.00
BLAKE               ¥34,200.00
CLARK               ¥29,400.00
KING                ¥60,000.00
TURNER              ¥18,000.00
JAMES               ¥11,400.00
FORD                ¥36,000.00
MILLER              ¥15,600.00

12 rows selected

SQL> select ename "Name",to_char(sal*12,'L9,999.00') "Annual Salary"
  2  from emp;

Name       Annual Salary
---------- -------------------
SMITH               ¥9,600.00
ALLEN      ###################
WARD       ###################
JONES      ###################
MARTIN     ###################
BLAKE      ###################
CLARK      ###################
KING       ###################
TURNER     ###################
JAMES      ###################
FORD       ###################
MILLER     ###################

12 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between '01-feb-81' and '31-dec-81'
  4  order by hiredate;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------
ALLEN      SALESMAN    1600.00 1981-2-20
WARD       SALESMAN    1250.00 1981-2-22
JONES      MANAGER     2975.00 1981-4-2
BLAKE      MANAGER     2850.00 1981-5-1
CLARK      MANAGER     2450.00 1981-6-9
TURNER     SALESMAN    1500.00 1981-9-8
MARTIN     SALESMAN    1250.00 1981-9-28
KING       PRESIDENT   5000.00 1981-11-17
FORD       ANALYST     3000.00 1981-12-3
JAMES      CLERK        950.00 1981-12-3

10 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between '01-feb-81' and '31-dec-81'
  4  order by hiredate desc;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------
JAMES      CLERK        950.00 1981-12-3
FORD       ANALYST     3000.00 1981-12-3
KING       PRESIDENT   5000.00 1981-11-17
MARTIN     SALESMAN    1250.00 1981-9-28
TURNER     SALESMAN    1500.00 1981-9-8
CLARK      MANAGER     2450.00 1981-6-9
BLAKE      MANAGER     2850.00 1981-5-1
JONES      MANAGER     2975.00 1981-4-2
WARD       SALESMAN    1250.00 1981-2-22
ALLEN      SALESMAN    1600.00 1981-2-20

10 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between '01-feb-81' and '31-dec-81'
  4  order by hiredate desc;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------
JAMES      CLERK        950.00 1981-12-3
FORD       ANALYST     3000.00 1981-12-3
KING       PRESIDENT   5000.00 1981-11-17
MARTIN     SALESMAN    1250.00 1981-9-28
TURNER     SALESMAN    1500.00 1981-9-8
CLARK      MANAGER     2450.00 1981-6-9
BLAKE      MANAGER     2850.00 1981-5-1
JONES      MANAGER     2975.00 1981-4-2
WARD       SALESMAN    1250.00 1981-2-22
ALLEN      SALESMAN    1600.00 1981-2-20

10 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between '01-1月-81' and '31-12月-81'
  4  order by hiredate desc;

select ename "Name",job,sal as "Salary",hiredate
from emp
where hiredate between '01-1月-81' and '31-12月-81'
order by hiredate desc

ORA-01843: 无效的月份

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from em
  3  where hiredate between to_date('01-jan-81',dd-mm-yy) and to_date('31-dec-81','dd-mm-yy')
  4  order by hiredate;

select ename "Name",job,sal as "Salary",hiredate
from em
where hiredate between to_date('01-jan-81',dd-mm-yy) and to_date('31-dec-81','dd-mm-yy')
order by hiredate

ORA-00942: 表或视图不存在

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81',dd-mm-yy) and to_date('31-dec-81','dd-mm-yy')
  4  order by hiredate;

select ename "Name",job,sal as "Salary",hiredate
from emp
where hiredate between to_date('01-jan-81',dd-mm-yy) and to_date('31-dec-81','dd-mm-yy')
order by hiredate

ORA-00904: "YY": 标识符无效

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
  4  order by hiredate;
  5  
  6  where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
  7  
SQL>
SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
  4  order by hiredatel
  5  ;
  6  ;
  7  
  8  
  9  
 10  
 11  
 12  
 13  
 14  fda
 15  
 16  fda
 17  
 18  
 19  
 20  
 21  fa
 22  ;
 23  ;;
 24  
 25  
 26  
 27  select ename "Name",job,sal as "Salary",hiredate
 28  from emp
 29  where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
 30  order by hiredate;

select ename "Name",job,sal as "Salary",hiredate
from emp
where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
order by hiredatel
;
;







fda

fda




fa
;
;;



select ename "Name",job,sal as "Salary",hiredate
from emp
where hiredate between to_date('01-jan-81',dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
order by hiredate

ORA-00907: 缺失右括号

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81','dd-mm-yy') and to_date('31-dec-81','dd-mm-yy')
  4  order by hiredate;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------

SQL> select todate('01-jan-81','dd-mm-yy')
  2  from dual;

select todate('01-jan-81','dd-mm-yy')
from dual

ORA-00904: "TODATE": 标识符无效

SQL> select to_date('01-jan-81','dd-mm-yy')
  2  from dual;

TO_DATE('01-JAN-81','DD-MM-YY'
------------------------------
2081-1-1

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from dual;

select ename "Name",job,sal as "Salary",hiredate
from dual

ORA-00904: "HIREDATE": 标识符无效

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81','dd-mon-yy') and to_date('31-dec-81','dd-mon-yy')
  4  order by hiredate;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------

SQL> select hiredate from emp;

HIREDATE
-----------
1980-12-17
1981-2-20
1981-2-22
1981-4-2
1981-9-28
1981-5-1
1981-6-9
1981-11-17
1981-9-8
1981-12-3
1981-12-3
1982-1-23

12 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81') and to_date('31-dec-81')
  4  order by hiredate;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------
ALLEN      SALESMAN    1600.00 1981-2-20
WARD       SALESMAN    1250.00 1981-2-22
JONES      MANAGER     2975.00 1981-4-2
BLAKE      MANAGER     2850.00 1981-5-1
CLARK      MANAGER     2450.00 1981-6-9
TURNER     SALESMAN    1500.00 1981-9-8
MARTIN     SALESMAN    1250.00 1981-9-28
KING       PRESIDENT   5000.00 1981-11-17
FORD       ANALYST     3000.00 1981-12-3
JAMES      CLERK        950.00 1981-12-3

10 rows selected

SQL> select ename "Name",job,sal as "Salary",hiredate
  2  from emp
  3  where hiredate between to_date('01-jan-81','dd-mon-rr') and to_date('31-dec-81','dd-mon-rr')
  4  order by hiredate;

Name       JOB          Salary HIREDATE
---------- --------- --------- -----------
ALLEN      SALESMAN    1600.00 1981-2-20
WARD       SALESMAN    1250.00 1981-2-22
JONES      MANAGER     2975.00 1981-4-2
BLAKE      MANAGER     2850.00 1981-5-1
CLARK      MANAGER     2450.00 1981-6-9
TURNER     SALESMAN    1500.00 1981-9-8
MARTIN     SALESMAN    1250.00 1981-9-28
KING       PRESIDENT   5000.00 1981-11-17
FORD       ANALYST     3000.00 1981-12-3
JAMES      CLERK        950.00 1981-12-3

10 rows selected

SQL>

转载于:https://www.cnblogs.com/baoguo/articles/1553225.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/262377.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

黑马训练营自学笔记(03)

---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ---------------------- 对ViewState的一些认识 因为Http协议是一总无状态记忆的协议,即服务器不会知道上次可客户端请求的内容。WebForm中许多服务端控件的实现依靠的就是Vie…

scrapy知乎爬虫mysql存储项目_Scrapy爬虫框架第八讲【项目实战篇:知乎用户信息抓取】--本文参考静觅博主所写...

思路分析:(1)选定起始人(即选择关注数和粉丝数较多的人--大V)(2)获取该大V的个人信息(3)获取关注列表用户信息(4)获取粉丝列表用户信息(5)重复(2)(3)(4)步实现全知乎用户爬取实战演练:(1)、创建项目:scrapy startproject zhijutest(2)、创建爬…

pyplot输出的绘图界面中文乱码的解决方案

解决办法很简单,明确设置并使用特定的中文字体即可。具体来说,分两步: 第一步:生成指定的字体属性对象。此对象名在下例中为fp。 import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties #注意路…

kali下生成web端后门

很多时候在***测试时选择web***害怕用的别人的马带有后门,这样自己的辛苦就要被别人不劳而获,很多时候我们都想拥有自己的马,那么这个时候你就应该使用kail来生成一个自己独特密码的web***了。Kali Linux自带有好几个web***生成工具&#xff…

童儿的故事(二)

回来的路上, 又看到昨天那个望桔的童儿。 “怎么,你还在胡思乱想?”我问他。 “我想,至少我可以望一望它。”顺势他把苹果搂的更紧。 得不到的时候也许会让一个人懂得珍惜, 即便他不懂得满足。 他喃喃道:“…

sql2008能否打开mysql数据库_SQL Server 2008通过LinkServer访问MySQL数据库

(中国软件网讯)怎样让SQL Server 2008数据库可以访问MySQL数据库的数据呢?其实这一实现的过程并不难,可以通过调用MySQL的ODBC驱动,在SQL Server中添加LinkServer的方式实现。本文我们就介绍了这一访问过程,现在我们就开始介绍&am…

素性测试的Miller-Rabin算法完全解析 (C语言实现、Python实现)

因为文中存在公式&#xff0c;只能用图片方式上传了&#xff01; 以下为C语言源代码&#xff1a; #include <stdio.h> typedef long long unsigned LLU; typedef int BOOL; #define TRUE 1 #define FALSE 0 BOOL isPrime(LLU n) { //这是传统的方法&#xff0c;用于与…

MongoDB源码阅读之ReplSet源码分析

1. ReplSet源码结构 rs_config.h replSet间同步设置的工具类 rs_member.h 心跳检测类和replSet成员状态的定义 rs_sync.h 同步数据类 rs.h 定义了几乎所有replSet相关的类&#xff08;Member:replSet中的节点成员&#xff0c; GhostSync&#xff1a;备份同步类&#xff0c;Rep…

C# 字符串性能

Written By Dr Herbie [2] Translated By Allen Lee Introduction 你在代码中处理字符串的方法可能会对性能产生令人吃惊的影响。程序中需要考虑两个由于使用字符串而产生的问题&#xff1a;临时字符串变量的使用和字符串连接。Background1.String是引用类型&#xff0c;在堆上…

手把手教你部署VSAN见证虚拟设备 (Cormac)

译者注&#xff1a;本文翻译自Cormac的博客&#xff0c;并未严格地逐字逐句的直译&#xff0c;如有谬误&#xff0c;万望见谅。原文见此http://cormachogan.com/2015/09/14/step-by-step-deployment-of-the-vsan-witness-appliance/现在开始在之前的帖子中我曾经介绍过见证虚拟…

mysql在哪儿查看表的代码_查看mysql数据库及表编码格式

转载来源&#xff1a;http://www.cnblogs.com/shootercheng/p/5836657.html一、查看MySQL数据库服务器和数据库MySQL字符集。二、查看MySQL数据表(table)的MySQL字符集。三、查看MySQL数据列(column)的MySQL字符集。1.查看数据库编码格式2.查看数据表的编码格式3.创建数据库时指…

PyCharm编程环境的中英文字体分别设置的好处多----一石三鸟地解决中文字体不一致、英文字体不涵盖中文字符、编程字体实用性兼顾美观性的三个问题

在编程环境&#xff08;例如Python的PyCharm&#xff09;中&#xff0c;我们希望编程环境的字体具有如下特性&#xff1a; &#xff08;1&#xff09;字体覆盖中文和英文字符。 &#xff08;2&#xff09;等宽字体&#xff0c;并且是TrueType字体&#xff0c;方便辨识代码中缩…

WordPress博客系统的安全

随着计算机网络的流行&#xff0c;越来越多的人开始创建自己的博客&#xff0c;论起博客系统&#xff0c;全球用的最多的博客系统就是wordpress&#xff08;以下简称WP&#xff09;。但是如果用过WP的人都应该知道&#xff0c;WP的站点想要做的好看&#xff0c;插件是必不可少的…

C/C++ 程序设计员应聘常见面试试题深入剖析

1.引言 本文的写作目的并不在于提供C/C程序员求职面试指导&#xff0c;而旨在从技术上分析面试题的内涵。文中的大多数面试题来自各大论坛&#xff0c;部分试题解答也参考了网友的意见。许多面试题看似简单&#xff0c;却需要深厚的基本功才能给出完美的解答。企业要求面试者写…

mysql为什么行数据库_关系数据表中的行称为什么?

在一个二维表中&#xff0c;水平方向的行称为元组&#xff0c;每一行是一个元组&#xff1b;元组对应表中的一个具体记录。数据元组也称为记录。一个数据表中的每一个记录均有一个惟一的编号(记录号)。一个记录也就是数据表中的一行。元组(tuple)是关系数据库中的基本概念&…

长截图或长图片如何按页面切分后打印或插入到Word文档中

现在用手机可以非常方便地将手机的任意页面&#xff08;禁止截图的App页面除外&#xff09;用截长屏的方式一次性将常常的页面内容截图下来&#xff0c;这些长页面通常是通常是聊天记录或各种文章等。 截图下来后&#xff0c;在手机或电脑中查看倒是不会有什么问题。但是&…

maven安装以及eclipse配置maven

http://jingyan.baidu.com/article/295430f136e8e00c7e0050b9.html 必须先下载并安装JDK&#xff0c;配置JDK的环境变量JAVA_HOME&#xff0c;否则maven将无法使用 eclipse安装maven插件后必须重新定位maven到本地maven目录 如下定位&#xff1a; 为了使得Eclipse中安装的Maven…

产品2

闹钟\拉链\拼图转载于:https://www.cnblogs.com/sode/archive/2012/10/22/2733640.html

Oracle分页存储过程

create or replace package JT_P_page istype type_cur is ref cursor; --定义游标变量用于返回记录集procedure Pagination (Pindex in number, --要显示的页数索引&#xff0c;从0开始 Psql in varchar2, --产生分页…