Select from one DB and insert in another DB - oracle

I need a sql query in which
Select from DB1 and insert into DB2 in one single query
Example:
DB1
Select username,account_status from dba_users;
DB2
Insert into table User_id

You have to create a database link (this should probably be done by a DBA). Once that is in place, you can select from the other database and write a statement like this:
INSERT INTO MyTable
SELECT * from MyTable#DB2
[Edit]
You can't without a database link.

Related

How to get the table name in trigger on which ddl operation will be performed

I want to do something like
create or replace trigger t1 before ddl on database
begin
insert into table1 values(//the table name on which the ddl will be performed);
end;
so if i create a table named "Hello" than "Hello"(table name) will be inserted in table1
so i don't know how to fetch the table name actually
That's show here in the Database Docs
So you could do something like...
CREATE OR REPLACE TRIGGER ddl_trig
AFTER DDL
ON DATABASE
BEGIN
INSERT INTO loguser.ddl_log
(user_name, ddl_date, ddl_type,
object_type, owner,
object_name)
VALUES
(ora_login_user, SYSDATE, ora_sysevent,
ora_dict_obj_type, ora_dict_obj_owner,
ora_dict_obj_name);
END ddl_trig;
/
BUT, you shouldn't build your own auditing software/code. You should instead use the database's built in auditing system.
See this.
Disclaimer: I work for Oracle and am a product manager on the database team.

Fetch table query in Oracle database for data extraction?

I want Oracle SQL Developer to create a SELECT statement "automatically" for the table that are in databse, I want the table query for extraction and so that I do not have to type for all.
Let me guess: you want SQL Developer to create a SELECT statement "automatically". If so, then drag table into the editor and choose an option:
Result:
SELECT
ename,
job,
sal,
comm
FROM
bonus;

CTE (With table as) in sql server equivalent in hive?

I use WITH table_name AS (select...;) command in SQL Developer to create temporary table and use that temp table in following queries. What is the similar command in Hadoop Hive?
Using SQL assistant User interface on Hadoop Hive.
I tried the following example, which gives error-
Create table Failed,80:
CREATE TEMPORARY TABLE temp1(col1 string);
CREATE TEMPORARY TABLE temp2 AS Select * from table_name;
Maybe you must write case sensitive like this:
CREATE TEMPORARY TABLE temp1(col1 STRING);
The same CTE as in MySQL:
with your_table as (
select 'some value' --from etc etc
)
select * from your_table;
Another example: https://stackoverflow.com/a/54960324/2700344
Hive CTE Official docs

how to extract tables attributes like column name , datatype ,nullable for all the tables from the database from oracle pl/sql

Is there any query that can be used to retrive the Tables and its column attributes like column name , datatype, nullable etc for all the tables inside the database
For Oracle Pl/SQL
The Oracle SQL you need would be the following (run as user 'SYS'):
select owner, table_name, column_name, data_type, nullable
from dba_tab_columns;
If you do a desc dba_tab_columns you will get a list of many more columns which may be of interest to you as part of your result set.
You can use a SQL tool (i.e. SQL*Plus) to run this query or you can use PL/SQL to call this query and put the results in PL/SQL variables then print them out via DBMS_OUTPUT.PUT_LINE().
HTH

How to have the list of table in a monetdb database?

In postgresql, one can have all tables names by running the following query
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
Is there something similar in monetdb to have the list of tables ?
I finally find this query
select tables.name from tables where tables.system=false ;
If you are using mclient, in the command line you could simply use the command "\d" to list all the tables in the current database.
sql> \d
TABLE sys.table1
TABLE sys.table2
TABLE sys.table3
Additionally, use the command "\d tablename" to view the metadata of a table - equivalent to "show create table" in mysql.

Resources