oracle驗證批量導入存儲過程

一、存儲過程sql

create or replace procedure pro_Test_Admin_Table(testadmintable in varchar2,resultValue out number) is
/**
功能:對一個批量添加的驗證, 返回結果: 1 : 成功  0:失敗 -1 :出現異常
做者:王聘羣
時間:2012-06-01
**/it

 v_sql varchar2(4000);io

 v_count number;table

begin
 
  begin
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''編號不能爲空,請確認!'' where t.fal is null and t.id is null';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''編號已經存在,請確認!'' where t.fal is null and exists(select 1 from admin_table a where a.id=t.id)';
  execute immediate v_sql;
  commit;
 
  v_sql :='update '||testadmintable||' t3 set t3.fal=''失敗'',t3.mark=''存在重複記錄,請確認!'' where t3.rowid in (select t0.rowid  from test_admin_table t0 ,
           (select t1.id,min(t1.rowid) row_id from  test_admin_table t1
            where exists(select 1 id from test_admin_table t0 where t0.id=t1.id group by t0.id having 2<= count(t0.id)) group by t1.id) t2
            where t0.id = t2.id and t0.rowid<>t2.row_id)';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''名稱不能爲空,請確認!'' where t.fal is null and t.name is null';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''年齡不能爲空,請確認!'' where t.fal is null and t.age is null';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''年齡必須爲數字,請確認!'' where t.fal is null and 0 = is_number(t.age)';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''年齡必須爲整型數字,請確認!'' where t.fal is null and INSTR(t.age,''.'')<>0';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''年齡必須爲數字,而且大於0小於150,請確認!'' where t.fal is null and ((select to_number(t.age) from dual) < 1 or  (select to_number(t.age) from dual) > 150)';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''工資不能爲空,請確認!'' where t.fal is null and t.salary is null';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''工資必須爲數字,請確認!'' where t.fal is null and 0=is_number(t.salary)';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''出生日期不能爲空,請確認!'' where t.fal is null and t.brithday is null';
  execute immediate v_sql;
  commit;
 
  v_sql := 'update '||testadmintable||' t set  t.fal=''失敗!'',t.mark=''出生日期必須爲時間類型,而且格式爲:年-月-日,請確認!'' where t.fal is null and 0=is_date(t.brithday,''yyyy-mm-dd'')';
  execute immediate v_sql;
  commit;
 
  v_sql := 'select count(1) from '||testadmintable||' t where t.fal is not null';
  execute immediate v_sql into v_count;
  commit;
 
  v_sql := 'update '||testadmintable||' t set t.fal=''成功'', t.mark=''驗證經過!'' where t.fal is null';
  execute immediate v_sql;
  commit;
 
  if v_count > 0 then
     resultValue := 0;
  else
     resultValue := 1;
  end if;
 
  exception
     when others then
     resultValue := -1;
  end;
 
end;
test

二、驗證結果表date

-- Create table
create table TEST_ADMIN_TABLE
(
  ID       VARCHAR2(1000),
  NAME     VARCHAR2(100),
  AGE      VARCHAR2(1000),
  SALARY   VARCHAR2(1000),
  BRITHDAY VARCHAR2(100),
  FAL      VARCHAR2(1000),
  MARK     VARCHAR2(1000)
)select

三、驗證結果信息exception

1 1 張* 24 2500 2012-05-23 失敗! 編號已經存在,請確認! AAANQaAABAAAPC6AAA
2 2 餘** 23 2530 2012-05-01 成功 驗證經過! AAANQaAABAAAPC6AAB
3  葉*20 2730 2012-06-20 失敗! 編號不能爲空,請確認! AAANQaAABAAAPC6AAC
4 3  25 5000 2012-01-20 失敗! 名稱不能爲空,請確認! AAANQaAABAAAPC6AAD
5 4 周** 24 xx 2012-03-20 失敗! 工資必須爲數字,請確認! AAANQaAABAAAPC6AAE
6 5 王挺* 20 6000 2012-03-20ysm 失敗! 出生日期必須爲時間類型,而且格式爲:年-月-日,請確認! AAANQaAABAAAPC6AAF
7 2 餘** 23 2530 2012-05-01 失敗 存在重複記錄,請確認! AAANQaAABAAAPC6AAG
8 6 劉** 24 5600 2012-05-05 成功 驗證經過! AAANQaAABAAAPC6AAH
9 7 黃* xsa 5621 2012-01-28 失敗! 年齡必須爲數字,請確認! AAANQaAABAAAPC6AAI
10 2 餘** 23 2530 2012-05-01 失敗 存在重複記錄,請確認! AAANQaAABAAAPC6AAJ
11 8 王** 20 4600 2012-02-21 成功 驗證經過! AAANQaAABAAAPC6AAK
12 6 劉** 24 5600 2012-05-05 失敗 存在重複記錄,請確認! AAANQaAABAAAPC6AAL
13 9 小緯子  5200 2012-05-13 失敗! 年齡不能爲空,請確認! AAANQaAABAAAPC6AAM
14 10 小順子 23  2012-06-28 失敗! 工資不能爲空,請確認! AAANQaAABAAAPC6AAN
15 11 小燕子 20 4500  失敗! 出生日期不能爲空,請確認! AAANQaAABAAAPC6AAO
16 12 小川子 24.5 4500 2012-05-23 失敗! 年齡必須爲整型數字,請確認! AAANQaAABAAAPC6AAP
17 13 小葉子 24 6300 2012-14-20 10:20:10 失敗! 出生日期必須爲時間類型,而且格式爲:年-月-日,請確認! AAANQaAABAAAPC6AAQ
18 14 小君子 0 5630 2012-05-23 失敗! 年齡必須爲數字,而且大於0小於150,請確認! AAANQaAABAAAPC6AAR
19 15 小川川 400 6800 2012-05-05 失敗! 年齡必須爲數字,而且大於0小於150,請確認! AAANQaAABAAAPC6AASim

相關文章
相關標籤/搜索