https://www.cndba.cn/dave/article/225https://www.cndba.cn/dave/article/225

1    说明

在Oracle 12c中,Oracle 建议使用catcon.pl 脚本来执行SQL 脚本和SQL 语句,其可以在root 和指定的PDB中执行。 Catcon.pl脚本是一个perl 脚本,需要在操作系统中执行。

在执行脚本时可以指定-c 参数指定特定的container,如果没有指定,默认对所有container有效。 脚本在$ORACLE_HOME/rdbms/admin目录下。

[oracle@cndba admin]$ pwd

/u01/app/oracle/product/12.1.0/db_1/rdbms/admin[oracle@cndba admin]$ ll catcon.pl

-rw-r--r--. 1 oracle oinstall 13220 Jun 14  2014 catcon.pl[oracle@cndba admin]$[oracle@cndba admin]$ $ORACLE_HOME/perl/bin/perl catcon.pl

Usage: catcon  [-u username[/password]] [-U username[/password]]                 [-d directory] [-l directory]                 [{-c|-C} container] [-p degree-of-parallelism]                 [-z EZConnect strings]                 [-e] [-s]                 [-E { ON | errorlogging-table-other-than-SPERRORLOG } ]                 [-I]                 [-g]                 [-f]                 [-r]

-b log-file-name-base

--

{ sqlplus-script [arguments] | --x } ...

Optional:

-u username (optional /password; otherwise prompts for password)

used to connect to the database to run user-supplied scripts or

SQL statements

defaults to "/ as sysdba"

-U username (optional /password; otherwise prompts for password)

used to connect to the database to perform internal tasks

defaults to "/ as sysdba"

-d directory containing the file to be run

-l directory to use for spool log files

-c container(s) in which to run sqlplus scripts, i.e. skip all

Containers not named here; for example,

-c 'PDB1 PDB2',

-C container(s) in which NOT to run sqlplus scripts, i.e. skip all

Containers named here; for example,

-C 'CDB$ROOT PDB3'

NOTE: -c and -C are mutually exclusive

-p expected number of concurrent invocations of this script on a given

host

NOTE: this parameter rarely needs to be specified

-z blank-separated EZConnect strings corresponding to RAC instances

which can be used to run scripts

-e sets echo on while running sqlplus scripts

-s output of running every script will be spooled into a file whose name

will be

__[].

-E sets errorlogging on; if ON is specified, default error logging table

will be used, otherwise, specified error logging table (which must

have been created in every Container) will be used

-I do not issue set Errorlogging Identifier (ostensibly because the

caller already did it and does not want us to override it)

-g turns on production of debugging info while running this script

-f instructs catcon to ignore PDBs which are closed or, if -c or -C was

used, do not exist and process existing PDBs which were specified

(explicitly or implicitly) and are open

NOTE: if this flag is not specified and some specified PDBs do not

exist or are not open, an error will be returned and none of

the Containers will be processed.

-r causes scripts to be run in all PDBs and then in the Root (reverse

of the default order); required for running catdwgrd.sql in a CDB

Mandatory:

-b base name (e.g. catcon_test) for log and spool file names

sqlplus-script - sqlplus script to run OR

SQL-statement  - a statement to execute

NOTES:

- if --x is the first non-option string, it needs to be

preceeded with -- to avoid confusing module parsing options into

assuming that '-' is an option which that module is not expecting and

about which it will complain

- command line parameters to SQL scripts can be introduced using --p

interactive (or secret) parameters to SQL scripts can be introduced

using --P

For example,

perl catcon.pl ... x.sql '--pJohn' '--PEnter Password for John:' ...

2    使用示例

2.1     在CDB中所有的Containers中执行catblock.sql脚本https://www.cndba.cn/dave/article/225

[oracle@cndba admin]$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS -d $ORACLE_HOME/rdbms/admin -b catblock_output catblock.sql

catcon: ALL catcon-related output will be written to catblock_output_catcon_24939.lst

