zoukankan      html  css  js  c++  java
  • Orcale数据库管理员用户创建dblink和同义词的方法 —— 数据库学习

    创建dblink总结:

    两个库/表空间(在不在同一台服务器上都一样)其中databaseA库想访问databaseB库的数据信息时,就需要创建dblink

    第一步:先得用数据库管理员身份给databaseA的用户(此处假设为:test)赋予创建dblink的权限:

    sqlplus / as sysdba(回车)

    grant create database link to test;

    解释:
    grant create database link to user ; --只有user用户能使用的dblink
    grant create public database link to user ;--所有用户都可以使用的dblink
    grant drop public database link to user; --删除dblink的权限

    第二步:使用plsql登录databaseA数据库,并在plsql 执行以下语句

    执行时注意以下几点:

    1. dblinkName:dblink的名字

    2. databaseB_user:被访问库的用户名

    3. passward:被访问库的用户名对应的密码

    4. '(DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))

    (CONNECT_DATA =(SERVICE_NAME = ORCL)))'

    这是一段配置,内容是:HOST = 127.0.0.1 远程数据库的地址(我是link的本地的另一个表空间),PORT = 1521 远程数据库的端口号,一般默认都是1521

    SERVICE_NAME = ORCL 是远程数据库的服务号

    create database link dblinkName connect to databaseB_user identified by passward
    using '(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = ORCL)
    )
    )';

    执行成功后可以使用 select * from baseB_table1@dblinkName; 可以查询出数据(baseB_table1 是databaseB库的表)

    同义词:

    我理解为方便databaseA的查询,所以将表名重命名 如果根本库不冲突可以命名为跟databaseB库相同的表名:

    首先为用户赋予创建同义词的权限 

      sqlplus / as sysdba(回车)

      grant create synonym to user;  --A库的用户名

    sql语句:使用plsql登录databaseA,在SQL窗口执行以下语句

    create or replace synonym 同义词名
      for 远程库用户.远程库表名@dblink名;
    create or replace synonym baseB_table1
      for databaseB_user.baseB_table1@dblinkName;

    create or replace synonym baseB_table2 for databaseB_user.baseB_table2@dblinkName;

    执行成功后可以使用 select * FROM baseB_table1 可以查询出数据(baseB_table1是databaseB库的表)

  • 相关阅读:
    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
    如何从vss中分离程序
    String or binary data would be truncated
    the pop3 service failed to retrieve authentication type and cannot continue
    The POP3 service failed to start because
    IIS Error he system cannot find the file specified _找不到页面
    pku2575Jolly Jumpers
    pku2940Wine Trading in Gergovia
    pku3219二项式系数
    pku1029false coin
  • 原文地址:https://www.cnblogs.com/EtherealWind/p/11132909.html
Copyright © 2011-2022 走看看