How do I execute "use dbname" over Oracle dblink to Sybase? - oracle

How do I access tables in my user schema in Sybase from Oracle?
In isql I can do
use mydb
go
How do I select from mydb tables from Oracle using dblink NITSYB5?
This does not work:
select count(*) from "mydb"."lon_client_confirm_exec"#NITSYB5;
Error:
ORA-00942: table or view does not exist
[Oracle][ODBC Sybase Wire Protocol driver][SQL Server]"mydb"."lon_client_confirm_exec" not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
{42S02,NativeErr = 208}
ORA-02063: preceding 3 lines from NITSYB5
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 3 Column: 30

NOTE: I don't work with Oracle and hence know nothing about Oracle's dblink, so fwiw ...
In Sybase ASE the fully qualified table name format is: <dbname>.<owner>.<table>
If you leave out the <owner> then the optimizer will first look for tables owned by the user running the query, then look for tables owned by dbo.
In your example it appears you've left out the <owner>. If the table is owned by your user or dbo then I'd suggest you try adding an additional period, eg:
select count(*) from mydb..lon_client_confirm_exec#NITSYB5;
NOTE: Add quotes as/if needed by Oracle's dblink.

SERVER 1 AND SERVER 2
open SSH server2 telnet server 1 host, its ok to done
su oracle
1) cd $ORACLE_HOME/bin
2) TNSPING database1 name
its ok done
create public database link
LINK_NAME
connect to
DB1USERNAME
identified by
111
using 'DB1NAME';
select * from dual#LINK_NAME, result x, finish.

Related

Informix - select from a table of another user

I have to do CRUD operations on a table that is not owned by the user I am using to connect to my Informix database. I have been granted the necessary privileges to do the operations, but I do not know how to do the actual query.
I have little experience with Informix, but I remember in OracleDB I had to do reference the shema like so:
SELECT * FROM SCHEMA.TABLE;
In Informix should I reference the user that owns the table ? Like :
SELECT * FROM OWNER:TABLE
Or can I just do :
SELECT * FROM TABLE
Thanks for any help !
In Informix you can generally use the table name without or without the owner prefix unless the database was created with mode ANSI in which case the owner prefix is required. Note that the correct syntax when using the owner is to use a period "." as in:
SELECT * FROM owner.table;
The colon is used to separate the database name as shown in the Informix Guide to SQL: Syntax https://www.ibm.com/docs/en/informix-servers/14.10?topic=segments-database-object-name#ids_sqs_1649
FYI you can determine if the database is mode ANSI with this query:
SELECT is_ansi FROM sysmaster:sysdatabases WHERE name = "<database name>";

In Oracle 11g, what permissions would I need to `SELECT * FROM V$TRANSPORTABLE_PLATFORM;`?

I am using AWS DMS to migrate an on-site Oracle 11g database to an Amazon RDS for Oracle DB instance of the same major version. I recently received this error:
2019-11-27T18:54:08 [SOURCE_CAPTURE ]E: Cannot execute SQL statement 'select tp.endian_format, tp.platform_name from v$database d, v$transportable_platform tp where d.platform_id = tp.platform_id'. OCI status '-1' [1020401] (oradcdc_redoutil.c:976)
2019-11-27T18:54:08 [TASK_MANAGER ]E: OCI error 'ORA-00942: table or view does not exist'; Cannot execute SQL statement 'select tp.endian_format, tp.platform_name from v$database d, v$transportable_platform tp where d.platform_id = tp.platform_id'. OCI status '-1'; Error executing source loop; Stream component failed at subtask 0, component st_0_XGQVEPQ6RSAXZT44XOZF7ERABI ; Stream component 's
My normal administrative schema can SELECT * FROM V$TRANSPORTABLE_PLATFORM; without issue, however, my new 'migration' schema cannot. Both have SELECT ANY TABLE privileges which, as described in Grant Select on All VIEWS [current and future] in Schema X, will allow the user to query any table or view in any schema in the database.
What permission am I missing in my migration schema? How does V$TRANSPORTABLE_PLATFORM differ from table/view objects in the database? What query could I run in order to obtain the type of V$TRANSPORTABLE_PLATFORM or any other database object?
A few things you may want to try:
Grant SELECT_CATALOG_ROLE to allow SELECT on system views
Add a manual GRANT to V_$TRANSPORTABLE_PLATFORM since V$TRANSPORTABLE_PLATFORM will reference that table
Ensure the schema is not ambiguous by adding SYS.

Oracle XE not seeing tables with names longer than 14 chars

I have an Oracle XE database link to a MySQL 5.7 instance. The link is working fine as I am able to do lookups like:
select count(*) from "wp_mal_mast"#MYSQl1;
However, when I try to do this for tables with a name greater than 14 characters, it fails with an error:
select count(*) from "123456789012345"#MYSQL1;
ORA-28511: lost RPC connection to heterogeneous remote agent using SID=ORA-28511: lost RPC connection to heterogeneous remote agent using SID=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=MYSQL1)))
But, if I select anything up to 14 chars, even non-existing, I get a normal response:
select count(*) from "12345678901234"#MYSQL1;
ORA-00942: table or view does not exist
[MySQL][ODBC 5.1 Driver][mysqld-5.7.19-log]Table 'blah.12345678901234' doesn't exist {42S02,NativeErr = 1146}
Here is my init[SID].
initMYSQL1.ora
HS_FDS_CONNECT_INFO=MYSQL1
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_SHAREABLE_NAME=/usr/lib64/libmyodbc5.so
set ODBCINI=/u01/app/oracle/product/11.2.0/xe/odbc.ini

