set echo off feedback off verify off pagesize 0 linesize 120

---变量从 sqlplus 的 call代码 传递过来 。

-- 1 表示连接用户

-- 2表示连接用户密码

-- 3表示连接字符串

---4表示授权用户

define v_input_un         = &1 
define v_input_pw         = &2
define v_input_conn_str   = &3
define v_input_owner      = &4

connect &v_input_un/&v_input_pw@&v_input_conn_str

define v_create_syn_command_file = .\log\create_syn_&v_input_un._&v_input_owner..sql
define v_create_syn_log_file     = .\log\create_syn_&v_input_un._&v_input_owner..log

-- not exists 就是判断语句,如果没有子条件数据返回,就继续查询。

spool &v_create_syn_command_file.
prompt spool &v_create_syn_log_file.
prompt set echo on feedback on
prompt show user
select
  'create or replace synonym '|| o.object_name ||' for &v_input_owner..'||o.object_name||';'
from     all_objects o
where    o.owner =  upper('&v_input_owner')
and      user    != upper('&v_input_owner')
and      o.object_type in ('TABLE', 'VIEW', 'SEQUENCE', 'PACKAGE', 'PROCEDURE', 'FUNCTION')
and      not exists
  (select null
   from   user_synonyms s
   where  s.table_owner = o.owner
   and    s.table_name  = o.object_name)
order by o.object_name
/
select
  'create or replace synonym '|| a_s.synonym_name ||' for &v_input_owner..'||a_s.synonym_name||';'
from     all_synonyms a_s
where    a_s.owner =  upper('&v_input_owner')
and      user      != upper('&v_input_owner')
and      not exists
  (select null
   from   user_synonyms u_s
   where  u_s.table_owner = a_s.owner
   and    u_s.table_name  = a_s.synonym_name)
order by a_s.synonym_name
/
prompt spool off
spool off

@&v_create_syn_command_file.

gen_create_syn.sql的更多相关文章

  1. call_create_syn.sql

    promptprompt ================================================================================prompt ...

  2. 最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目

    最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目 最近一个来自重庆的客户找到走起君,客户的业务是做移动互联网支付,是微信支付收单渠道合作伙伴,数据库里存储的是支付流水和交易流水 ...

  3. SQL Server 大数据搬迁之文件组备份还原实战

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...

  4. Sql Server系列:分区表操作

    1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...

  5. SQL Server中的高可用性(2)----文件与文件组

        在谈到SQL Server的高可用性之前,我们首先要谈一谈单实例的高可用性.在单实例的高可用性中,不可忽略的就是文件和文件组的高可用性.SQL Server允许在某些文件损坏或离线的情况下,允 ...

  6. EntityFramework Core Raw SQL

    前言 本节我们来讲讲EF Core中的原始查询,目前在项目中对于简单的查询直接通过EF就可以解决,但是涉及到多表查询时为了一步到位就采用了原始查询的方式进行.下面我们一起来看看. EntityFram ...

  7. 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)

    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...

  8. 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)

    从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...

  9. 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)

    从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...

随机推荐

  1. Android 中OKHttp请求数据get和post

    1:在Android Studio 的 build.gradle下  添加 然后再同步一下 compile 'com.squareup.okhttp:okhttp:2.4.0'compile 'com ...

  2. 浅谈h5移动端页面的适配问题

    一.前言 昨天唠叨了哈没用的,今天说点有用的把.先说一下响应式布局吧,我一直认为响应式布局的分项目,一下布局简单得项目做响应式还是可以可以得.例如博客.后台管理系统等.但是有些会认为响应式很牛逼,尤其 ...

  3. Centos sudo添加用户

    $ su - # vi /etc/sudoers 在root ALL=(ALL) ALL下 添加 username ALL=(ALL) ALL 输入wq!强制保存.

  4. how to stop a thread

    it seems all stop methods of thread have been deprecated by java. so how to stop a thread then? it i ...

  5. mysql日志详细解析【转载】

    转自:http://pangge.blog.51cto.com/6013757/1319304 MySQL日志: 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志: 日志是mysql数据 ...

  6. Qt之中文显示(QMessageBox、QLineEdit右键菜单等)

    来源:http://blog.sina.com.cn/s/blog_a6fb6cc90101art3.html 在编写Qt程序的时候,总会碰到中文问题,一直都很困惑,原本在使用QLineEdit的时候 ...

  7. C#判断文字是否为汉字

    /// <summary> /// 检测一个字符串是不是以汉字开始 /// </summary> /// <param name="str">要 ...

  8. 一篇非常适合git入门的文章

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579 ...

  9. plsql 安装后database下拉没有东西

    今天第一天上班我自己也有点紧张,但是问题还是有的: 今天来说一下问题,就是装了plsql竟然在database这一栏没有东西,我也是纠结了很久,感觉今天的任务也被拉下了. 其实这个问题在我以前装的时候 ...

  10. 格式化格林威治时间(Wed Aug 01 00:00:00 CST 2012)

    1.如果格林威治时间时间是date类型.(这种格式最简单)       SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd") ...