catcon: See catblock_output*.log files for output generated by scripts

catcon: See catblock_output_*.lst files for spool files, if any

Enter Password:

catcon.pl: completed successfully[oracle@cndba admin]$

相关参数说明:

-u:指定每个container中执行命令的用户。

-d:指定执行脚本的目录。

-b:指定输出log文件的名称。

我们这里没有指定-c,所以会在所有的container中执行,如果有PDB 没有open,那么就会报错。

2.2     在指定的PDB中执行catblock.sql脚本

https://www.cndba.cn/dave/article/225

SQL> show pdbs

CON_ID CON_NAME              OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

2 PDB$SEED              READ ONLY  NO

3 PDB1               READ WRITE NO

4 IM                  READ WRITE NO

SQL>[oracle@cndba ~]$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS -U SYS -d $ORACLE_HOME/rdbms/admin -l '/tmp' -c 'IM' -b catblock_output catblock.sql

catcon: ALL catcon-related output will be written to /tmp/catblock_output_catcon_25194.lst

catcon: See /tmp/catblock_output*.log files for output generated by scripts

catcon: See /tmp/catblock_output_*.lst files for spool files, if any

Enter Password:

Enter Password:

catcon.pl: completed successfully[oracle@cndba ~]$

除了上节讲的参数之外,这里还多了3个参数:

-U: 指定执行内部任务的用户。

-l:指定输出日志文件的目录。

-c:指定在哪些PDB上执行脚本。

2.3     在CDB中除了指定的PDB之外的container上执行catblock.sql脚本

SQL> show pdbs

CON_ID CON_NAME              OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

2 PDB$SEED              READ ONLY  NO

3 PDB1               READ WRITE NO

4 IM                  READ WRITE NO[oracle@cndba ~]$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS -d $ORACLE_HOME/rdbms/admin -l '/tmp' -C 'IM' -b catblock_output catblock.sql

catcon: ALL catcon-related output will be written to /tmp/catblock_output_catcon_25305.lst

catcon: See /tmp/catblock_output*.log files for output generated by scripts

catcon: See /tmp/catblock_output_*.lst files for spool files, if any

Enter Password:

catcon.pl: completed successfully[oracle@cndba ~]$

这里只有一个新参数:

-C:表示除了这个PDB,在其他的PDB上执行。

2.4     执行带有命令行参数的SQL 脚本

https://www.cndba.cn/dave/article/225https://www.cndba.cn/dave/article/225

$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS -d /u01/scripts -b custom_script_output custom_script.sql '--phr' '--PEnter password for user hr:'

参数说明如下:

The --p parameter specifies hr for a command line parameter

The --P parameter specifies an interactive parameter that prompts for the password of user hr.

2.5     在CDB的所有Container中执行SQL 语句

https://www.cndba.cn/dave/article/225

[oracle@cndba ~]$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u SYS -e -b select_output -- --x'SELECT * FROM DUAL'

catcon: ALL catcon-related output will be written to select_output_catcon_25562.lst

catcon: See select_output*.log files for output generated by scripts

catcon: See select_output_*.lst files for spool files, if any

Enter Password:

catcon.pl: completed successfully

--查看生成的log:https://www.cndba.cn/dave/article/225

[oracle@cndba ~]$ ls

20831110                   custom_script_output2.log               Desktop                               Public

awrrpt_1_93_94_2.html      custom_script_output3.log               Documents                             select_output0.log

awrrpt_1_93_94.html        custom_script_output_catcon_25434.lst   Downloads                             select_output1.log

awrrpt_1_95_96.html        custom_script_output_catcon_25482.lst   Music                                 select_output2.log

awrrpt_1_96_97.html        custom_script_output_catcon_25507.done  p20831110_121020_Linux-x86-64_db.zip  select_output3.log

cndba.dmp                  custom_script_output_catcon_25508.done  p6880880_121010_Linux-x86-64.zip      select_output_catcon_25562.lst

