一、表結構
-- create table
create table card_bin_ctrl
(card_bin char(12) not null,
card_len integer not null,
channel_type char(2) not null,
card_bin_len integer,
card_type char(1),
issuer_code char(11),
card_name char(60),
amt_limit char(12),
tran_enable char(1),
reversal1 char(100),
reversal2 char(100)
)tablespace elink
pctfree 10
initrans 1
maxtrans 255
storage
(initial 64k
next 1m
minextents 1
maxextents unlimited
);-- create/recreate primary, unique and foreign key constraints
alter table card_bin_ctrl
add primary key (card_bin, card_len, channel_type)
using index
tablespace elink
pctfree 10
initrans 2
maxtrans 255
storage
(initial 64k
next 1m
minextents 1
maxextents unlimited
);二、投產操作步驟如下
1、登入sql*plus
2、依次輸入以下命令:
a)show serveroutput
b)set serveroutput on
c)show serveroutput
d)exec insert_03_channel;
三、儲存過程如下
create or replace procedure insert_03_channel is
tmp_card_bin card_bin_ctrl.card_bin%type; --暫存單個card_bin的變數
tmp_card_bin_ctrl_rcd card_bin_ctrl%rowtype; --暫存card_bin_ctrl表中單條記錄的變數
--定義並初始化變數
channel_07 card_bin_ctrl.channel_type%type := '07';
channel_16 card_bin_ctrl.channel_type%type := '16';
channel_03 card_bin_ctrl.channel_type%type := '03';
cursor cur_card_bin is --指向card_bin_ctrl表中所有卡bin的游標
select distinct card_bin from card_bin_ctrl;
type rc is ref cursor;
cur_card_bin_ctrl_rcd rc; --指向包含特定卡bin的記錄集合的游標
begin
dbms_output.enable(9999999999);
open cur_card_bin;
loop
exit when(cur_card_bin%notfound);
fetch cur_card_bin
into tmp_card_bin;
open cur_card_bin_ctrl_rcd for
select * from card_bin_ctrl where card_bin = tmp_card_bin;
loop
exit when(cur_card_bin_ctrl_rcd%notfound);
fetch cur_card_bin_ctrl_rcd
into tmp_card_bin_ctrl_rcd;
begin
if (trim(tmp_card_bin_ctrl_rcd.channel_type) = channel_07 or
trim(tmp_card_bin_ctrl_rcd.channel_type) = channel_16) then
insert into card_bin_ctrl
(card_bin,
card_len,
channel_type,
card_bin_len,
card_type,
issuer_code,
card_name,
amt_limit,
tran_enable,
reversal1,
reversal2)
values
(tmp_card_bin_ctrl_rcd.card_bin,
tmp_card_bin_ctrl_rcd.card_len,
channel_03,
tmp_card_bin_ctrl_rcd.card_bin_len,
tmp_card_bin_ctrl_rcd.card_type,
tmp_card_bin_ctrl_rcd.issuer_code,
tmp_card_bin_ctrl_rcd.card_name,
tmp_card_bin_ctrl_rcd.amt_limit,
tmp_card_bin_ctrl_rcd.tran_enable,
tmp_card_bin_ctrl_rcd.reversal1,
tmp_card_bin_ctrl_rcd.reversal2);
commit;
end if;
exception
when dup_val_on_index then
dbms_output.put_line('重複插入,聯合主鍵衝突!');
when others then
rollback;
end;
end loop;
close cur_card_bin_ctrl_rcd;
end loop;
close cur_card_bin;
end insert_03_channel;
使用SQLPLUS備份儲存過程
set echo off set newpage none set feedback off set linesize 2500 set heading off set pagesize 0 set termout off set trimout on set trimspool on col pr...
oracle 儲存過程建立和使用舉例
oracle 儲存過程建立和使用舉例 1.建立儲存過程 create or replace package pk 1 as 建立包的宣告 type cur is ref cursor 宣告乙個指標 procedure p1 cr out cur end create or replace packa...
儲存過程與儲存函式
plsql中語法 create or replace procedure 過程名 引數名 in out 型別 asbegin end 宣告pro add sal儲存過程,作用是給指定員工漲1000元工資,並列印出漲前和漲後工資 create orreplace procedure pro add s...