惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
T
Tenable Blog
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
WordPress大学
WordPress大学
Latest news
Latest news
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
C
Cisco Blogs
博客园 - 聂微东
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
小众软件
小众软件
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
Y
Y Combinator Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 最新话题
月光博客
月光博客
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
S
Security Affairs
P
Proofpoint News Feed
D
DataBreaches.Net
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG

博客园 - wzc998

Oracle Audit 关于"cannot perform a DDL, commit or rollback inside a query or DML" 错误 关于varchar2在pl/sql和schema级别的最大值 ORA-01031 权限不足错误的解决 XSL ASP .net实现松耦合事件的三种方法 Log4net不同版本在app.config和web.config的配置区别 SQL*Loader FAQ 【转】NLS 视图的研究 oracle多语言环境下to_date时间转换问题 【转】如何使用 ADO.NET 和 Visual C# .NET 调用带参数的存储过程 【转】SQL SERVER 存储过程学习笔记 【转】代码复用原则:合理使用类组合和类继承 委托与接口的关系 IOC 【转】范式 【转】oracle范式与交叉表 oracle存储过程返回交叉表(使用存储过程/高级语言调用)
通过代码备份存储过程,package body 和表数据 并还原
wzc998 · 2011-08-12 · via 博客园 - wzc998

Table data
--buckup table data
create table Table_BUCKUP as
(select * from Table1);

--roolback table data

drop table Table1;
create table Table1 as
(select * from Table_BUCKUP);

drop table Table_BUCKUP;

当表中存在long类型字段是会有异常 ORA-00997: 非法使用 LONG 数据类型, 遇到这种问题使用to_lob或或sys.dbms_metadata_util.long2varchar对数据进行转换,如下:

create table Table_BUCKUP as
(select to_lob(col) as C1 from Table1);

此时roolback 需要将lob转回到原来的类型了。

Package

--buck up DDL
Create table Package_BUCKUP
(name varchar(10),
script club
);
insert into Package_BUCKUP
value
select 'PKG1' name,dbms_metadata.get_ddl('PACKAGE','PackageName','SchemaName') script from dual;

--roolback DDL

由于EXECUTE IMMEDIATE 不能执行 club字段类型 可以将club转成varchar2或long再执行,9i以上版本的oracle中 varchar2再PL/SQL中最大值是32767 再schema中4000, 如果你的script不超过32767就不存在问题。

但是我得超过了最大值限制。 其实可以输出到文件,再执行。 有时间的时候我再试吧,经过沟通领导不需要通过script备份,领导想用pl/sqldeveloper得功能导出来备。

下面给出我失败的例子

PROCEDURE rollbacktest
IS
  v_sql      clob;
  v_sql_long long;
  tmp        long;
  tmp1       long;
  TMP2       long;
  TMP3       long;
  TMP4       long;
  TMP5       long;
  TMP6       long;
  TMP7       long;
  TMP8       long;
  TMP9       long;
  TMP10      long;
  TMP11      long;
  TMP12      long;
  TMP13      long;
  TMP14      long;
  TMP15      long;
  TMP16      long;
  TMP17      long;
  TMP18      long;
  TMP19      long;
  TMP20      long;
  TMP21      long;
  TMP22      long;
  TMP23      long;
  TMP24      long;
  TMP25      long;
  TMP26      long;
  TMP27      long;
  TMP28      long;
  TMP29      long;
  TMP30      long;
  TMP31      long;
  TMP32      long;
  TMP33      long;
  TMP34      long;
  TMP35      long;
  TMP36      long;
  TMP37      long;
  TMP38      long;
  TMP39      long;
  TMP40      long;
  TMP41      long;
  TMP42      long;
  TMP43      long;
  TMP44      long;
  TMP45      long;
  TMP46      long;
  TMP47      long;
  TMP48      long;
  TMP49      long;
  TMP50      long;
  TMP51      long;
  TYPE ref0 IS REF CURSOR;
  cur0        ref0;
  v_count     int;
  v_interval  int;
  v_tmp_execu long;
  v_tmp_swap  long;