custom_script_output0.log  custom_script_output_catcon_25509.done  PatchSearch.xml                       Templates

custom_script_output1.log  custom_script_output_catcon_25510.done  Pictures                              Videos[oracle@cndba ~]$ cat select_output0.log

SQL*Plus: Release 12.1.0.2.0 Production on Sat Nov 7 06:00:36 2015

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

SQL> Connected.

SQL>   2

Session altered.

SQL>   2

Session altered.

SQL> SQL>   2

Session altered.

SQL>   2

Session altered.

SQL> SQL>

SQL>   2

Session altered.

SQL>

NOW_CONNECTED_TO

--------------------------------------------------------------------------------

==== Current Container = CDB$ROOT Id = 1 ====

SQL>

NOW_CONNECTED_TO

--------------------------------------------------------------------------------

==== Current Container = CDB$ROOT Id = 1 ====

SQL>   2

Session altered.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL>   2

CATCONSECTION

--------------------------

==== CATCON EXEC ROOT ====

SQL>

BEGIN_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:CDB$ROOT Id:1 15-11-07 06:00:37 Proc:0 ====

SQL>

BEGIN_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:CDB$ROOT Id:1 15-11-07 06:00:37 Proc:0 ====

SQL>   2

Session altered.

SQL>   2

Session altered.

SQL>   2

D

-

X

SQL>

END_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:CDB$ROOT Id:1 15-11-07 06:00:37 Proc:0 ====

SQL>

END_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:CDB$ROOT Id:1 15-11-07 06:00:37 Proc:0 ====

SQL> SQL>

SQL>   2

Session altered.

SQL> SQL>

SQL>   2

Session altered.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL>   2

Session altered.

SQL>

NOW_CONNECTED_TO

--------------------------------------------------------------------------------

==== Current Container = PDB$SEED Id = 2 ====

SQL>

NOW_CONNECTED_TO

--------------------------------------------------------------------------------

==== Current Container = PDB$SEED Id = 2 ====

SQL> SQL>   2

CATCONSECTION

-----------------------------------

==== CATCON EXEC IN CONTAINERS ====

SQL>

BEGIN_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:PDB$SEED Id:2 15-11-07 06:00:38 Proc:0 ====

SQL>

BEGIN_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:PDB$SEED Id:2 15-11-07 06:00:38 Proc:0 ====

SQL>   2

Session altered.

SQL>   2

Session altered.

SQL>   2

D

-

X

SQL>

END_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:PDB$SEED Id:2 15-11-07 06:00:38 Proc:0 ====

SQL>

END_RUNNING

--------------------------------------------------------------------------------

==== SELECT * FROM DUAL Container:PDB$SEED Id:2 15-11-07 06:00:38 Proc:0 ====

SQL> SQL>

SQL>   2

Session altered.

SQL> SQL>

SQL> ========== PROCESS ENDED ==========

SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options[oracle@cndba ~]$

https://www.cndba.cn/dave/article/225

版权声明:本文为博主原创文章,未经博主允许不得转载。

