Oracle儲存過程給變數賦值的方法

2021-07-14 09:28:23 字數 474 閱讀 5945

截止到目前我發現有三種方法可以在儲存過程中給變數進行賦值:

1、直接法     :=    

如:v_flag := 0;

2、select into

如:假設變數名為v_flag,select count(*) into v_flag from students;

3、execute immediate 變數名(一般是sql的select語句) into 變數名

如:v_sqlfalg   := 'select count(*) from user_tables where table_name='''||v_tablename || '''';

execute immediate v_sqlfalg into v_flag;

其中,v_tablename也是變數

當然2和3實質是一樣的。只不過3中的select語句是根據變數生成的。

在儲存過程中,是不能直接寫select語句的。

Oracle 過程中變數賦值

create or replace function get sal1 id employees.employee id type return number is sal employees.salary type begin sal 0 select salary into sal from e...

oracle 儲存過程 變數的宣告和賦值的3種方式

按照資料型別的宣告方式進行區分 方式一 直接宣告資料型別 格式 變數名 資料型別 大小 v start date varchar2 19 v num number 說明 設定為字串型別時,需要指定大小,否則報錯 變數的宣告必須在 begin 關鍵字之前進行。錯誤用法 begin v sql varc...

oracle給員工加薪儲存過程

create or replace procedure lee update sala ascursor c row isselect from lee emp 0714 for update of sala begin for v row in c row loop if v row.sala 1...