I currently have an issue whereby I cannot reference a table in a linked database within a stored procedure. I get the error message:
ORA-00942: table or view does not exist
Here are the steps I took on the host machine (running oracle 10g) to set up the database link to the remote database (running oracle 11g). The steps are accurate, but some some names have been changed, though they have been kept consistent.
Update tnsnames.ora, adding a new entry:
REMOTE_DB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.10.10.10) (QUEUESIZE = 20) (PORT = 1521) ) (CONNECT_DATA = (SERVICE_NAME = remote_service) ) )
Create database link, as the user who will later be creating and executing the stored procedure:
create database link remote_link connect to "remote_user" identified by "remote_pass" using 'REMOTE_DB';
Prove database link is working by selecting from it:
select id from remote_table@remote_link; id -------------------------------------------------------------------------------- 8ac6eb9b-fcc1-4574-8604-c9fd4412b917 c9e7ee51-2314-4002-a684-7817b181267b cc395a81-56dd-4d68-9bba-fa926dad4fc7 d6b450e0-3f36-411a-ba14-2acc18b9c008
Create stored procedure that depends on working database link:
create or replace PROCEDURE test_remote_db_link AS v_id varchar(50); BEGIN select id into v_id from remote_table@remote_link where id = 'c9e7ee51-2314-4002-a684-7817b181267b'; dbms_output.put_line('v_id : ' || v_id); END test_remote_db_link;
Explode own head after staring at the following error message for over an entire working day:
Error(10,27): PL/SQL: ORA-00942: table or view does not exist
I have tried many things to try to sort this issue out, including:
When creating the database link, not using quotes around the username and password. Link creates fine, but selecting from it gives me this error:
ERROR at line 1: ORA-01017: invalid username/password; logon denied ORA-02063: preceding line from TWS_LINK
Tried various combinations of username and password in upper/lowercase. Received same error as 1.
Tried single quotes instead of double quotes around username and password. Recieved this error:
ERROR at line 1: ORA-00987: missing or invalid username(s)
Proved I have full access to the remote db by connecting into it with sqlplus:
[oracle]$ sqlplus remote_user/remote_pass@REMOTE_DB SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 20 22:23:12 2011 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
I'm not sure what to do next. The possible next step is to start looking at issues on the remote database, and perhaps see if other databases can connect to it. Another would be to look at incompatibilities going from host 10g to remote 11g.