create or replace procedure ecs_customdetail_0929 --建立儲存過程
islongerstation varchar2(50); --定義變數
type v_cursor is ref cursor; --變義游標
detailid v_cursor;
in_id v_cursor;
v_str varchar2(200);
in_str varchar2(200);
tab_detailid varchar2(32);
in_stationname varchar2(50);
begin
v_str := 'select id from customdetail_0927';
open detailid for v_str ; --開啟游標
loop fetch detailid into tab_detailid; --迴圈游標
exit when detailid%notfound; --當找不到資料的時候退出迴圈
in_str :='select stationname from bak0902_sell_customerdetail where id = '''||tab_detailid||''''; --變數的連線方法
open in_id for in_str ;
longerstation :='a'; --給變數賦值
loop fetch in_id into in_stationname;
exit when in_id%notfound;
if length(in_stationname)>=length(longerstation) then longerstation :=in_stationname;
end if;
end loop;
dbms_output.put_line(longerstation);
insert into b_bus_selcustomerdetaildel1010 select * from bak0902_sell_customerdetail where id=tab_detailid and stationname=longerstation; --把查出來的資料插入另一資料表裡
delete from bak0902_sell_customerdetail where id=tab_detailid and stationname=longerstation;--刪除相應的資料
commit;
close in_id;
end loop;
close detailid;
end ecs_customdetail_0929;
Oracle儲存過程詳解 三 巢狀
created on 2016 4 22 by administrator declare p dname varchar2 50 微軟 p deptno number 60 p deptloc varchar2 100 公尺國 v state varchar2 50 狀態 begin 內部巢狀塊 ...
oracle儲存過程學習筆記 三
2.空值表示式與or 程式段1 set serveroutput on declare my name varchar2 10 scott other name varchar2 10 null begin if my name scott or other name join then dbms ...
Oracle儲存過程呼叫儲存過程
oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...