8.oracle table query

Demonstrates how to use the select statement, next to emp, dept, salgrade table structure commentary.

Employee emp table

    Whether the data type field name is null Remarks

    --------   -----------   --------   --------

    NUMBER the EMPNO ( 4 ) Number of employees                

    VARCHAR2 ENAME ( 10 ) the name of the Y-employees        

    VARCHAR2 JOB ( 9 ) the Y-Job                

    NUMBER MGR ( . 4 ) the higher the number of the Y            

    HIREDATE DATE Y entry date               

    NUMBER SAL ( 7 , 2 ) the Y-month salary            

    NUMBER COMM ( . 7 , 2 ) the Y bonus                

    NUMBER the DEPTNO ( 2 ) the Y-department

    -------------------------------------------

    job fields:

    Poor staff clerk

    salesman sales

    manager manager

    analyst Analyst

    president, president
department table dept

    Whether the data type field name is null Remarks

    --------    -----------      --------   --------

    NUMBER the DEPTNO ( 2 ) department number               

    VARCHAR2 DNAME ( 14 ) the Y-department name        

    (LOC VARCHAR2 13 ) the Y-sector location

    -------------------------------------------

    DNAME field:

    accounting Finance Department

    research R & D

    Business operations

      

    salgrade wage level table

    Whether the data type field name is null Remarks

    --------  ---------  --------  --------

    GRADE NUMBER Y level                

    LOSAL NUMBER Y Minimum Wage               

    HISAL NUMBER Y highest wages

 

1, see the table structure

 desc emp;

2, all queries column

 the SELECT  *  from the dept;
  - Note: Avoid quick to use select *, * use efficiency is relatively low, especially in large table to pay attention.

3, switch the display operation time, operation time displayed at the bottom.

set timing on/off;

eg:
sql> insert into tb_stu values('0001','zhangsan',24);
1 row inserted
executed in 0.015 seconds

 4, insert into ... select ... statements copy table

  语法:insert into table2(field1,field2,...) select value1,value2,... from table1

- Create tb_dept

create table tb_dept
    (
      deptno number(4) not null,
      dname  varchar2(14),
      loc    varchar2(13)
    )
    - Add primary key constraint 
    ALTER  Table tb_dept the Add  constraint tb_dept Primary  Key (DEPTNO);

  --insert into...select...用法 insert into tb_dept (deptno, dname, loc) select a.deptno, a.dname, a.loc from dept a;

 

5, statistical select count (*) from emp;

 

Guess you like

Origin www.cnblogs.com/Diyo/p/11654352.html