`

pro learn

阅读更多
1、pro1: CREATE OR REPLACE PROCEDURE fojian_oneParam( rCursor OUT SYS_REFCURSOR, numberVarchar varchar2, textVarchar varchar2, justNumber varchar2, justDate date, param_type char, mutil_select char ) AS v_sql varchar2(500); e_exception exception; BEGIN --insert into test_proc(area_id_v,sale,start_time,end_time) values(area_id_v,sale,start_time,end_time); --commit; v_sql:='select area_id_v 地区编号 ,area_name 地区名称 ,sale 销售额 ,profit 利润,showtime 统计时间 from fj_test where 1=1'; --param_type 为返回类型; --00为number型字符;01为文本型字符;1为number型;2为日期型字符;3为数字、字符、日期的综合类型 --mutil_select 是否使用in查询 0为单选;1为多选; IF param_type = '00' AND numberVarchar IS NOT NULL THEN IF mutil_select ='0' THEN v_sql := v_sql || ' and area_id_v ='''|| numberVarchar ||''''; END IF; IF mutil_select ='1' THEN v_sql :=v_sql || ' and area_id_v in (''' || replace(numberVarchar,',',''',''') || ''')'; END IF; END IF; IF param_type = '01' AND textVarchar IS NOT NULL THEN IF mutil_select ='0'THEN v_sql := v_sql || ' and area_name =''' || textVarchar ||''''; END IF; IF mutil_select ='1' THEN v_sql :=v_sql || ' and area_name in (''' || replace(textVarchar,',',''',''') || ''')'; END IF; END IF; IF param_type = '1' AND justNumber IS NOT NULL THEN IF mutil_select ='0'THEN v_sql := v_sql || ' and sale >' || justNumber; END IF; IF mutil_select ='1' THEN v_sql :=v_sql || ' and sale in (' || justNumber || ')'; END IF; END IF; IF param_type = '2' AND justDate IS NOT NULL THEN v_sql := v_sql || ' and showtime >= ''' || justDate || ''''; END IF; IF param_type = '3' AND justDate IS NOT NULL THEN IF numberVarchar is not null THEN v_sql := v_sql || ' and area_id_v in (''' || replace(numberVarchar,',',''',''') || ''')'; END IF; IF justNumber is not null THEN v_sql := v_sql || ' and sale >=' || justNumber; END IF; v_sql := v_sql || ' and showtime >= ''' || justDate || ''''; END IF; IF numberVarchar = '19970101' THEN RAISE e_exception; END IF; --insert into testpro values(v_sql); --commit; dbms_output.put_line(v_sql); --dbms_output.put_line(justDate); open rCursor for v_sql; EXCEPTION WHEN e_exception THEN --INSERT INTO log_table (info) VALUES (e_exception); open rCursor for 'select area_id_v ,area_name ,sale,profit,showtime from fj_test'; WHEN OTHERS THEN insert into log_table (info) values ('Another error occurred'); END fojian_oneParam; 2、create procedure with package CREATE OR REPLACE PACKAGE fojian AS TYPE myrctype IS REF CURSOR; PROCEDURE getFojian (p_id in varchar2, p_rc OUT myrctype); END fojian; CREATE OR REPLACE PACKAGE BODY fojian AS PROCEDURE getFojian (p_id in varchar2, p_rc OUT myrctype) IS sqlstr VARCHAR2 (500); BEGIN IF p_id is null THEN OPEN p_rc FOR SELECT * FROM fj_test; ELSE sqlstr := 'select * from fj_Test where area_id=:p_id'; OPEN p_rc FOR sqlstr USING p_id; END IF; END getFojian ; END fojian; 3、create table with procedure create table fj_test_rpt(statdate date, userid varchar2(20), area_id_v varchar2(10), area_id_n number(10), areaname varchar2(20), outcome_dazong number(38,6), income_dazong number(38,6), outcome_shenzhou number(38,2), income_shenzhou number(38,2), outcome_donggan number(38), income_donggan number(38) ); declare begin for i in 1..20 loop for j in 1..50 loop insert /*+APPEND*/ into fj_test_rpt select (sysdate+i)+j/24/3600, 'fojian', '01', 1, '广州', trunc(dbms_random.value*1000,6), trunc(dbms_random.value*1000,6), trunc(dbms_random.value*1000,2), trunc(dbms_random.value*1000,2), trunc(dbms_random.value*1000,0), trunc(dbms_random.value*1000,0) from dual; end loop; end loop; commit; end;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics