儲存過程定義資訊檢視
column text format a30;
column name format a20;
select * from user_source where name ='select_emp';
修改
修改和建立一樣就是加上or replace;
刪除儲存過程:
drop procedure '過程名';
建立過程:
create or replace procedure update_emp is
begin
update emp set ename = 'hhdhjf' where empno = 7934;
end update_emp;
呼叫過程:
call update_emp ();
execute update_emp;
建立過程(實現兩個數交換)
create or replace procedure exchange_value(value1 in out number,
value2 in out number) as
temp1 number;
temp2 number;
begin
temp1 := value1;
temp2 := value2;
value1 := temp2;
value2 := temp1;
end exchange_value;
呼叫該過程
variable val1 number;
variable val2 number;
exec :val1 := 2009;
exec :val2 := 9002;
exec exchange_value(:val1, :val2);
輸出值:
select :value1, :value2 from dual;
select :val1, :val2 from dual;
儲存過程使用預設值
set serverout on;
create or replace procedure creat_value(value1 varchar2 default '123456',
value2 varchar2 default '789') as
begin
dbms_output.put_line('value1:' || value1 || ' ' || 'value2:' || value2);
end creat_value;
呼叫過程
begin
creat_value();
creat_value('kkkkk');
creat_value('sssss', 'eeeeee');
end;
帶引數out
create or replace procedure select_emp(emp_num in number,
emp_name out varchar2) as
begin
select ename into emp_name from emp where empno = emp_num;
end select_emp;
variable v_name varchar2(10);
call select_emp(7934,:v_name);
或execute select_emp(7934,:v_name);
輸出print v_name;
帶引數in out
v_name in out departments.department_name%type,
v_address in out departments.address%type) as
begin
insert into departments values(v_id, v_name, v_address);
v_id := v_id - 1;
select department_id, department_name, address
into v_id, v_name, v_address
from departments
where department_id = v_id;
exception
when dup_val_on_index then
dbms_output.put_line('插入系部資訊時,系部號不能重複。');
when no_data_found then
dbms_output.put_line('查詢系部資訊時,該系不存在');
呼叫過程:
variable v_id number;
variable v_name varchar2(8);
variable v_address varchar2(40);
execute :v_name :='地理物理';
execute :v_address := 'x號教學樓';
execute :v_id :='111';
輸出引數:
print v_id ;
print v_name;
print v_address;
帶引數儲存過程in
create or replace procedure update_emp2(emp_num in number,
emp_name in varchar2) as
begin
update emp set ename = emp_name where empno = emp_num;
end update_emp2;
不帶引數名呼叫:
call update_emp2(7934, 'ddddd');
使用引數名呼叫:
execute update_emp2(emp_num => 7934, emp_name => 'ddddd');
mysql 儲存過程學習 mysql儲存過程學習
一 mysql建立乙個修改表字段的儲存過程 drop procedure if exists pr test create procedure pr test begin declare var int declare var1 int set var 416 set var1 420 while ...
儲存過程學習筆記
最近公司沒什麼事,空餘時間比較多,因此想的事情也比較多,呵呵.想想做開發都快兩年了,但對資料庫的東西可了解的可謂少之又少.當初學習時就對資料庫沒有過多的研究,只知道對資料表的增刪改查,至於儲存過程 觸發器 索引什麼的都不會。而工作後公司至少連sql語句都不用自己寫的,用的orm技術,直接將表例項化,...
SQL儲存過程學習
一 sql儲存過程的概念,優點及語法整理在學習程式過程之前,先了解下什麼是儲存過程?為什麼要用儲存過程,他有那些優點 定義 將常用的或很複雜的工作,預先用sql語句寫好並用乙個指定的名稱儲存起來,那麼以後要叫資料庫提供與已定義好的儲存過程的功能相同的服務時,只需呼叫execute,即可自動完成命令。...