Running query cannot connect to vendort's database, even dblink exists

I have a simple query, which I run on sqldeveloper on put database, but it select data from different vendor database. We have db_link created. but I run, as in my Pro C program:
select some_files from mytable trd, vendordbname.vendortable
where(condition)
and I get an error:
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 25 Column:
What kind of solution I have to find, to make it run? Use dblink name? or something else? I will appreciate any possible help
Thanks
ok, when it runs with Pro C, everything sets up on UNIX and sqlplus.
When I run it from sqldeveloper I have to add the vendor host name
select some_files from mytable trd, vendordbname.vendortable#vendorhost
where(condition)

ORA-00980 synonym translation no longer valid in PLSQL

I've got a synonym on a remote Oracle database that I can access in SQL over a database link, eg,
insert into my_table select * from my_synonym#my_database_link;
If I put the above statement into a PLSQL block, it won't compile, giving the error message "ORA-00980: synonym translation is no longer valid". The standard explanation is the table that the synonym points to has been dropped, etc, but this is not the case because the statement works in SQL.
If something works in SQL but not in PL/SQL then in most cases this is a problem with privileges.
Any privilege that a user received through a role is not active when you enter a PL/SQL block. So most probably the SELECT privilege on the underlying table was granted through a role and thus is not "active" in the PL/SQL block.
The usual cure for this is to grant the privileges directly to the user, not through a role.
Thank you to everyone who tried to help. This turned out to be an Oracle limitation:
https://support.oracle.com/rs?type=doc&id=453754.1
APPLIES TO:
PL/SQL - Version 9.2.0.8 and later Information in this document
applies to any platform.
Checked for relevance on 01-Apr-2015
SYMPTOMS
A PL/SQL block fails with error: ORA-00980: synonym translation is no
longer valid, when selecting data from a remote database. The
following code demonstrates this issue:
On DB3 (create the table)
CONNECT u3/u3 DROP TABLE tab; CREATE TABLE tab(c1 number); INSERT
INTO tab VALUES (1); COMMIT;
On DB2 (create a synonym to the table on DB3)
CONNECT u2/u2 DROP DATABASE LINK dblink2; CREATE DATABASE LINK
dblink2 CONNECT TO u3 IDENTIFIED BY u3 USING 'EMT102U6'; SELECT *
FROM global_name#dblink2; DROP SYNONYM syn2; CREATE SYNONYM syn2
FOR tab#dblink2; SELECT * FROM syn2;
On DB1 (create a synonym to the synonym on DB2)
CONNECT u1/u1 DROP DATABASE LINK dblink1; CREATE DATABASE LINK
dblink1 CONNECT TO u2 IDENTIFIED BY u2 USING 'EMT102W6'; SELECT *
FROM global_name#dblink1; DROP SYNONYM syn1; CREATE SYNONYM syn1
FOR syn2#dblink1; SELECT c1 from syn1;
This works in SQL but fails when called from PL/SQL
DECLARE num NUMBER; BEGIN SELECT c1 INTO num FROM syn1; END;
/
ERROR at line 4: ORA-06550: line 4, column 3: PL/SQL: ORA-00980:
synonym translation is no longer valid ORA-06550: line 4, column 3:
PL/SQL: SQL Statement ignored
CAUSE
This issue was reported in Bug 2829591 QUERING FROM A PL/SQL
PROCEDURE IN 9I -> 8I-> 7.3.4, GETTING ORA-980. This bug was closed
as 'NOT A BUG' for the following reasons
PL/SQL cannot instruct middle database (DB2) to follow the database
link during the compilation phase. Therefore in order for this PL/SQL
block to compile and run, both database links dblink1 and dblink2
should be defined on the front end database - DB1. During runtime
database link dblink2 will be looked up in DB2 as expected.
SOLUTION
To implement the solution, please execute the following steps:
Create a database link dblink2 on DB1 pointing to DB3
SQL> create database link dblink2 connect to u3 identified by u3 using
'EMT102U6';
Create and compile the PL/SQL block on DB1.
CREATE DATABASE LINK dblink2 CONNECT TO u3 IDENTIFIED BY u3 USING
'EMT102U6';
SELECT * FROM global_name#dblink2; DECLARE num NUMBER; BEGIN
SELECT c1 INTO num FROM syn1; END; / PL/SQL procedure successfully
completed.
TIP: Another option is to use dyanmic SQL in the PL/SQL block as a
work around. When using dynamic SQL the database link is not resolved
at compile time but at runtime.
Workaround solution is to use an Oracle view instead.
CREATE VIEW v_my_synomym as (select * from my_synonym#my_database_link);
Then reference the view in your package or procedure i.e.:
insert into my_table select * from v_my_synonym;
Check in remote database grants for "my_synonym" must be almost "select" for the user you use in connect string, check also the object which this synonym points at (maybe someone deleted the table).
I found this issue when owner of the table/view/procedure are not match with owner mentioned in SYNONYM.
Example : If owner of table TABLE_BRACH is ownerA and in Synonym mentioned table owner is something else (Not ownerA).
Solution:
1. Drop the SYNONYM
2. Create that with same name with correct owner.
CREATE PUBLIC SYNONYM BRANCH FOR ownerA.TABLE_BRACH ;

Resources