How to create a table from remote database using dblink

coder11 b

How to create a table from remote database using dblink

create table MYTABLE@DBLINK (name varchar2(20)));

*Cause: An attempt was made to use a DDL operation on a remote database. For example, "CREATE TABLE tablename@remotedbname ...".

*Action: To alter the remote database structure, you must connect to the remote database with the appropriate privileges.

Is this a privilege error or it is not possible to do with dblink?

Littlefoot

If you managed to create a database link, you obviously have that user's credentials so the simplest option is to actually connect as remote user and create table in that schema directly.

If you want to do it from your schema, you can't do it using that syntax, but - there's a workaround: dbms_utility.exec_ddl_statement

Here's an example.

Database link first:

SQL> create database link dbl_mike connect to mike identified by lion using '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = my_server)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XEPDB1)))';

Database link created.

Does it work? Yes!

SQL> select * from dual@dbl_mike;

D
-
X

This is what you tried, and found out that it won't work:

SQL> create table test_dbl@dbl_mike (id number);
create table test_dbl@dbl_mike (id number)
                     *
ERROR at line 1:
ORA-02021: DDL operations are not allowed on a remote database

Workaround I mentioned:

SQL> exec dbms_utility.exec_ddl_statement@dbl_mike('create table test_dbl (id number)');

PL/SQL procedure successfully completed.

Testing (if table exists, I can insert a row over database link and select from that table):

SQL> insert into test_dbl@dbl_mike (id) values (100);

1 row created.

SQL> select * from test_dbl@dbl_mike;

        ID
----------
       100

SQL>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can you do an update to a table in another database using postgres dblink?

dblink from remote server into a Google Cloud SQL instance using .pgpass

How to drop table with dblink

Using ORA_ROWSCN for archiving a table from source to remote database

How to select * from table () referencing a function from dblink

How to create a table in database using jquery

How to create table using oracle database

How to create a table in database using wordpress plugin

Cross database query using dblink

How to create a list view from a database table?

Anylogic: How to create plot from database table?

DBlink error when querying the remote table

How to create a database connection from C# to a remote couchbase databse

How can I create a new table in my SQLite Database using a param from a Java String variable?

How to Create a JSONArray using JSONObject with all values from a database table in java

Is it possible to create an "infinite" stream from a database table using Akka Stream

Insert Data to Oracle DB table from SQL Server Table with dblink with using SQL Server

How to create a Table from lists using ReactJS?

Insert data into remote database table from local database table

How create auto suggestion textbox in c# using DataBase table

how to create a table if it does not exist it database using php?

How to create a new table in database using sapui5?

How to create a new Table in SQLite database from android app

How to create a View from JSON BLOB field in a table in ORACLE Database?

How to create a dynamic TableView in JavaFX from a user selected database table

How to create MVIEW containing dblink in postgresql

how do I create a dblink connection in postgres that I can keep using

django: how to bootstrap/create a database with fabric on the remote server, using django db settings

Using dblink extension from pg-promise