【run;r;/的用法】
SQL> SELECT * FROM dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> run
1* SELECT * FROM dept
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> r
1* SELECT * FROM dept
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> /
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
【修改Oracle日期的默认格式】
SQL> alter session set NLS_date_format='YYYY-MM-DD';
【绑定变量查询】
SQL> SELECT * FROM dept t WHERE t.deptno = &dept_no;
输入 dept_no 的值: 40
原值 1: SELECT * FROM dept t WHERE t.deptno = &dept_no
新值 1: SELECT * FROM dept t WHERE t.deptno = 40
DEPTNO DNAME LOC
---------- -------------- -------------
40 OPERATIONS BOSTON
【绑定变量插入】
SQL> INSERT INTO dept(deptno,dname,loc) VALUES (&dept_no,'&dept_name','&loc_name');
输入 dept_no 的值: 90
输入 dept_name 的值: work
输入 loc_name 的值: hangzhou
原值 1: INSERT INTO dept(deptno,dname,loc) VALUES (&dept_no,'&dept_name','&loc_name')
新值 1: INSERT INTO dept(deptno,dname,loc) VALUES (90,'work','hangzhou')
已创建 1 行。
【绑定变量修改】
SQL> UPDATE dept t SET t.dname = '&d_name' WHERE t.deptno = 90;
输入 d_name 的值: job
原值 1: UPDATE dept t SET t.dname = '&d_name' WHERE t.deptno = 90
新值 1: UPDATE dept t SET t.dname = 'job' WHERE t.deptno = 90
已更新 1 行。
【绑定变量删除】
SQL> DELETE FROM dept t WHERE t.deptno = &dept_no;
输入 dept_no 的值: 90
原值 1: DELETE FROM dept t WHERE t.deptno = &dept_no
新值 1: DELETE FROM dept t WHERE t.deptno = 90
已删除 1 行。
【利用子查询创建表】
SQL> CREATE TABLE my_dept AS SELECT * FROM dept;
表已创建。
【利用子查询插入数据】
SQL> INSERT INTO my_dept SELECT * FROM dept;
已创建4行。
【事务】
多个DML语句
单个DCL语句
单个DDL语句
【事务保存点】
SQL> SAVEPOINT p;
保存点已创建。
SQL> INSERT INTO my_dept VALUES (&dept_no,'&d_name','&loc_name');
输入 dept_no 的值: 70
输入 d_name 的值: work
输入 loc_name 的值: hangzhou
原值 1: INSERT INTO my_dept VALUES (&dept_no,'&d_name','&loc_name')
新值 1: INSERT INTO my_dept VALUES (70,'work','hangzhou')
已创建 1 行。
SQL> SELECT * FROM my_dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
70 work hangzhou
SQL> SAVEPOINT s;
保存点已创建。
SQL> ROLLBACK TO SAVEPOINT p;
回退已完成。
SQL> SELECT * FROM my_dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
【别名】
SQL> SELECT deptno "部门编号", dname AS "部门名称", loc location FROM dept;
部门编号 部门名称 LOCATION
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
【“||”连接符】
SQL> SELECT deptno || ' -- ' || dname || ' -- ' || loc AS list FROM dept;
LIST
---------------------------------------------------------------------------
10 -- ACCOUNTING -- NEW YORK
20 -- RESEARCH -- DALLAS
30 -- SALES -- CHICAGO
40 -- OPERATIONS -- BOSTON
【“<>” 不等于】
SQL> SELECT * FROM dept WHERE deptno <> 20;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
30 SALES CHICAGO
40 OPERATIONS BOSTON
【NULL 是否为空】
SQL> SELECT * FROM emp WHERE mgr IS NULL ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
7839 KING PRESIDENT 17-11月-81 5000 10
【函数】
LOWER
UPPER
INITCAP
CONCAT
SUBSTR
LENGTH
INSTR
LPAD
ROUND
TRUNC
MOD
MONTHS_BETWEEN
ADD_MONTHS
NEXT_DAY
LAST_DAY
NVL
DECODE
... ...
SQL> SELECT ename , CONCAT(empno,job) ejob, LENGTH(ename) len, INSTR(ename,'A') ins , LOWER(job) ljob, LPAD(job,10,'*') pjob, SUBSTR(ename,1,3) str FROM emp ;
ENAME EJOB LEN INS LJOB PJOB STR
---------- ------------------------------------------------- ---------- ---------- --------- -------------------- ------
SMITH 7369CLERK 5 0 clerk *****CLERK SMI
ALLEN 7499SALESMAN 5 1 salesman **SALESMAN ALL
WARD 7521SALESMAN 4 2 salesman **SALESMAN WAR
JONES 7566MANAGER 5 0 manager ***MANAGER JON
MARTIN 7654SALESMAN 6 2 salesman **SALESMAN MAR
BLAKE 7698MANAGER 5 3 manager ***MANAGER BLA
CLARK 7782MANAGER 5 3 manager ***MANAGER CLA
SCOTT 7788ANALYST 5 0 analyst ***ANALYST SCO
KING 7839PRESIDENT 4 0 president *PRESIDENT KIN
TURNER 7844SALESMAN 6 0 salesman **SALESMAN TUR
ADAMS 7876CLERK 5 1 clerk *****CLERK ADA
JAMES 7900CLERK 5 2 clerk *****CLERK JAM
FORD 7902ANALYST 4 0 analyst ***ANALYST FOR
MILLER 7934CLERK 6 0 clerk *****CLERK MIL
已选择14行。
SQL> SELECT ROUND(45.923,2) a, ROUND(45.923,0) b, ROUND(45.923,-1) c FROM DUAL;
A B C
---------- ---------- ----------
45.92 46 50
SQL> SELECT TRUNC(45.923,2) a, TRUNC(45.923,0) b, TRUNC(45.923,-1) c FROM DUAL;
A B C
---------- ---------- ----------
45.92 45 40
【sqlplus命令】
SQL> save 'd:\a.txt';
已创建文件 d:\a.txt
SQL> get 'd:\a.txt';
1* SELECT TRUNC(45.923,2) a, TRUNC(45.923,0) b, TRUNC(45.923,-1) c FROM DUAL
SQL> /
A B C
---------- ---------- ----------
45.92 45 40
SQL> @ 'd:\a.txt';
A B C
---------- ---------- ----------
45.92 45 40
【连接】
SQL> conn scott/tiger@ORCL
已连接。
【访问其他用户的表】
SQL> conn sys/sys as sysdba;
已连接。
SQL> select * from emp;
select * from emp
*
ERROR 位于第 1 行:
ORA-00942: 表或视图不存在
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7788 SCOTT ANALYST 7566 19-4月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7876 ADAMS CLERK 7788 23-5月 -87 1100 20
7900 JAMES CLERK 7698 03-12月-81 950 30
7902 FORD ANALYST 7566 03-12月-81 3000 20
7934 MILLER CLERK 7782 23-1月 -82 1300 10
已选择14行。
【修改"SQL>"的名字】
SQL> set sqlprompt tom
tomselect * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
【授权】
SQL> grant select,update,insert,delete on dept to sys;
授权成功。
【撤销授权】
SQL> revoke select,update,insert,delete on dept from sys;
撤销成功。
【创建用户】
SQL> conn sys/sys as sysdba
已连接。
SQL> create user yangyz identified by yangyz ;
用户已创建
【for update wait语句】
SQL> select * from my_dept for update of deptno;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> select * from my_dept for update wait 80;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
【锁定表-共享锁】
SQL> LOCK TABLE my_dept IN SHARE MODE ;
表已锁定。
SQL> LOCK TABLE my_dept IN SHARE UPDATE MODE;
表已锁定。
SQL> LOCK TABLE my_dept IN EXCLUSIVE MODE;
表已锁定。
SQL> LOCK TABLE my_dept IN EXCLUSIVE MODE NOWAIT ;
【数据类型】
VARCHAR
VARCHAR2
CHAR
NUMBER
DATE
LONG
CLOB
RAW
LONG RAW
BLOB
BFILE
【修改表结构】
SQL> ALTER TABLE my_dept ADD(worker varchar2(20)) ;
表已更改。
SQL> desc my_dept;
名称 是否为空? 类型
----------------------------------------- -------- ---------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
WORKER VARCHAR2(20)
SQL> ALTER TABLE my_dept MODIFY(worker varchar2(10)) ;
表已更改。
SQL> desc my_dept;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
WORKER VARCHAR2(10)
SQL> ALTER TABLE my_dept DROP COLUMN worker;
表已更改。
SQL> desc my_dept;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
SQL> ALTER TABLE my_dept SET UNUSED COLUMN deptno;
表已更改。
SQL> desc my_dept;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
WORKER VARCHAR2(10)
SQL> ALTER TABLE my_dept DROP UNUSED COLUMNS;
表已更改。
SQL> create table student(stuid number,stuname varchar2(30),stuage number,score number(5,2));
表已创建。
SQL> ALTER TABLE student ADD CONSTRAINT pk_stu PRIMARY KEY (stuid);
表已更改。
SQL> ALTER TABLE student DROP CONSTRAINT pk_stu;
表已更改。
【查看约束表】
SQL> DESC USER_CONSTRAINTS;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
CONSTRAINT_NAME NOT NULL VARCHAR2(30)
CONSTRAINT_TYPE VARCHAR2(1)
TABLE_NAME NOT NULL VARCHAR2(30)
SEARCH_CONDITION LONG
R_OWNER VARCHAR2(30)
R_CONSTRAINT_NAME VARCHAR2(30)
DELETE_RULE VARCHAR2(9)
STATUS VARCHAR2(8)
DEFERRABLE VARCHAR2(14)
DEFERRED VARCHAR2(9)
VALIDATED VARCHAR2(13)
GENERATED VARCHAR2(14)
BAD VARCHAR2(3)
RELY VARCHAR2(4)
LAST_CHANGE DATE
INDEX_OWNER VARCHAR2(30)
INDEX_NAME VARCHAR2(30)
INVALID VARCHAR2(7)
VIEW_RELATED VARCHAR2(14)
【表分区】
范围分区法
散列分区法 Hash分区
复合分区法
列表分区法
SQL> CREATE TABLE student(id number not null,name varchar2(20),score number(5,2)) PARTITION BY RANGE(score)(PARTITION p1 VALUES LESS THAN (60),PARTITION p2 VALUES LESS THAN (70),PARTITION p3 VALUES LESS THAN (80),PARTITION p4 VALUES LESS THAN (MAXVALUE));
表已创建。
SQL> CREATE TABLE teacher(id number not null,name varchar2(20),salary number(10,2)) PARTITION BY HASH(id) (PARTITION p1,PARTITION p2,PARTITION p3,PARTITION p4) ;
表已创建。
SQL> CREATE TABLE my_saldegree
(pid number,grade number,losal number,hisal number)
PARTITION BY RANGE(grade)
SUBPARTITION BY HASH(losal,hisal)(
PARTITION p1 VALUES LESS THAN(10) (SUBPARTITION sp1,SUBPARTITION sp2),
PARTITION p2 VALUES LESS THAN(20) (SUBPARTITION sp3,SUBPARTITION sp4)
);
表已创建。
SQL> CREATE TABLE customer (cusid number, name varchar2(20), state varchar2(20)) PARTITION BY LIST(state) (PARTITION asia VALUES('china','jpan','india'), PARTITION europe VALUES('england','franch'));
表已创建。
【查询分区】
SQL> SELECT * FROM user_tab_partitions ;
SQL> SELECT * FROM user_tab_partitions WHERE table_name = 'STUDENT';
SQL> SELECT * FROM user_tab_partitions WHERE LOWER(table_name) = 'student';
TABLE_NAME COM PARTITION_NAME SUBPARTITION_COUNT HIGH_VALUE
------------------------------ --- ------------------------------ ------------------ -----------------------
STUDENT NO P1 0 60
STUDENT NO P2 0 70
STUDENT NO P3 0 80
STUDENT NO P4 0 MAXVALUE
【修改表分区】
SQL> ALTER TABLE student DROP PARTITION p4;
表已更改。
SQL> ALTER TABLE student ADD PARTITION p5 VALUES LESS THAN (90);
表已更改。
SQL> ALTER TABLE student TRUNCATE PARTITION p5;
表已截掉。
SQL> ALTER TABLE student MERGE PARTITIONS p2,p3 INTO PARTITION p6;
表已更改。
SQL> SELECT * FROM user_tab_partitions WHERE table_name = UPPER('student');
TABLE_NAME COM PARTITION_NAME SUBPARTITION_COUNT HIGH_VALUE
------------------------------ --- ------------------------------ ------------------ ---------------------------
STUDENT NO P1 0 60
STUDENT NO P6 0 80
STUDENT NO P5 0 90
【按分区查询】
SQL> SELECT * FROM student PARTITION(p1);
SQL> desc user_tab_partitions;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
TABLE_NAME VARCHAR2(30)
COMPOSITE VARCHAR2(3)
PARTITION_NAME VARCHAR2(30)
SUBPARTITION_COUNT NUMBER
HIGH_VALUE LONG
HIGH_VALUE_LENGTH NUMBER
PARTITION_POSITION NUMBER
TABLESPACE_NAME VARCHAR2(30)
PCT_FREE NUMBER
PCT_USED NUMBER
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENT NUMBER
MAX_EXTENT NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
LOGGING VARCHAR2(7)
COMPRESSION VARCHAR2(8)
NUM_ROWS NUMBER
BLOCKS NUMBER
EMPTY_BLOCKS NUMBER
AVG_SPACE NUMBER
CHAIN_CNT NUMBER
AVG_ROW_LEN NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
BUFFER_POOL VARCHAR2(7)
GLOBAL_STATS VARCHAR2(3)
USER_STATS VARCHAR2(3)
SQL> desc user_ind_partitions;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
INDEX_NAME VARCHAR2(30)
COMPOSITE VARCHAR2(3)
PARTITION_NAME VARCHAR2(30)
SUBPARTITION_COUNT NUMBER
HIGH_VALUE LONG
HIGH_VALUE_LENGTH NUMBER
PARTITION_POSITION NUMBER
STATUS VARCHAR2(8)
TABLESPACE_NAME VARCHAR2(30)
PCT_FREE NUMBER
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENT NUMBER
MAX_EXTENT NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
LOGGING VARCHAR2(7)
COMPRESSION VARCHAR2(8)
BLEVEL NUMBER
LEAF_BLOCKS NUMBER
DISTINCT_KEYS NUMBER
AVG_LEAF_BLOCKS_PER_KEY NUMBER
AVG_DATA_BLOCKS_PER_KEY NUMBER
CLUSTERING_FACTOR NUMBER
NUM_ROWS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
BUFFER_POOL VARCHAR2(7)
USER_STATS VARCHAR2(3)
PCT_DIRECT_ACCESS NUMBER
GLOBAL_STATS VARCHAR2(3)
DOMIDX_OPSTATUS VARCHAR2(6)
PARAMETERS VARCHAR2(1000)
【重复插入】
SQL> INSERT INTO student SELECT * FROM student;
已创建2行。
SQL> INSERT INTO student SELECT * FROM student;
已创建4行。
【同义词】
SQL> CREATE SYNONYM stu FOR student;
同义词已创建。
SQL> CREATE PUBLIC SYNONYM st FOR scott.student;
同义词已创建。
SQL> DROP SYNONYM stu;
同义词已丢弃。
SQL> DESC user_synonyms;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
SYNONYM_NAME NOT NULL VARCHAR2(30)
TABLE_OWNER VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
DB_LINK VARCHAR2(128)
【序列】
SQL> CREATE SEQUENCE seq_1 INCREMENT BY 1 START WITH 1 MAXVALUE 9999 NOMINVALUE CYCLE ;
序列已创建。
SQL> CREATE SEQUENCE seq_2 INCREMENT BY 1 START WITH 1 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE;
序列已创建。
SQL> CREATE SEQUENCE seq_5 INCREMENT BY -1 START WITH 10 MAXVALUE 20 MINVALUE 0 NOCYCLE NOCACHE;
序列已创建。
SQL> SELECT seq_1.nextval FROM DUAL;
NEXTVAL
----------
1
SQL> SELECT seq_1.currval FROM DUAL;
CURRVAL
----------
1
SQL> ALTER SEQUENCE seq_1 MAXVALUE 99;
序列已更改。
SQL> DROP SEQUENCE seq_5;
序列已丢弃。
SQL> desc user_sequences;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
SEQUENCE_NAME NOT NULL VARCHAR2(30)
MIN_VALUE NUMBER
MAX_VALUE NUMBER
INCREMENT_BY NOT NULL NUMBER
CYCLE_FLAG VARCHAR2(1)
ORDER_FLAG VARCHAR2(1)
CACHE_SIZE NOT NULL NUMBER
LAST_NUMBER NOT NULL NUMBER
【视图】
SQL> CREATE VIEW job AS SELECT empno, ename,job,mgr,hiredate,sal,comm,e.deptno,dname,loc FROM emp e, dept d WHERE e.deptno = d.deptno;
视图已建立。
SQL> CREATE OR REPLACE VIEW job AS SELECT empno, ename,job,mgr,hiredate,sal,comm,e.deptno,dname,loc FROM emp e, dept d WHERE e.deptno = d.deptno;
视图已建立。
SQL> CREATE OR REPLACE VIEW job AS SELECT empno, ename,job,mgr,hiredate,sal,comm,e.deptno,dname,loc FROM emp e, dept d WHERE e.deptno = d.deptno ORDER BY d.deptno;
视图已建立。
SQL> CREATE OR REPLACE FORCE VIEW v_none AS SELECT * FROM no_table;
警告: 创建的视图带有编译错误。
SQL> DROP VIEW v_none;
视图已丢掉。
SQL> CREATE OR REPLACE VIEW v_emp AS SELECT * FROM emp t WHERE t.deptno = 10 UNION ALL SELECT * FROM emp e WHERE e.deptno = 20 ;
视图已建立。
SQL> ALTER VIEW v_emp COMPILE ;
视图已变更。
SQL> DESC user_views;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
VIEW_NAME NOT NULL VARCHAR2(30)
TEXT_LENGTH NUMBER
TEXT LONG
TYPE_TEXT_LENGTH NUMBER
TYPE_TEXT VARCHAR2(4000)
OID_TEXT_LENGTH NUMBER
OID_TEXT VARCHAR2(4000)
VIEW_TYPE_OWNER VARCHAR2(30)
VIEW_TYPE VARCHAR2(30)
SUPERVIEW_NAME VARCHAR2(30)
【rownum,rowid】
SQL> select rownum,rowid from dual;
ROWNUM ROWID
---------- ------------------
1 AAAADeAABAAAAZSAAA
SQL> SELECT t.* ,rowid FROM emp t WHERE rowid = 'AAAHW7AABAAAMUiAAA';
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ROWID
---------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ------------------
7369 SMITH CLERK 7902 17-12月-80 800 20 AAAHW7AABAAAMUiAAA
SQL> select * from emp where rownum <= 3;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
SQL> select * from emp where rownum = 3;
未选定行
【索引】
唯一索引
组合索引
反向键索引
位图索引
键压缩索引
分区索引
SQL> CREATE UNIQUE INDEX idx_stuid ON student(id);
索引已创建。
SQL> CREATE INDEX idx_empno_deptno ON emp(empno,deptno);
索引已创建。
SQL> DROP INDEX idx_stuid;
索引已丢弃。
SQL> CREATE BITMAP INDEX idx_job ON my_emp(job);
索引已创建。
SQL> CREATE TABLE indexorg (id number primary key, name varchar2(20)) ORGANIZATION INDEX ;
表已创建。
SQL> CREATE INDEX idx_ename ON scott.my_emp(LOWER(ename));
索引已创建。
SQL> CREATE INDEX idx_job_ename ON employee(job,ename) COMPRESS 1 ;
索引已创建。
【簇】
SQL> CREATE CLUSTER class_clsuter(classno varchar2(10)) TABLESPACE users;
已创建数据簇。
SQL> CREATE INDEX idx_class_cluster ON cluster class_clsuter;
索引已创建。
SQL> CREATE TABLE stuclass(classno varchar2(10), classname varchar2(20)) CLUSTER class_clsuter(classno);
表已创建。
SQL> CREATE TABLE classstu(stuno varchar2(10), stuname varchar2(20),classno varchar2(10)) CLUSTER class_clsuter(classno) ;
表已创建。
SQL> DROP CLUSTER class_clsuter INCLUDING TABLES ;
数据簇已丢弃。
SQL> desc user_clusters;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
CLUSTER_NAME NOT NULL VARCHAR2(30)
TABLESPACE_NAME NOT NULL VARCHAR2(30)
PCT_FREE NUMBER
PCT_USED NUMBER
KEY_SIZE NUMBER
INI_TRANS NOT NULL NUMBER
MAX_TRANS NOT NULL NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NOT NULL NUMBER
MAX_EXTENTS NOT NULL NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
AVG_BLOCKS_PER_KEY NUMBER
CLUSTER_TYPE VARCHAR2(5)
FUNCTION VARCHAR2(15)
HASHKEYS NUMBER
DEGREE VARCHAR2(10)
INSTANCES VARCHAR2(10)
CACHE VARCHAR2(5)
BUFFER_POOL VARCHAR2(7)
SINGLE_TABLE VARCHAR2(5)
DEPENDENCIES VARCHAR2(8)
【ORDBMS和RDBMS】
面向过程和面向对象
【抽象数据类型】
SQL> CREATE OR REPLACE TYPE addresss_type AS OBJECT (province varchar2(20), city varchar2(20), details varchar2(40))
2 /
类型已创建。
SQL> CREATE OR REPLACE TYPE provider AS OBJECT (proname varchar2(20), address addresss_type)
2 /
类型已创建。
SQL> CREATE TABLE providers (proid number, prodetail provider);
表已创建。
SQL> CREATE TABLE provider_tab OF provider ;
表已创建。
SQL> INSERT INTO providers VALUES (101,provider('XX公司',addresss_type('浙江','杭州','滨江滨康路1号')));
已创建 1 行。
SQL> CREATE OR REPLACE TYPE person AS OBJECT (pid number, pname varchar2(20)) NOT FINAL ;
2 /
类型已创建。
SQL> CREATE OR REPLACE TYPE worker UNDER person (salary number(10,2));
2 /
类型已创建。
SQL> INSERT INTO workers SELECT worker(1001,'zhangsan',5000) FROM dual;
已创建 1 行。
SQL> CREATE OR REPLACE TYPE programer AS OBJECT(pid number, pname varchar2(20), address addresss_type, MEMBER FUNCTION getaddress RETURN addresss_type, MEMBER PROCEDURE setaddress(newaddress addresss_type));
2 /
类型已创建。
SQL> CREATE OR REPLACE TYPE BODY programer AS
MEMBER FUNCTION getaddress RETURN addresss_type IS
BEGIN
RETURN address;
END;
MEMBER PROCEDURE setaddress(newaddress addresss_type) IS
BEGIN
address := new