oracle 帶游標的儲存過程

2021-09-01 07:24:51 字數 2179 閱讀 5017

如果各位以前從來沒有寫儲存過程,可得仔細了,因為在進行儲存過程編寫的時候,新手很容易出錯,非常容易。

執行儲存過程各個oracle客戶端是不是樣的

可能你在網上看到的是呼叫exec,但是你再怎以呼叫你都執行不了,原因何在,因為exec是pl/sql develop裡面的乙個程式,而你當前使用oracl客戶端不是pl/sql,如果你再怎麼也執行不了。

我所使用的工具是dbvisualize,在使用這個工具時,我遇到了各種各樣的問題。

首先得:@set serveroutput on;

首先得:@set serveroutput on;

而在dbvisualizer裡面的建立

--/create procedure abc

asou integer;

begin

select count(1) into ou from dp_1_sys_branceoffice;

end;/執行

--/begin

abc();

end;

/也可以

call abc();

而如果你想用exec,那麼你必須安裝pl/sql,這樣,它會在環境變數裡面新增上exec,然後你在命令列上就行exec

procedurename();

定義變數要有長度,如:

create or replace procedure "deppon"."ou"(x in integer)

as b varchar2(200);

begin

select name into b from dp_1_sys_branceoffice where id=x;

dbms_output.put_line(b);

end;

如果你寫成了    b varchar2;會報錯"字串長度限制在範圍 (1...32767)"

當然,你進行定義引數時,並不需要指明長度,如下

create or replace procedure ou(x in integer,v out varchar2)

as b varchar2(200);

begin

select name into b from table where id=x;

end;

上面的 v out varchar2如果我們寫成  v out varchar2(200) 編譯器就會報錯了

--/declare

*** varchar2(12);

begin

ou(1,***);

dbms_output.put_line(***);

end;

/帶游標的儲存過程

create or replace procedure general_hub_node_dis

is hub varchar2(200);

node varchar2(200);

rs sys_refcursor;

begin

open rs for select hub_name,node_name from t_solution_hub_node;

loop

fetch rs into hub,node;

exit when rs%notfound;

execute immediate 'insert into ***(hub,branceoffice) select a.name as hub,b.name as branchoffice from

table1 a right join table2 b on(1=1) where b.start_dc=concat(:1,:2) and b.latitude is not

null and a.name = concat(:3,:4)' using node,'外場',hub,'外場';

end loop;

end;

因為 dbms_output.put_line的

最大輸入是

250個字元,所以如果我們需要輸出大於250的字元

我們列印輸出時,需要用到的

vaa:=1;

while vaa<=length(vsql)

loop

dbms_output.put_line(substr(vsql, vaa, 200));

vaa := vaa + 200;

end loop;

oracle帶游標的儲存過程

create or replace procedure xs test add19 is bachelor edu varchar2 2000 new bachelor edu varchar2 2000 aa varchar2 2000 bb varchar2 2000 edu length in...

oracle 含參帶游標的儲存過程

系統中有個模組的基礎資料需要導到資料庫,由於資料量比較大,而且 內容分布較凌亂。就先將資料匯入臨時表,然後根據臨時表進行有效的檢索並新增到對應的表中。今天下午寫了個含有引數,帶游標的儲存過程。算是把這個問題給解決了。本人需求大致如下 現有臨時表 sheet1 資料是直接從excel的sheet1中讀...

帶游標的儲存過程例子,很經典

create or replace procedure sum storage isplant g containerinv.plant type sloc g containerinv.sloc type part g containerinv.partno type qty g containe...