aphrodite 2011-05-11
CREATE OR REPLACE PROCEDURE PD_GENERATE_HELP_LAST_TABLES IS
--把从sqlserver中生成的vw_last_xxx所对应的视图生成本地的数据表
tabNocount NUMBER ;
v_sql VARCHAR2(200);
BEGIN
--判断表dat_help_last_scqy1(成品油生产旬报)
SELECT count(*) INTO tabNocount FROM user_tables WHERE table_name = 'DAT_HELP_LAST_SCQY1';
IF tabNocount>0 THEN
dbms_output.put_line('drop table dat_help_last_scqy1');
v_sql := 'DROP TABLE DAT_HELP_LAST_SCQY1';
EXECUTE IMMEDIATE v_sql;
END IF;
dbms_output.put_line('create table dat_help_last_scqy1');
v_sql := 'CREATE TABLE DAT_HELP_LAST_SCQY1 AS SELECT * FROM VW_LAST_SCQY1';
EXECUTE IMMEDIATE v_sql;
--判断表dat_help_last_scqy2(成品油生产月报)
SELECT count(*) INTO tabNocount FROM user_tables WHERE table_name = 'DAT_HELP_LAST_SCQY2';
IF tabNocount>0 THEN
dbms_output.put_line('drop table dat_help_last_scqy2');
v_sql := 'DROP TABLE DAT_HELP_LAST_SCQY2';
EXECUTE IMMEDIATE v_sql;
END IF;
dbms_output.put_line('create talbe dat_help_last_scqy2');
v_sql := 'CREATE TABLE DAT_HELP_LAST_SCQY2 AS SELECT * FROM VW_LAST_SCQY2';
EXECUTE IMMEDIATE v_sql;
--判断表dat_help_last_shsndybb(能源调度月报表)
SELECT count(*) INTO tabNocount FROM user_tables WHERE table_name = 'DAT_HELP_LAST_SHSNDYBB';
IF tabNocount>0 THEN
dbms_output.put_line('drop table dat_help_last_shsndybb');
v_sql := 'DROP TABLE DAT_HELP_LAST_SHSNDYBB';
EXECUTE IMMEDIATE v_sql;
END IF;
dbms_output.put_line('create table dat_help_last_shsndybb');
v_sql := 'CREATE TABLE dat_help_last_shsndybb AS SELECT * FROM vw_last_shsndybb';
EXECUTE IMMEDIATE v_sql;
END PD_GENERATE_HELP_LAST_TABLES;
测试
begin
-- Call the procedure
pd_generate_help_last_tables;
end;
如果出现 ORA-01031: 权限不足
ORA-06512: 在"SYSTEM.CCCCCC", line 6
ORA-06512: 在line 1
的错误,则执行以下授权语句
grant create table to jwdc;
grant resource to jwdc;
grant create procedure to jwdc;