存储过程--例子

create or replace procedure cust_xchgsta_byday_proc(p_day varchar2) is
--by day type_all
v_cnt_401 t_console_daysta_tab.cnt_401_snd%type;
v_cnt_301e t_console_daysta_tab.cnt_301e_rcv%type;
v_cnt_301h t_console_daysta_tab.cnt_301h_rcv%type;

v_cnt_402 t_console_daysta_tab.cnt_402_snd%type;
v_cnt_302e t_console_daysta_tab.cnt_302e_rcv%type;
v_cnt_302h t_console_daysta_tab.cnt_302h_rcv%type;

v_cnt_403 t_console_daysta_tab.cnt_403_snd%type;
v_cnt_303e t_console_daysta_tab.cnt_303e_rcv%type;
v_cnt_303h t_console_daysta_tab.cnt_303h_rcv%type;

v_cnt_404 t_console_daysta_tab.cnt_404_snd%type;
v_cnt_304e t_console_daysta_tab.cnt_304e_rcv%type;
v_cnt_304h t_console_daysta_tab.cnt_304h_rcv%type;

v_cnt_411 t_console_daysta_tab.cnt_411_snd%type;
v_cnt_311 t_console_daysta_tab.cnt_311_rcv%type;

v_cnt_412 t_console_daysta_tab.cnt_412_snd%type;
v_cnt_312 t_console_daysta_tab.cnt_312_rcv%type;

--add up type_all
v_cnt_401_addup t_console_daysta_tab.addup_401_snd%type;
v_cnt_301e_addup t_console_daysta_tab.addup_301e_rcv%type;
v_cnt_301h_addup t_console_daysta_tab.addup_301h_rcv%type;

v_cnt_402_addup t_console_daysta_tab.addup_402_snd%type;
v_cnt_302e_addup t_console_daysta_tab.addup_302e_rcv%type;
v_cnt_302h_addup t_console_daysta_tab.addup_302h_rcv%type;

v_cnt_403_addup t_console_daysta_tab.addup_403_snd%type;
v_cnt_303e_addup t_console_daysta_tab.addup_303e_rcv%type;
v_cnt_303h_addup t_console_daysta_tab.addup_303h_rcv%type;

v_cnt_404_addup t_console_daysta_tab.addup_404_snd%type;
v_cnt_304e_addup t_console_daysta_tab.addup_304e_rcv%type;
v_cnt_304h_addup t_console_daysta_tab.addup_304h_rcv%type;

v_cnt_411_addup t_console_daysta_tab.addup_411_snd%type;
v_cnt_311_addup t_console_daysta_tab.addup_311_rcv%type;

v_cnt_412_addup t_console_daysta_tab.addup_412_snd%type;
v_cnt_312_addup t_console_daysta_tab.addup_312_rcv%type;

