批量提交事例
-- Create sequence
create sequence P_STOCK_MONTH_SEQ
minvalue 1
maxvalue 99999999999
start with 37
increment by 1
cache 20;
-- Create table
create table P_STOCK_MONTH
(
tid INTEGER not null,
id NUMBER not null,
type NUMBER,
cate_id NUMBER,
goods_id NUMBER,
amount NUMBER,
unit NUMBER,
price_base NUMBER,
total NUMBER,
amount_deliver NUMBER,
amount_sell NUMBER,
amount_lock NUMBER,
house_id NUMBER,
house_no VARCHAR2(100),
status NUMBER,
delete_flag NUMBER,
remark VARCHAR2(1000),
industry_id NUMBER,
amount_loss NUMBER,
stock_month VARCHAR2(8)
)
tablespace JXC
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 P_STOCK_MONTH
add constraint PK_P_STOCK_MONTH primary key (TID)
using index
tablespace JXC
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
--建立同步資料儲存過程
create or replace procedure proc_sync_stock as
/*
Date:2015-11-06
Author:huangxianglong
Description:每個月底23:59:59同步資料到p_stock_month中
Version:1.0
*/
begin
DECLARE CURSOR cur IS
SELECT p_stock_month_seq.nextval,
m.*,
to_char(sysdate, 'yyyy-mm')
FROM p_stock m;
TYPE rec IS TABLE OF p_stock_month%ROWTYPE;
recs rec;
BEGIN
OPEN cur;
WHILE (TRUE) LOOP
FETCH cur BULK COLLECT
INTO recs LIMIT 100;
FORALL i IN 1 .. recs.COUNT
INSERT INTO p_stock_month VALUES recs (i);
COMMIT;
EXIT WHEN cur%NOTFOUND;
END LOOP;
CLOSE cur;
END;
end proc_sync_stock;
--建立JOB
begin
sys.dbms_scheduler.create_job(job_name => 'JXC.JOB_PROC_SYNC_STOCK',
job_type => 'STORED_PROCEDURE',
job_action => 'PROC_SYNC_STOCK',
start_date => to_date('30-11-2015 23:59:59', 'dd-mm-yyyy hh24:mi:ss'),
repeat_interval => 'Freq=Monthly;Interval=1;ByMonth=Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => true,
auto_drop => false,
comments => '');
end;
create sequence P_STOCK_MONTH_SEQ
minvalue 1
maxvalue 99999999999
start with 37
increment by 1
cache 20;
-- Create table
create table P_STOCK_MONTH
(
tid INTEGER not null,
id NUMBER not null,
type NUMBER,
cate_id NUMBER,
goods_id NUMBER,
amount NUMBER,
unit NUMBER,
price_base NUMBER,
total NUMBER,
amount_deliver NUMBER,
amount_sell NUMBER,
amount_lock NUMBER,
house_id NUMBER,
house_no VARCHAR2(100),
status NUMBER,
delete_flag NUMBER,
remark VARCHAR2(1000),
industry_id NUMBER,
amount_loss NUMBER,
stock_month VARCHAR2(8)
)
tablespace JXC
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 P_STOCK_MONTH
add constraint PK_P_STOCK_MONTH primary key (TID)
using index
tablespace JXC
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
--建立同步資料儲存過程
create or replace procedure proc_sync_stock as
/*
Date:2015-11-06
Author:huangxianglong
Description:每個月底23:59:59同步資料到p_stock_month中
Version:1.0
*/
begin
DECLARE CURSOR cur IS
SELECT p_stock_month_seq.nextval,
m.*,
to_char(sysdate, 'yyyy-mm')
FROM p_stock m;
TYPE rec IS TABLE OF p_stock_month%ROWTYPE;
recs rec;
BEGIN
OPEN cur;
WHILE (TRUE) LOOP
FETCH cur BULK COLLECT
INTO recs LIMIT 100;
FORALL i IN 1 .. recs.COUNT
INSERT INTO p_stock_month VALUES recs (i);
COMMIT;
EXIT WHEN cur%NOTFOUND;
END LOOP;
CLOSE cur;
END;
end proc_sync_stock;
--建立JOB
begin
sys.dbms_scheduler.create_job(job_name => 'JXC.JOB_PROC_SYNC_STOCK',
job_type => 'STORED_PROCEDURE',
job_action => 'PROC_SYNC_STOCK',
start_date => to_date('30-11-2015 23:59:59', 'dd-mm-yyyy hh24:mi:ss'),
repeat_interval => 'Freq=Monthly;Interval=1;ByMonth=Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec',
end_date => to_date(null),
job_class => 'DEFAULT_JOB_CLASS',
enabled => true,
auto_drop => false,
comments => '');
end;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24486203/viewspace-2124077/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【INSERT】逐行提交、批量提交及極限提速方法
- 大表資料插入批量提交
- 使用BULK COLLECT+FORALL加速批量提交
- laravel mysql批量提交報Access denied 錯誤LaravelMySql
- Entity Framework中 批量提交 事務處理Framework
- Oracle EBS提交過多請求批量取消的方法Oracle
- Oracle Date Function 講解和事例OracleFunction
- hibernate出錯 不能事例sessionFactorySession
- Spring整合Kafka實現批量消費和手動提交offsetSpringKafka
- Oracle Date Function 講解和事例【Blog 搬家】OracleFunction
- oracle使用outline固定執行計劃事例Oracle
- mysql master-slave複製錯誤[解決事例]MySqlAST
- 7分鐘用事例帶你掌握工作常用的 git 命令Git
- 對CSS變數不熟悉,這5個事例可看看!CSS變數
- 開發:隨筆記錄之 HTML 彈出透明層事例筆記HTML
- c#關於同步 /異常/多執行緒/事件 事例C#執行緒事件
- ELK研究(一):elasticsearch java api介面操作ES叢集 ---TransportClient的使用介紹 bulk批量提交資料ElasticsearchJavaAPIclient
- git 修改提交作者及提交日期Git
- 關於搶購秒殺的實現思路與事例程式碼
- mysql兩階段提交和組提交MySql
- 搜狗站長工具【post請求模擬登入】程式碼分享總結【批量提交搜狗收錄網址】
- GitPHP提交GitPHP
- Git——提交Git
- CF提交
- RDIFramework.NET V3.3 WinForm版新增訂單管理主從表事例FrameworkORM
- sourceTree“重置提交”和“提交回滾”的區別
- 抖音批量取消喜歡,批量取消抖音喜歡
- 表格的批量重新命名與批量刪除
- Python提交Python
- github提交操作Github
- 非同步提交非同步
- 提交規範
- 如何提交pr
- GitHub提交PRGithub
- SQLServer批量更新SQLServer
- Laravel 批量更新Laravel
- 批量請求
- 批量監控