Home Database Mysql Tutorial Oracle DBLink创建和维护以及ORA-02085 解决办法

Oracle DBLink创建和维护以及ORA-02085 解决办法

Jun 07, 2016 pm 03:53 PM
oracle

今天业务需要,要跨库查询Oracle数据,于是想到了dblink, 下面一一细说,Oracle DBLink。

今天业务需要,要跨库查询Oracle数据,于是想到了dblink, 下面一一细说,,Oracle DBLink。

首先Oracle DBLink 分成 如下三种:

创建dblink:

一:创建 public database link 的实例:

create public database link  todb151 

      connect to hezi  identified by manager

      using '(DESCRIPTION =

                (ADDRESS_LIST =

                  (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.4.151)(PORT = 18000))

                )

                (CONNECT_DATA =

                  (SERVICE_NAME = newzqdb)

                )

              )';   
应该注意的是:
1,上面的hezi 这个用户,是你要连接的远程数据库中的用户(也就是 4.151上的)。

2,SQL> select * from pd_zh_cn.tb_goods@todb151;  通过todb151来跨库查询4.151,会拥有hezi的查询权限。只要本地的用户拥有数据库访问权限即可,所以尽量不要建public数据库连接,或者不要用大权限用户hezi来创建,以免让本地小权限的用户,去远程4.151查看到了不该看到的信息。

3.using 后面的引号中间的内容实际上就有  本地tnsname.ora 中的相应数据库连接信息。所以这里也可以直接改写成:
create public database link  todb151 

      connect to hezi  identified by manager

      using 'db151' ;                     

前提是本地tnsname.ora 文件中有:

  db151 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.4.151)(PORT = 18000))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = newzqdb)

    )

  )

其中SERVICE_NAME 一般是下面红字部分,

SQL> show parameter service_names

NAME                                TYPE        VALUE

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

service_names                        string      newzqdb

还要注意要和监听的服务名一致,因为这个远程是要借助监听的。这里明确的告诉大家,配置静态监听注册时,需要输入的全局数据库名(GLOBAL_DBNAME)输入什么都可以,只要保证listerner.ora中的GLOBAL_DBNAME和tnsnames.ora中的SERVICE_NAME保持一致,所以如果是静态监听,那么在创建dblink时应该也应该符合,service_name =listerner.ora中的GLOBAL_DBNAME ,(创建dblink时不一定非得一样)

[oracle@rac1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-JUL-2015 21:39:53

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=newzq.com.cn)(PORT=18000)))
STATUS of the LISTENER
------------------------
Alias                    LISTENER
Version                  TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                01-JUL-2015 20:18:41
Uptime                    0 days 1 hr. 21 min. 12 sec
Trace Level              off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File  /u01/oracle/products/database/11.2.0.1/network/admin/listener.ora
Listener Log File        /u01/oracle/products/diag/tnslsnr/newzq/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=newzq.com.cn)(PORT=18000)))
Services Summary...
Service "newzqdb" has 1 instance(s).
  Instance "newzqdb", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

二:创建 private dblink 实例:注意没有private字眼。

  create database link dblink

        connect to liuwenhe identified by liuwenhe

        using '(DESCRIPTION =

                (ADDRESS_LIST =

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

                )

                (CONNECT_DATA =

                  (SERVICE_NAME = newzqdb)

                )

              )'; 

 管理dblink:                 

在当前数据库下查看所有的DBLINK的方法:

    1. select * from dba_db_links;     

删除当前数据库下的一个指定的DBLINK的方法:

    1. 删除public link 

        drop public database link dblink;

    2. 删除private link 

        drop database link dblink;

ORA-02085 解决办法 :

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

How to import oracle database How to import oracle database Apr 11, 2025 pm 08:06 PM

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

How to view instance name of oracle How to view instance name of oracle Apr 11, 2025 pm 08:18 PM

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

How to uninstall Oracle installation failed How to uninstall Oracle installation failed Apr 11, 2025 pm 08:24 PM

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

How to get time in oracle How to get time in oracle Apr 11, 2025 pm 08:09 PM

There are the following methods to get time in Oracle: CURRENT_TIMESTAMP: Returns the current system time, accurate to seconds. SYSTIMESTAMP: More accurate than CURRENT_TIMESTAMP, to nanoseconds. SYSDATE: Returns the current system date, excluding the time part. TO_CHAR(SYSDATE, 'YYY-MM-DD HH24:MI:SS'): Converts the current system date and time to a specific format. EXTRACT: Extracts a specific part from a time value, such as a year, month, or hour.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to read the oracle awr report How to read the oracle awr report Apr 11, 2025 pm 09:45 PM

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.

See all articles