PL/SQL_1

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 語句

  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章