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任务栈TaskStack

    Task:有多个Activity按顺序组成的一个完整的业务逻辑. 任务栈(TaskStack):新增的Activity放入栈中,点击back栈顶Activity从栈中退出. android:nohis ...

  2. OpenVPN客户端解析

    windows版本的VPN客户端,实际上就是一个外壳,创建了图形界面,托盘,和 右键菜单, 在connect的动作里,实际上是通过cmd调用 openvpn.exe openvpn --config ...

  3. spark 编程向导

    http://spark.apache.org/docs/latest/programming-guide.html

  4. 让AutoMapper在你的项目里飞一会儿(转)

    出处:http://www.cnblogs.com/WeiGe/p/3835523.html 先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说 ...

  5. As3.0 类的【枚举】

    As3.0 类的枚举   “枚举”是您创建的一些自定义数据类型,用于封装一小组值.ActionScript 3.0 并不支持具体的枚举工具,这与 C++ 使用 enum 关键字或 Java 使用 En ...

  6. PHP的几个常用加密函数【转载】

    转自 https://jellybool.com/post/php-encrypt-functions 在网站的开发过程中,常常需要对部分数据(如用户密码)进行加密,本文主要介绍PHP的几个常见的加密 ...

  7. Oracle where 0=1 or 1=1

    本文转载自:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html sql where 1=1和 0=1 的作用   where 1 ...

  8. Jenkins环境集成第一弹

    1. 起因 策划经常过来让我打包给他们测试,过于频繁影响到了自己的进度,决定弄一个打包工具让他们自己打包,在网上搜索了一下貌似有几个比较成熟的工具,Travis,Jenkins等等. 在网上也搜索到了 ...

  9. Mishka and Interesting sum

    Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes input ...

  10. bios自检时间长,显示0075错误

    一amibios主板,只有一IDE接口,接一硬盘一光驱,每次启动时,在bios自检界面,在检测完usb设备后,都要等个那么一两分钟,这个时候,可以在屏幕的右下角看到有数字:0075 ,这就是错误代码. ...