ORA-02082: A Loopback Database Link Must Have a Connection Qualifier
ORA-02082 is thrown by Oracle when you attempt to create or use a loopback database link — a link that points back to the same database instance you are currently connected to — without specifying a connection qualifier. Oracle requires a CONNECT TO clause in this scenario to distinguish which user or session the loopback link should authenticate as. Without it, Oracle cannot resolve the ambiguity and raises this error immediately.
Top 3 Causes
1. Creating a Loopback DB Link Without CONNECT TO
The most common cause: a developer or DBA creates a database link targeting the same database without providing credentials.
-- This will raise ORA-02082
CREATE DATABASE LINK my_loopback
USING 'ORCL';
-- Correct approach: always include CONNECT TO for loopback links
CREATE DATABASE LINK my_loopback
CONNECT TO scott IDENTIFIED BY tiger
USING 'ORCL';
-- Verify the link works
SELECT * FROM dual@my_loopback;
2. TNS Entry Points to the Same SID or Service Name
When the TNS alias used in the USING clause resolves to the same database (same SID or service name), Oracle detects a loopback condition. If no connection qualifier is provided, ORA-02082 is raised.
-- First, check your current global name
SELECT * FROM global_name;
-- Check existing DB links for potential loopback conflicts
SELECT owner, db_link, username, host
FROM dba_db_links
ORDER BY owner;
-- Fix: create a separate TNS alias and use CONNECT TO
-- (Add this to tnsnames.ora first)
-- ORCL_LOOP =
-- (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))
-- (CONNECT_DATA=(SERVICE_NAME=ORCL)))
CREATE DATABASE LINK safe_loopback
CONNECT TO hr IDENTIFIED BY hr_pass
USING 'ORCL_LOOP';
3. Misconfigured PUBLIC Database Link
Creating a PUBLIC database link targeting the local database without a connection qualifier also triggers ORA-02082. Public links are accessible to all users, making the qualifier even more critical.
-- Wrong: raises ORA-02082
CREATE PUBLIC DATABASE LINK pub_loop
USING 'ORCL';
-- Correct: include CONNECT TO
CREATE PUBLIC DATABASE LINK pub_loop
CONNECT TO app_user IDENTIFIED BY app_pass
USING 'ORCL';
-- Drop and recreate if already created incorrectly
DROP PUBLIC DATABASE LINK pub_loop;
CREATE PUBLIC DATABASE LINK pub_loop
CONNECT TO app_user IDENTIFIED BY app_pass
USING 'ORCL';
-- Confirm creation
SELECT db_link, username, host
FROM dba_db_links
WHERE db_link = 'PUB_LOOP';
Quick Fix Solutions
-
Always include
CONNECT TOwhen the DB Link target is the same database. - Drop and recreate any incorrectly defined loopback links:
-- Drop the problematic link
DROP DATABASE LINK my_loopback;
-- Recreate with proper connection qualifier
CREATE DATABASE LINK my_loopback
CONNECT TO valid_user IDENTIFIED BY valid_password
USING 'ORCL';
- Audit existing links for missing usernames:
-- Find DB links with no connection qualifier defined
SELECT owner, db_link, host, created
FROM dba_db_links
WHERE username IS NULL
ORDER BY owner, db_link;
Prevention Tips
-
Enforce a naming convention: Prefix all loopback links with
LB_orLOOPBACK_so they are easy to identify and audit regularly. -
Implement a review process: Require DBA approval for all
CREATE DATABASE LINKstatements, and add automated checks in your CI/CD pipeline to flag any DDL that creates a DB link without aCONNECT TOclause.
-- Periodic health check: run this to catch misconfigured links early
SELECT owner, db_link, host, username,
CASE WHEN username IS NULL THEN 'MISSING QUALIFIER' ELSE 'OK' END AS status
FROM dba_db_links
ORDER BY owner, db_link;
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)