cur_date date;
sta_date date;
begin
select sysdate into cur_date from dual; --当前日期
select to_date(p_day, ‘yyyymmdd‘) into sta_date from dual; --统计日期
dbms_output.put_line(‘cur_date is ‘ || cur_date);
dbms_output.put_line(‘sta_date is ‘ || sta_date);
--count by day
--xx1
select count(*) c
into v_cnt_401
from t_send_datagrams t
where t.message_type = ‘bac401‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_301e
from t_bac301_prcess_state t
where t.channel in (‘3‘, ‘4‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_301h
from t_bac301_prcess_state t
where t.channel in (‘1‘, ‘2‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;
--xx2
select count(*) c
into v_cnt_402
from t_send_datagrams t
where t.message_type = ‘bac402‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_302e
from t_bac302_prcess_state t
where t.channel in (‘3‘, ‘4‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_302h
from t_bac302_prcess_state t
where t.channel in (‘1‘, ‘2‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;
--xx3
select count(*) c
into v_cnt_403
from t_send_datagrams t
where t.message_type = ‘bac403‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_303e
from t_bac303_prcess_state t
where t.channel in (‘3‘, ‘4‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_303h
from t_bac303_prcess_state t
where t.channel in (‘1‘, ‘2‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

--xx4
select count(*) c
into v_cnt_404
from t_send_datagrams t
where t.message_type = ‘bac404‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_304e
from t_bac304_prcess_state t
where t.channel in (‘3‘, ‘4‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_304h
from t_bac304_prcess_state t
where t.channel in (‘1‘, ‘2‘)
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;
--x11
select count(*) c
into v_cnt_311
from t_bac311_prcess_state t

where to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_411
from t_send_datagrams t
where t.message_type = ‘bac411‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

--x12
select count(*) c
into v_cnt_312
from t_bac312_prcess_state t
where to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

select count(*) c
into v_cnt_412
from t_send_datagrams t
where t.message_type = ‘bac412‘
and to_date(to_char(t.last_oper_time, ‘yyyymmdd‘), ‘yyyymmdd‘) =
sta_date;

--type all add up count
--xx1
select count(*) c
into v_cnt_401_addup
from t_send_datagrams t
where t.message_type = ‘bac401‘;

select count(*) c
into v_cnt_301e_addup
from t_bac301_prcess_state t
where t.channel in (‘3‘, ‘4‘);

select count(*) c
into v_cnt_301h_addup
from t_bac301_prcess_state t
where t.channel in (‘1‘, ‘2‘);
--xx2
select count(*) c
into v_cnt_402_addup
from t_send_datagrams t
where t.message_type = ‘bac402‘;

select count(*) c
into v_cnt_302e_addup
from t_bac302_prcess_state t
where t.channel in (‘3‘, ‘4‘);

select count(*) c
into v_cnt_302h_addup
from t_bac302_prcess_state t
where t.channel in (‘1‘, ‘2‘);
--xx3
select count(*) c
into v_cnt_403_addup
from t_send_datagrams t
where t.message_type = ‘bac403‘;

select count(*) c
into v_cnt_303e_addup
from t_bac303_prcess_state t
where t.channel in (‘3‘, ‘4‘);

select count(*) c
into v_cnt_303h_addup
from t_bac303_prcess_state t
where t.channel in (‘1‘, ‘2‘);

--xx4
select count(*) c
into v_cnt_404_addup
from t_send_datagrams t
where t.message_type = ‘bac404‘;

select count(*) c
into v_cnt_304e_addup
from t_bac304_prcess_state t
where t.channel in (‘3‘, ‘4‘);

select count(*) c
into v_cnt_304h_addup
from t_bac304_prcess_state t
where t.channel in (‘1‘, ‘2‘);
--x11
select count(*) c into v_cnt_311_addup from t_bac311_prcess_state t;

select count(*) c
into v_cnt_411_addup
from t_send_datagrams t
where t.message_type = ‘bac411‘;

--x12
select count(*) c into v_cnt_312_addup from t_bac312_prcess_state t;

select count(*) c
into v_cnt_412_addup
from t_send_datagrams t
where t.message_type = ‘bac412‘;

--remove old data

delete from t_console_daysta_tab where sta_day = sta_date;

insert into t_console_daysta_tab k
(k.id,
k.sta_day,
k.cnt_401_snd,
k.cnt_301e_rcv,
k.cnt_301h_rcv,

k.cnt_402_snd,
k.cnt_302e_rcv,
k.cnt_302h_rcv,

k.cnt_403_snd,
k.cnt_303e_rcv,
k.cnt_303h_rcv,

k.cnt_404_snd,
k.cnt_304e_rcv,
k.cnt_304h_rcv,

k.cnt_311_rcv,
k.cnt_411_snd,

k.cnt_312_rcv,
k.cnt_412_snd,

k.addup_401_snd,
k.addup_301e_rcv,
k.addup_301h_rcv,

k.addup_402_snd,
k.addup_302e_rcv,
k.addup_302h_rcv,

k.addup_403_snd,
k.addup_303e_rcv,
k.addup_303h_rcv,

k.addup_404_snd,
k.addup_304e_rcv,
k.addup_304h_rcv,

k.addup_311_rcv,
k.addup_411_snd,

k.addup_312_rcv,
k.addup_412_snd,

k.sta_time)
values
(sys_guid(),
sta_date,
v_cnt_401,
v_cnt_301e,
v_cnt_301h,

v_cnt_402,
v_cnt_302e,
v_cnt_302h,

v_cnt_403,
v_cnt_303e,
v_cnt_303h,

v_cnt_404,
v_cnt_304e,
v_cnt_304h,

v_cnt_311,
v_cnt_411,

v_cnt_312,
v_cnt_412,

v_cnt_401_addup,
v_cnt_301e_addup,
v_cnt_301h_addup,

v_cnt_402_addup,
v_cnt_302e_addup,
v_cnt_302h_addup,

v_cnt_403_addup,
v_cnt_303e_addup,
v_cnt_303h_addup,

v_cnt_404_addup,
v_cnt_304e_addup,
v_cnt_304h_addup,

v_cnt_311_addup,
v_cnt_411_addup,

v_cnt_312_addup,
v_cnt_412_addup,

cur_date);
commit;

end cust_xchgsta_byday_proc;

时间: 2024-11-11 04:56:01

存储过程--例子的相关文章

DBUTIL 调用存储过程例子

执行存储过程和执行select查询相比,无非就是SQL语句不同.下面是一个用存储过程查记录的例子.根据你的数据库不同和域对象不同,此代码要修改 Java code ? 1 2 3 4 5 QueryRunner r = new QueryRunner(); String sql = "{call search_as_cname(?)}"; //携参存储过程的SQL这样写 String textStr = "英%"; Course s = (Course)r.quer

附上SQL Server的存储过程例子

代码如下,看了就明白: --添加项目大类存储过程 use chaiqianD2 go if object_id('p_InsertBigType', 'p') is not null drop procedure p_InsertBigType go create procedure p_InsertBigType @Name nvarchar(50) --[大类名称] as begin insert into [项目大类]([大类名称]) values(@name) end 2.稍微难点滴,大

mysql存储过程例子

/*定义变量方式1:set @变量名=值;方式2:select 值 into @变量名;方式3:declare 变量名 类型(字符串类型加范围) default 值; in参数 入参的值会仅在存储过程中起作用out参数 入参的值会被置为空,存储中计算的值会影响外面引用该变量的值inout参数 入参的值不会被置为空,存储中计算的值会影响外面引用该变量的值*/use mysql;/*创建1个存储过程*/delimiter $$DROP PROCEDURE IF EXISTS porc_person_

oracle_存储过程例子_1

--关于游标 if,for 的例子create or replace procedure peace_ifis cursor var_c is select * from grade;begin for temp in var_c loopif temp.course_name='OS' then dbms_output.put_line('Stu_name='||temp.stu_name);else if temp.course_name='DB' then dbms_output.put_

sql 存储过程例子和学习demo

-------------------------------------------------------------------------- -------------------------------存储过程Study------------------------------ -------------------------------------------------------------------------- --删除表 drop table student go -

postgrep创建存储过程例子

1.创建数据库psql create database db_hxl encoding = 'utf8';#\c db_hxl 2.创建表create table tb_test01(id bigserial primary key not null,name varchar(32),createtime timestamp default current_timestamp,modifytime  timestamp default current_timestamp); 3.创建存储过程 C

MySql存储过程例子1

delimiter // drop procedure if exists p_PreLogin// create procedure p_PreLogin( IN in_username varchar(32), IN in_password varchar(32), IN in_asshkey varchar(33), IN in_usshkey varchar(33), IN in_gameid tinyint, IN in_logintype tinyint ) PROC_LABEL:

sqlserver 存储过程例子

//带参数的小列子 if (exists (select * from sys.objects where name = 'proc_get_Purchasing2')) drop proc proc_get_student go alter proc proc_get_Purchasing2(@today int) as --declare @today int //申明变量 declare @weeks nvarchar(3) //设置变量值 set @weeks set @weeks=ca

mysql 存储过程 例子

CREATE DEFINER=`root`@`%` PROCEDURE `sp_GetWangingsCount`(IN `PCode` VARCHAR(50), IN `FromDay` DATE, IN `Cycle` INT, IN `DayCount` INT, OUT `Rlt` INT, OUT `DayStr` VARCHAR(520)) LANGUAGE SQL NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT