1.字段索引
create index 索引名 on 表名(索引字段名) --创建索引
create unique index 索引名 on 表名(索引字段名) --创建唯一索引
drop index 索引名 on 表名 --删除索引
2.存储过程
create procedure 存储名(参数) is
begin
执行部分
end
3.函数(一般只返回一个值)
create function xxx(xxx) return number is yearSal number(7,2);
begin
select xxx into yearSal from xxx where xxx=xxx;
return yearSal;
end;
4.包
create or replace package body xxx is
xxxprocedure
xxxfunction
end;
5.要定义和数据库字段相同类型的参数
xxx表.xxx字段%type
6.复合类型-->记录实例
--定义一个pl/sql记录实例,内部有3个元素 declare type emp_record_type is record(name number(10),salary number(10,2),title varchar2(30)) --定义一个emp_record_type变量 sp_record emp_record_type; begin --把3个字段取出来放到记录类型中 select name,salary,title into sp_record from xxx where xxx --使用时,用"."就可以引用到了 dbms_output.put_line(emp_record_type.name)
7.复合类型-->表实例
--定义一个pl/sql表实例,下标是整数 declare type emp_table_type is table of xxx表.xxx字段%type index by binary_integer; --定义一个emp_table_type变量 sp_table emp_table_type; begin --把3个字段取出来放到记录类型中 select name into sp_table(0) from xxx where xxx --使用 dbms_output.put_line(sp_table(0))
8.触发器
create [or replace] trigger 触发器名 触发时间 触发事件 on 表名 [for each row] pl/sql 语句