Oracle 051 (oracle 11g), 05111g

Source: Internet
Author: User

Oracle 051 (oracle 11g), 05111g

Oracle 051 questions (oracle 11g)

1. INTERVAL usage

Select interval '000000' MONTH, INTERVAL '54-2 'year to month, INTERVAL '11: 12: 300 'hour to second from dual;

The query result is:

INTERVAL '000000' MONTH
---------------------------------------------------------------------------
INTERVAL '54-2' YEARTOMONTH
---------------------------------------------------------------------------
INTERVAL '11: 12: 10.1234567 'HOURTOSECOND
---------------------------------------------------------------------------
+ 25-00
+ 54-02
+ 00 11:12:10. 123457

 

2. ORDERBY

Select distinct deptno, sal from emp order1;

Equivalent

Select distinct deptno, sal from emp orderDeptno;

 

Select distinct deptno, sal from emp order2;

Equivalent

Select distinct deptno, sal from emp orderSal;

 

  1. Use data merging in the SELECT clause

The emp table is as follows:

EMPNO

ENAME

JOB

MGR

HIREDATE

SAL

COMM

7369

SMITH

CLERK

7902

17-DEC-80

800

7499

ALLEN

SALESMAN

7698

20-FEB-81

1600

300

7521

WARD

SALESMAN

7698

22-FEB-81

1250

500

7566

JONES

MANAGER

7839

02-APR-81

2975

7654

MARTIN

SALESMAN

7698

28-SEP-81

1250

1400

7698

BLAKE

MANAGER

7839

01-MAY-81

2850

7782

CLARK

MANAGER

7839

09-JUN-81

2450

7788

SCOTT

ANALYST

7566

19-APR-87

3000

7839

KING

PRESIDENT

17-NOV-81

5000

The query statement is as follows:

Select empno | ''| TO_CHAR (ROUND (SYSDATE-hiredate)/365) * sal + comm) from emp;

The query result is:

EMPNO | ''| TO_CHAR (ROUND (SYSDATE-HIREDATE)/365) * SAL + COMM)
--------------------------------------------------------------------------------
7369
7499 56300
7521 44250
7566
7654 43900
7698
7782
7788
7839
7844 51000
7876
7900
7902
7934

The query result contains only one column, indicating the concatenation of the empno value and the following arithmetic value.

Note:

A) Use "|" in SELECT to merge data

B) the query result is incorrect. No calculation result is returned for rows with the COMM value being null.

 

  1. Q-quote delimiter

Query statement

Select Q' [I am 'OK "ey"]' from dual;

Output

I am 'OK "ey"

The following symbols are all feasible.

Select Q' <I am 'OK "ey">' from dual;

Select Q' \ I am 'OK "ey" \' from dual;

Select Q' {I am 'OK "ey"}' from dual;

Select Q' # I am 'OK "ey" #' from dual;

Select q '* I am' OK "ey" * 'from dual;

Select Q' (I am 'OK "ey")' from dual;

Select Q' % I am 'OK "ey" %' from dual;

 

  1. USING

Select * from emp join dept using (deptno );

The query result is:

DEPTNO EMPNO ENAME JOB MGR HIREDATE SAL COMM DNAME LOC
---------------------------------------------------------------------------------------------------------
10 7782 clark manager 7839 09-JUN-81 2450 ACCOUNTING NEW YORK
10 7839 king president 17-NOV-81 5000 ACCOUNTING NEW YORK
10 7934 miller clerk 7782 23-JAN-82 1300 ACCOUNTING NEW YORK
20 7566 jones manager 7839 02-APR-81 2975 RESEARCH DALLAS
20 7902 ford analyst 7566 03-DEC-81 3000 RESEARCH DALLAS
20 7876 adams clerk 7788 23-MAY-87 1100 RESEARCH DALLAS
20 7369 smith clerk 7902 17-DEC-80 800 RESEARCH DALLAS
20 7788 scott analyst 7566 19-APR-87 3000 RESEARCH DALLAS
30 7521 ward salesman 7698 22-FEB-81 1250 500 SALES CHICAGO
30 7844 turner salesman 7698 08-SEP-81 1500 0 SALES CHICAGO
30 7499 allen salesman 7698 20-FEB-81 1600 300 SALES CHICAGO
30 7900 james clerk 7698 03-DEC-81 950 SALES CHICAGO
30 7698 blake manager 7839 01-MAY-81 2850 SALES CHICAGO
30 7654 martin salesman 7698 28-SEP-81 1250 1400 SALES CHICAGO

Make oracle use the fields specified by using for join, instead of the default two in the natural join connection.

Reference http://blog.163.com/wkyuyang_001/blog/static/108021228200917598857/

 

Supplement:

  1. COUNT (*), COUNT (column_name), COUNT (DISTINCT)

COUNT (*)-all, include null

COUNT (column_name)-without null

COUNT (DISTINCT)-remove duplicate

 

  1. SQL statement execution sequence

A) FROM (query data sources)

B) WHERE (filter rows based on the conditions in WHERE)

C) group by (Execution GROUP)

D) HAVING (filtering in each group based on the conditions in HAVING)

E) SELECT (pick out the specified column)

F) order by (SORT)

Sugeei

March 28

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.