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;
写法:
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;
本文详细介绍了PL/SQL中的几种基本元素的定义与使用方法,包括FUNCTION函数、PROCEDURE存储过程、TRIGGER触发器及SEQUENCE序列。通过具体实例展示了每种元素的功能及其应用场景。
149

被折叠的 条评论
为什么被折叠?



