oracle 存储过程


create or replace procedure P_CREATE_HISTORY_TABLE
is
V_SQL String(31000) :='';

begin
FOR i in 1..2
LOOP
declare num number;
begin select count(1) into num from user_tables where table_name = 'onoffhist_'||to_char(add_months(sysdate,i),'YYYYMM');
if num >0
then execute immediate 'drop table onoffhist_'||to_char(add_months(sysdate,i),'YYYYMM');
end if;
end;
V_SQL := V_SQL||'
create table dtpgsis_onoff.onoffhist_'||to_char(add_months(sysdate,i),'YYYYMM')
||'( id number(10,0) not null enable,
sn number(*,0),
datetime varchar2(20),
maxvalue float(126),
minvalue float(126),
value float(126),
constraint onoffhist_'||to_char(add_months(sysdate,i),'YYYYMM')||' primary key(id)
using index pctfree 10 initrans 2 maxtrans 255
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "DTPGSIS_ONOFF" ENABLE
)' ;
-- DBMS_OUTPUT.put_line(V_SQL);
EXECUTE IMMEDIATE V_SQL;
END LOOP;

COMMIT;
END;
遇到权限问题,请参考此文章解决
[url]
http://www.itpub.net/viewthread.php?tid=413853&extra=&page=1
[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值