暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 一次执行多个DDL语句

askTom 2016-09-12
730

问题描述

嗨,汤姆,

我需要你在这方面的专业知识。
我正在使用一个自行编程的版本控制系统来升级我的客户系统。
在它中,所有带有包、函数、DDL命令、DML命令的变更集都保存在数据库中的BLOB中。

为了更新我的客户,所有这些文件和命令都是写在一个包含所有内容的大sql文件中。
其中有创建语句、插入语句、更新语句、更改表...等等。

作为下一步,我将在客户系统上的SQL-plus中执行此文件。
它工作的很好,但我正在寻找一个更好的方法与更多的控制和日志。

因此,我正在测试如何动态执行多个ddl语句和所有这些源。

我举了一些例子,这些源被存储:

例如,我的dbupdaes是这样存储的
(作为一个文件存储在包含多个ddl语句的blob中):
-- Create table
create table T605SCFG
(
  betart         NUMBER(6) not null,
  core_lang      VARCHAR2(4) default 'DE' not null,
  hostname       VARCHAR2(100) not null,
  portnumber     NUMBER(6) default 17000 not null,
  core_name      VARCHAR2(30) not null,
  core_repl_name VARCHAR2(40) not null
);

-- Add comments to the table 
comment on table T605SCFG
  is 'Konfiguration für SOLR';
-- Add comments to the columns 
comment on column T605SCFG.betart
  is 'Mandantnummer des Artikelstamms';

-- Create/Recreate primary, unique and foreign key constraints 
alter table T605SCFG
  add constraint T605SCFG_PK primary key (BETART, CORE_LANG);

alter table T605SCFG
  add constraint T605SCFG_UX1 unique (CORE_NAME);


函数、包、过程、...都是一样的

另一个例子是如何存储软件包:

create or replace package shc_ab003_objects is
  
  -- public functions and procedures

  -- einen Positionslauf zurückgeben (auf T087poli basierend)
  function get_t_ab003_poli(pi_manr number
                           ,pi_ainr number
                           ,pi_aufpos number
                           ,pi_lauf number
                           ) return t_ab003_poli;
.
.
.
.
.
.

end shc_ab003_objects;
/
create or replace package body shc_ab003_objects is

  -- Cursor-Getter für T_AB003_POLI
  procedure get_t_ab003_poli_cursor(po_cursor out sys_refcursor
                                   ,pi_manr in number
                                   ,pi_ainr in number
                                   ,pi_aufpos in number
                                   ,pi_lauf in number default 0
                                   ) is
  v_lauf number := nvl(pi_lauf, 0);
  begin
  open po_cursor for
     select t_ab003_poli(t1.manr, t1.ainr, t1.lauf, t1.aufpos, t1.menge
                        ,t1.stat, t1.fstat, t1.diffvw, t1.diffew, t1.vkpr         
                        ,t1.eipr, t1.raba, t1.arnr, t1.kdnr, t1.fr5
                        ,decode(t2.mwco, null, 0, t2.mwco), t1.baspr
                        )
       from t087poli t1
       left outer join t387poli_zusi t2 on (t2.manr = t1.manr and t2.ainr = t1.ainr and t2.aufpos = t1.aufpos and t2.lauf = t1.lauf)
      where 1=1
        and t1.manr = pi_manr
        and t1.ainr = pi_ainr
        and t1.aufpos = pi_aufpos
        and (v_lauf = 0 or v_lauf = t1.lauf)
      order by t1.lauf
      ;    
  end;
  
.
.
.
.
.
.
.
  
begin
  -- Initialisierung
  null;
  
end shc_ab003_objects;
/




现在,我正在寻找一种方法,在相同的结构中执行它们。

也许有一个方法与执行立即或一个dbms包或其他任何我不知道...

谢谢你的帮助!

专家解答

所以...您希望将DDL存储在表中。然后使用自创脚本来构建这些安装?

请。别这样!

执行起来很棘手。但更重要的是这是一场安全噩梦!确保人们只运行有效的更改而不是邪恶的东西是困难的。

只需使用常规文本文件来存储DDL更改。然后使用git或SVN对这些进行源代码管理。如果您使用的是SQL Developer ,那么它内置了对它们的支持!

http://www.thatjeffsmith.com/archive/2014/06/managing-scripts-in-oracle-sql-developer/
http://www.thatjeffsmith.com/archive/2012/06/do-you-develop-your-plsql-directly-in-the-database/

有多种解决方案可以帮助您获取源文件并将其转换为安装脚本。

我对这些都没有真正的经验,虽然我听说过很多关于Liquibase的报道:

http://www.liquibase.org/
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论