oracle 函数结构示例
FUNCTION
写法:
CREATE OR REPLACE FUNCTION GET_TABLE()
return NUMBER/VARCHAR2 AS NAME VARCHAR2(20);
BEGIN
SELECT USER_NAME INTO NAME FROM student;
RETURN NAME;
END;
PROCEDURE
存储过程写法:
create or replace procedure PRO_Search
(
v_name in ss.student.stuName%type,
v_id in ss.student.stuId%type
)
as
q_name ss.student.stuName%type;
q_id ss.student.stuId%type;
begin
select stuName,stuId into q_name,q_id from ss.student where stuName = v_name and stuId = v_id;
end;
TRIGGER
触发器定法:
create or replace tirgger tri_AB
after update or insert on A for each row //"for each row"很重要。
begin
if updating or inserting then
insert into B values(:NEW.a);
end if;
end;
/
SEQUENCE
序列写法:
create sequence seq_num with start(初始值) 0 increment(步长) by 1 maxvalue 100 minvalue 0 cycle(到100后回到1开始);
用法:select seq1.nextval,studentid from student;