一、建立视图
CREATE OR REPLACE VIEW myview
AS
SELECT * FROM dept WHERE deptno>20
WITH CHECK OPTION;
二、建立只读视图
CREATE OR REPLACE VIEW myview
AS
SELECT * FROM dept WHERE deptno>20
WITH READ ONLY;
三、建立同义词
CREATE SYNONYM dept FOR scott.dept;
三、建立公共同义词
CREATE PUBLIC SYNONYM dept FOR scott.dept;
四、建立序列
CREATE SEQUENCE myseq
START WITH 3
INCREMENT BY 2
ORDER
MAXVALUE 8
MINVALUE 2
NOCYCLE;
四、查询序列值
select myseq.currval,myseq.nextval from dual;
五、修改序列
ALTER SEQUENCE myseq MAXVALUE 12;
不能修改currval
六、事务体现
A用户:
SELECT * FROM dept FOR UPDATE;
此时B用户作更新操作时会处于一直等待A完成状态:
UPDATE dept SET deptname="fsda" WHERE deptno='001';
七、行级触发器
1、:old表
CREATE OR REPLACE TRIGGER del_deptid
AFTER DELETE ON dept
FOR EACH ROW
BEGIN
DELETE FROM emp WHERE id=:old.id;
END del_deptid;
2、:new表
CREATE OR REPLACE TRIGGER insert_dept
AFTER INSERT ON dept
FOR EACH ROW
BEGIN
INSERT INTO emp(eid,ename,id) VALUES('121','QWERT',:new.id);
END;
3、触发器内不允许再写commit和rollback语句的替代方法
CREATE OR REPLACE TRIGGER books_delete
AFTER DELETE ON books
FOR EACH ROW
BEGIN
IF :old.books_id='0001' THEN
RAISE_APPLICATION_ERROR(-20000,'不允许删除!');
END IF;
END;
八、语句级触发器
CREATE TABLE mylog(curr_user VARCHAR2(100),curr_date date,act CHAR(1));
CREATE OR REPLACE TRIGGER dml_aa
AFTER INSERT OR DELETE OR UPDATE
BEGIN
IF INSERTING THEN
INSERT INTO mylog VALUES(user,sysdate,'I');
ELSEIF DELETING THEN
INSERT INTO mylog VALUES(user,sysdate,'D');
ELSE
INSERT INTO mylog VALUES(user,sysdate,'U');
END IF;
END;
九、替换触发器(Oracle中只能建在视图上)
CREATE OR REPLACE TRIGGER tr_v_e_d
INSTEAD OF INSERT ON v_emp_dept
FOR EACH ROW
BEGIN
INSERT INTO deptment VALUES(:new.id,:new.name);
INSERT INTO emp(eid,ename,sex,id) VALUES(:new.eid,:new.ename,:new.sex,:new.id);
END;
十、授权
grant execute on tt.proc01 to test;
grant all on scott.dept to test with grant option;
grant creat user to test with admin option;
八、角色
CREATE ROLE myrole;
GRANT SELECT on scott.dept TO myrole;
GRANT myrole TO jerry;
九、表空间
CREATE TABLESPACE tabs DATAFILE 'c:/oracle/product/10.1.0/oradata/test/tabs.dbf' SIZE 10M
GRANT UNLIMITED TABLESPACE,DBA TO test;
CREATE TABLE ty(t CHAR(10)) TABLESPACE tabs;