BEGIN
v_interval := 32767;

  select script into v_sql from package_buckup where name = 'PAS_PKG';

  OPEN cur0 FOR
    select LEVEL - 1
      from package_buckup
     where name = 'PAS_PKG'
    connect by LEVEL <= ceil(length(script) / v_interval);

  LOOP
    FETCH cur0
      into v_count;
    EXIT WHEN cur0%NOTFOUND;
 
    dbms_output.put_line(to_char(v_count));
    if v_count = 0 then
      tmp := dbms_lob.substr(v_sql, v_interval, 1);
      insert into package_debug values (tmp, sysdate, 'tmp', v_count);
    else
      tmp := tmp ||
             dbms_lob.substr(v_sql, v_interval, (v_count * v_interval) + 1);
      insert into package_debug values (tmp, sysdate, 'tmp', v_count);
    end if;
   
    if v_count = 0 then
      TMP1 := TMP;
    end if;
    if v_count = 1 then
      TMP2 := TMP;
    end if;
    if v_count = 2 then
      TMP3 := TMP;
    end if;
    if v_count = 3 then
      TMP4 := TMP;
    end if;
    if v_count = 4 then
      TMP5 := TMP;
    end if;
    if v_count = 5 then
      TMP6 := TMP;
    end if;
    if v_count = 6 then
      TMP7 := TMP;
    end if;
    if v_count = 7 then
      TMP8 := TMP;
    end if;
    if v_count = 8 then
      TMP9 := TMP;
    end if;
    if v_count = 9 then
      TMP10 := TMP;
    end if;
    if v_count = 10 then
      TMP11 := TMP;
    end if;
    if v_count = 11 then
      TMP12 := TMP;
    end if;
    if v_count = 12 then
      TMP13 := TMP;
    end if;
    if v_count = 13 then
      TMP14 := TMP;
    end if;
    if v_count = 14 then
      TMP15 := TMP;
    end if;
    if v_count = 15 then
      TMP16 := TMP;
    end if;
    if v_count = 16 then
      TMP17 := TMP;
    end if;
    if v_count = 17 then
      TMP18 := TMP;
    end if;
    if v_count = 18 then
      TMP19 := TMP;
    end if;
    if v_count = 19 then
      TMP20 := TMP;
    end if;
    if v_count = 20 then
      TMP21 := TMP;
    end if;
    if v_count = 21 then
      TMP22 := TMP;
    end if;
    if v_count = 22 then
      TMP23 := TMP;
    end if;
    if v_count = 23 then
      TMP24 := TMP;
    end if;
    if v_count = 24 then
      TMP25 := TMP;
    end if;
    if v_count = 25 then
      TMP26 := TMP;
    end if;
    if v_count = 26 then
      TMP27 := TMP;
    end if;
    if v_count = 27 then
      TMP28 := TMP;
    end if;
    if v_count = 28 then
      TMP29 := TMP;
    end if;
    if v_count = 29 then
      TMP30 := TMP;
    end if;
    if v_count = 30 then
      TMP31 := TMP;
    end if;
    if v_count = 31 then
      TMP32 := TMP;
    end if;
    if v_count = 32 then
      TMP33 := TMP;
    end if;
    if v_count = 33 then
      TMP34 := TMP;
    end if;
    if v_count = 34 then
      TMP35 := TMP;
    end if;
    if v_count = 35 then
      TMP36 := TMP;
    end if;
    if v_count = 36 then
      TMP37 := TMP;
    end if;
    if v_count = 37 then
      TMP38 := TMP;
    end if;
    if v_count = 38 then
      TMP39 := TMP;
    end if;
    if v_count = 39 then
      TMP40 := TMP;
    end if;
    if v_count = 40 then
      TMP41 := TMP;
    end if;
    if v_count = 41 then
      TMP42 := TMP;
    end if;
    if v_count = 42 then
      TMP43 := TMP;
    end if;
    if v_count = 43 then
      TMP44 := TMP;
    end if;
    if v_count = 44 then
      TMP45 := TMP;
    end if;
    if v_count = 45 then
      TMP46 := TMP;
    end if;
    if v_count = 46 then
      TMP47 := TMP;
    end if;
    if v_count = 47 then
      TMP48 := TMP;
    end if;
    if v_count = 48 then
      TMP49 := TMP;
    end if;
    if v_count = 49 then
      TMP50 := TMP;
    end if;
 
    --if mod(v_count+1,3) = 0 then
    tmp := '';
 
  end loop;
 
  /*select length(tmp1 || tmp2 || tmp3 || tmp4 || tmp5 || tmp6 || tmp7 || tmp8 || tmp9 ||
                    tmp10 || tmp11 || tmp12 || tmp13 || tmp14 || tmp15 ||
                    tmp16 || tmp17 || tmp18 || tmp19 || tmp20 || tmp21) into v_count from dual;
                   
                    dbms_output.put_line(v_count);*/
                   
  /*EXECUTE IMMEDIATE tmp1 || tmp2 || tmp3 || tmp4 || tmp5 || tmp6 || tmp7 || tmp8 || tmp9 ||
                    tmp10 || tmp11 || tmp12 || tmp13 || tmp14 || tmp15 ||
                    tmp16 || tmp17 || tmp18 || tmp19 || tmp20 || tmp21 ||
                    tmp22 || tmp23 || tmp24 || tmp25 || tmp26 || tmp27 ||
                    tmp28 || tmp29 || tmp30 || tmp31 || tmp32 || tmp33 ||
                    tmp34 || tmp35 || tmp36 || tmp37 || tmp38 || tmp39 ||
                    tmp40 || tmp41 || tmp42 || tmp43 || tmp44 || tmp45 ||
                    tmp46 || tmp47 || tmp48 || tmp49 || tmp50;*/

END backuptest;

 Error: character string buffer too small