游标(CURSOR):
(1) DECLARE CURSOUR C IS
SELECT * FROM EMP;
V_EMP C%ROWTYPE;
BEGIN
OPEN C;
FETCH C INTO V_EMP; --
DBMS_OUTPUT.PUTLINE(V_EMP.ENAME);
CLOSE C;
END;
(2) DECLARE
CURSOR C IS
SELECT * FROM EMP;
V_EMP C%ROWTYPE;
BEGIN
OPEN C;
LOOP
FETCH C INTO V_EMP;
DBMS_OUTPUT.PUTLINE(V_EMP.EMPNAME);
EXIT WHEN (C%NOTFOUND);
END LOOP;
CLOSE C;
END;
Procedure/存储过程。EXEC PROCEDURE ;(2)BGEIN P;END; 将declare替换成create or replace Procedure d
CREATE OR REPLACE FUNCTION SAL_TAX --创建函数,用在函数用来改用的地方
<V_SAL NUMBER>
RETURN NUMBER
IS
BEGIN
IF (V_SAL < 2000) THEN RETURN 0.10;
ELSIF (V_SAL < 2750) THEN RETURN 0.15;
ELSE RETURN 0.20;
END IF;
END;
触发器:
CREATE TABEL EMP2_LOG
(
UNAME VARCHAR2(20),
ACTION VARCHAR2(10),
ATIME DATE
);
CREATE OR REPLACE TRIGGER TRIG
AFTER INSERT OR DELETE OR UPDATE ON EMP2 FOR EACH ROW --每更新一行就操作
BEGIN
IF INSERTING THEN
INSERT INTO EMP2_LOG VALUES (USER,'INSERT',SYSDATE);
ELSIF UPDATING THEN
INSERT INTO EMP2_LOG VALUES (USER,'UPDATE',SYSDATE);
ELSIF DELETING THEN
INSERT INTO EMP2_LOG VALUES (USER,'DELETE',SYSDATE);
END IF;
END;
触发器实际 应用,修改一个关联的值时对相应影响的栏位也进行修改:
CREATE OR REPLACE TRIGGER TRIG
AFTER UPDATE ON DEPT
FOR EACH ROW
BEGIN
UPDATE EMP SET DEPNO = :NEW.DEPTNO WHERE DEPNO = :OLD.DEPNO;
END;/
将参考 了该值得所有记录都改变了。
--树状结构存储
CREATE TABLE ARTICLE
(
ID NUMBER PRIMARY KEY,
CONT VARCHAR2(4000),
PID NUMBER,
ISLEAF NUMBER(1), --0代表非叶子节点,1代表叶子节点
aleavel number(2)
);
--show erro 显示错误