oracle里面cat,Oracle 12c 中推荐使用 catcon.pl 执行SQL脚本相关推荐

  1. Oracle 在Sqlplus 执行sql脚本文件。

    首先在随便1个地方建立1个sql语句的文件. 例如: 执行命令为: sqlplus loginID/passwd@serverIP/servcie_name @path/file.name 例如: 见 ...

  2. 云服务器怎么执行sql文件在哪里,总结帝国CMS下在PHP文件中怎么调用数据库类执行SQL语句实例...

    总结帝国CMS下在PHP文件中怎么调用数据库类执行SQL语句实例 发布时间:2020-10-19 14:58:08 来源:亿速云 阅读:83 作者:小新 这篇文章将为大家详细讲解有关总结帝国CMS下在 ...

  3. Delphi 7 在程序中直接执行SQL脚本文件

    Delphi 7 在程序中直接执行SQL脚本文件 在处理MSDE一些操作中.需要执行一些SQL脚本.有的是从 SQLServer 2000中生成的SQL为后缀的脚本.在MSDE中没有企业管理器, 操作 ...

  4. 如何在mysql中执行sql脚本文件

    一.sql脚本文件 简介 xxxx.sql这种文件被称为sql脚本文件. sql脚本文件中编写了大量的sql语句. 我们执行sql脚本文件的时候,该文件中所有的sql语句会全部执行! 批量的执行SQL ...

  5. 标题IDEA中执行SQL脚本

    IDEA中执行SQL脚本 一.下载Database插件 二.使用步骤 一.下载Database插件 插件Database详细使用: Database使用 二.使用步骤 直接在选择要执行的脚本右击执行 ...

  6. sql 后台运行远程服务器,在SQLServer中通过.NET远程的执行SQL文件

    在项目开发过程中,操作数据库的过程中经常会遇到对表结构.存储过程等进行修改,这时一般的操作都是通过直接在SQL Server中的企业管理器进行操作,或者查询分析器里来执行相关的语句,而我们在实际应用中 ...

  7. oracle 在此 select 语句中缺少 into 子句,Go database/sql文档

    No.1 文档概要 在Golang中使用SQL或类似SQL的数据库的惯用方法是通过 database/sql 包操作.它为面向行的数据库提供了轻量级的接口.这篇文章是关于如何使用它,最常见的参考. 为 ...

  8. python执行oracle的sql语句_在oracledb中执行SQL脚本一次执行一条语句

    假设我有一个sql脚本,如下所示:--split statement 1 ALTER TABLE abs ADD (make VARCHAR2(2 byte), model varCHAR2(12 B ...

  9. sqlplus中批量执行sql脚本(Oracle)

    假如我们有很多sql脚本,如果一个一个sql脚本文件执行显然过于麻烦,下边我们演示sql脚本批量执行. 解决方法:将需要执行的sql脚本文件的@绝对路径 存放到一个脚本文件中,然后执行这个脚本文件就可 ...

最新文章

  1. 独立开发人员的自由之路 ——1
  2. leetcode24. 两两交换链表中的节点(思路+解析)
  3. 第六节:又一种新的数据类型:元组Tuple
  4. Qt工作笔记-可拖动大小的QListWidget(自定义控件方式)
  5. Centos安装php高版本
  6. Mac的shell命令大全
  7. sql语句练习50题(Mysql版)
  8. 高斯光束及其MATLAB仿真
  9. 前端原生开发解决方案
  10. 2 spss 统计绘图与线性回归
  11. Web.xml 错误或异常页面配置
  12. 【点击复制 并自动打开微信添加好友】h5点击复制微信号并自动打开微信添加好友
  13. 什么是世界协调时间UTC
  14. Java实现IP库归属地查询
  15. Netlogon 特权提升漏洞(CVE-2020-1472)原理分析与验证
  16. 记一次:9i数据库,/home目录满,tossing监控出问题,导致脑裂
  17. 2019第十届蓝桥杯省赛总结
  18. 跨专业考计算机哪个专业好考吗,考研常识:跨专业考研好考专业?
  19. C/C++编程:回车符和换行符
  20. 服务器操作系统tco的英文全称,云服务器ECS的英文全称

热门文章

  1. Django开发个人博客网站——19、通过Django Haystack实现搜索功能(上)
  2. 老男孩教育Linux运维培训32期决心书
  3. 摩尔斯电码转换python编码_摩尔斯电码到英文python3
  4. Node.js 前世今生
  5. Windows Server 2008 R2安装openSSH服务
  6. 教你怎么在电脑上玩《代号:Ace》手游,《代号:Ace》二次元吃鸡手游电脑版教程
  7. 帝国CMS仿hao123漫画网站模板动态版
  8. 告诉你怎样选择虚拟主机!
  9. 计算机与数学文化论文参考文献,数学文化论文,关于高中数学教学中数学文化相关参考文献资料-免费论文范文...
  10. 企业绩效评价体系的四大层次