标签:into creat mod sequence NPU inf out group by success
-- 创建表 PLAYER_INFO
DROP TABLE PLAYER_INFO;
CREATE TABLE PLAYER_INFO
(
player_id number(12, 0) PRIMARY KEY
,player_name varchar2(20) NOT NULL
,oper_mark number(12, 0)
,input_date number(10,0) DEFAULT to_number(to_char(sysdate,‘yyyymmdd‘))
,input_time number(10,0) DEFAULT to_number(to_char(sysdate,‘hh24miss‘))
);
-- 创建序列 SEQ_PLAYER_INFO
DROP SEQUENCE SEQ_PLAYER_INFO;
CREATE SEQUENCE SEQ_PLAYER_INFO
INCREMENT BY 1
START WITH 1
MAXVALUE 999999999999999999999999999
CYCLE
CACHE 20;
--创建姓名库 PLAYER_NAME_LIST
DROP TABLE PLAYER_NAME_LIST;
CREATE TABLE PLAYER_NAME_LIST
(
PLAYER_NAME varchar2(20) NOT NULL
);
INSERT INTO PLAYER_NAME_LIST (PLAYER_NAME) VALUES (‘张三‘);
INSERT INTO PLAYER_NAME_LIST (PLAYER_NAME) VALUES (‘李四‘);
INSERT INTO PLAYER_NAME_LIST (PLAYER_NAME) VALUES (‘王五‘);
INSERT INTO PLAYER_NAME_LIST (PLAYER_NAME) VALUES (‘ANLEX‘);
INSERT INTO PLAYER_NAME_LIST (PLAYER_NAME) VALUES (‘GORDON‘);
CREATE OR REPLACE PROCEDURE gen_player_info_for_test
(
p_gen_count NUMBER -- 生成条目数
,p_error_no OUT NUMBER -- 错误号
,p_error_info OUT VARCHAR2 -- 错误提示
,p_error_id OUT NUMBER -- 错误序号
,p_error_sysinfo OUT VARCHAR2 -- 系统错误信息
) AS
p_curr_value NUMBER := 0;
p_end_value NUMBER := 0;
player_name VARCHAR2(20) := ‘‘;
CURSOR player_name_cur IS SELECT PLAYER_NAME FROM PLAYER_NAME_LIST; --生成游标
BEGIN
dbms_output.put_line(‘----------- PROCUDURE START -----------‘);
p_curr_value := 0;
p_end_value := p_gen_count;
player_name := ‘‘;
WHILE p_curr_value < p_end_value
LOOP
p_curr_value := p_curr_value + 1;
FOR player_name IN player_name_cur --循环游标
LOOP
INSERT INTO player_info
(player_id,
player_name,
oper_mark)
VALUES
(seq_player_info.nextval,
player_name.PLAYER_NAME||p_curr_value,
60 + abs(mod(dbms_random.random, 40)));
COMMIT;
END LOOP;
END LOOP;
dbms_output.put_line(‘----------- PROCUDURE END -----------‘);
p_error_no := 0;
p_error_info := ‘EXECUTE SUCCESS‘;
p_error_id := SQLCODE;
p_error_sysinfo := SQLERRM;
EXCEPTION
WHEN OTHERS THEN
p_error_no := 999;
p_error_info := ‘存储过程执行错误‘;
p_error_id := SQLCODE;
p_error_sysinfo := SQLERRM;
END gen_player_info_for_test;
CREATE OR REPLACE PROCEDURE insert_job_for_test AS
BEGIN
DECLARE
p_error_no NUMBER(10) :=1;
p_error_info VARCHAR2(100) :=‘‘;
p_error_id NUMBER(20) :=1;
p_error_sysinfo VARCHAR2(100) :=‘‘;
BEGIN
gen_player_info_for_test(100, p_error_no, p_error_info, p_error_id, p_error_sysinfo);
END;
COMMIT;
END insert_job_for_test;
附:时间间隔说明
interval是指上一次执行结束到下一次开始执行的时间间隔,当interval设置为null时,该job执行结束后,就被从队列中删除。若要周期性进行执行,则要对间隔进行设置,常见间隔设置如下:
每分钟执行
TRUNC(sysdate, ‘mi‘) + 1/ (24*60)
每小时执行
TRUNC(sysdate, ‘hh‘) + 1/ (24)
每天定时执行
例如:每天的凌晨1点执行
TRUNC(sysdate + 1) + 1/ (24)
每周定时执行
例如:每周一凌晨1点执行
TRUNC(next_day(sysdate, ‘星期一‘)) + 1/24
每月定时执行
例如:每月1日凌晨1点执行
TRUNC(LAST_DAY(SYSDATE)) + 1 + 1/24
每季度定时执行
例如:每季度的第一天凌晨1点执行
TRUNC(ADD_MONTHS(SYSDATE, 3), ‘Q‘) + 1/24
每半年定时执行
例如:每年7月1日凌晨1点执行
ADD_MONTHS(TRUNC(SYSDATE, ‘yyyy‘), 6) + 1/24
每年定时执行
例如:每年1月1日凌晨1点执行
ADD_MONTHS(TRUNC(SYSDATE, ‘yyyy‘), 12) + 1/24
SELECT
INPUT_TIME AS INPUT_TIME
,COUNT(*) AS CNT
FROM PLAYER_INFO
GROUP BY INPUT_TIME;
标签:into creat mod sequence NPU inf out group by success
原文地址:https://www.cnblogs.com/rengongzhizhang-v1/p/13977556.html