Querying a database and insert resulting into a table in a seperate database in Oracle SQL Developer - sql

Hi I have two database connections in Oracle SQL developer. I am trying to query results out of one database and insert them into another. If one database is named Issue and the other one named Hub. The table I want the results to go in is in the DB Hub. So in a worksheet in the hub database would I do something like this?
INSERT INTO RESULTS
SELECT ...
FROM ISSUE.TABLE1 ISSUE1,
ISSUE.TABLE2 ISSUE2,
WHERE ...
However when I do this I get this error:
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
I am connecting to the database Issue incorrectly?
Thanks,

Most probably you have problems with your privileges.
Try this:
login as user ISSUE and execute this statement:
GRANT SELECT ON TABLE1 TO HUB;
GRANT SELECT ON TABLE2 TO HUB;
login again as HUB and try again your select statement.
I'm not at my desk, therefore I can't test it on my own.
If your database users are on different Oracle instances, then you need a database link from HUB to ISSUE.

This came directly out of the manual;
INSERT INTO db1.table1(col1) SELECT col2 FROM db2.table2;
Did you try reading the manual about cross database inserts?

Related

I cant access another users table within java application

I'm using oracle database 12c. 1 database with two schemas (users) one user is called PROD the second one CREDIT. I'm connected to database, using ojdbc (simple java application) as user PROD when i try to execute SQL query, which selects data from table owned by second user CREDIT.
I'll get error
PL/SQL: ORA-00942
Now when i connect to database using SQL Developer and run this query it works fine.
Select looks like this
SELECT C.USER FROM CREDIT.USERS C
In view "all_objects" I did found this table owned by user CREDIT and user PROD(both users have same structure but different data). Why am I getting this error?

How to create database table when using Wildfly?

I am trying to complete a tutorial on a simple javaEE project using wildfly. The first step is creating two tables in my database. As it says I should create my tables like this: "CREATE TABLE wildfly.name...." but it gives me an error saying thet wildfly is unknown.
Link to the tutorial: click here
My question is why should i put "wildfly." before the table name and how can I solve this error?
Thank you for your help!
Note: I am using oracle database instead of mysql
It's a misleading MySQL tutorial example because in Oracle syntax "wildfly." is a user(schema) in the Oracle database.
Schema/user in Oracle is a namespace for tables and other objects. So, when you issue such a statement - you're telling oracle to create table in namespace WILDFLY. If you don't have such user in your database or you don't have rights to access such user/schema - you can't create tables there.
You should create such user in Oracle database (or alter your statement to another user/schema name that you actually have in your database) and put your tables there.
For example these statements are correct because I created WILDFLY user before putting tables to it:
CONNECT SYS/****#ORCL AS SYSDBA
CREATE USER WILDFLY IDENTIFIED BY WILDFLYPASSWORD;
GRANT UNLIMITED TABLESPACE TO WILDFLY;
CREATE TABLE WILDFLY.MYTABLE...

Error in APEX SQL

I am working on Oracle 11g. I have created a table STUDENTS using APEX in my port: 8080 . After that when I use SQLPLUS in cmd and write SELECT * FROM STUDENTS it shows TABLE OR VIEW DOES NOT EXIST. What am I doing wrong here?
Ok...When you created the table using APEX, what schema was it created in? When you connect via SQL*Plus, are you logging in as the same user who owns the table?
If not, you'll need to grant select on the table to the user that wants to access the table, and also either specify the owner when referencing the table in your select statement, or create a synonym, or use alter session set current_schema statement.

SQL Error: ORA-00942 table or view does not exist

I use SQL developer and i made a connection to my database with the system user, after I created a user and made a another connection with that user with all needed privileges.
But when I try to proceed following I get the SQL Error
ORA-00942 table or view does not exist.:
INSERT INTO customer (c_id,name,surname) VALUES ('1','Micheal','Jackson')
Because this post is the top one found on stackoverflow when searching for "ORA-00942: table or view does not exist insert", I want to mention another possible cause of this error (at least in Oracle 12c): a table uses a sequence to set a default value and the user executing the insert query does not have select privilege on the sequence. This was my problem and it took me an unnecessarily long time to figure it out.
To reproduce the problem, execute the following SQL as user1:
create sequence seq_customer_id;
create table customer (
c_id number(10) default seq_customer_id.nextval primary key,
name varchar(100) not null,
surname varchar(100) not null
);
grant select, insert, update, delete on customer to user2;
Then, execute this insert statement as user2:
insert into user1.customer (name,surname) values ('michael','jackson');
The result will be "ORA-00942: table or view does not exist" even though user2 does have insert and select privileges on user1.customer table and is correctly prefixing the table with the schema owner name. To avoid the problem, you must grant select privilege on the sequence:
grant select on seq_customer_id to user2;
Either the user doesn't have privileges needed to see the table, the table doesn't exist or you are running the query in the wrong schema
Does the table exist?
select owner,
object_name
from dba_objects
where object_name = any ('CUSTOMER','customer');
What privileges did you grant?
grant select, insert on customer to user;
Are you running the query against the owner from the first query?
Case sensitive Tables (table names created with double-quotes) can throw this same error as well. See this answer for more information.
Simply wrap the table in double quotes:
INSERT INTO "customer" (c_id,name,surname) VALUES ('1','Micheal','Jackson')
You cannot directly access the table with the name 'customer'. Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'. hope this helps..
Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm
An Oracle synonym basically allows you to create a pointer to an object that exists somewhere else. You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account). If they are not there, it will give you an error telling you that they do not exist.
I am using Oracle Database and i had same problem. Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.
And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE). Also same applicable on column name.
It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.
in my case when i used asp.net core app i had a mistake in my sql query. If your database contains many schemas, you have to write schema_name before table_name, like:
Select * from SCHEMA_NAME.TABLE_NAME...
i hope it will helpful.

SELECT data from another schema in oracle

I want to execute a query that selects data from a different schema than the one specified in the DB connection (same Oracle server, same database, different schema)
I have an python app talking to an Oracle server. It opens a connection to database (server/schema) A, and executes select queries to tables inside that database.
I've tried the following :
select ....
from pct.pi_int, pct.pi_ma, pct.pi_es
where ...
But I get:
ORA-00942: table or view does not exist
I've also tried surrounding the schema name with brackets:
from [PCT].pi_int, [PCT].pi_ma, [PCAT].pi_es
I get:
ORA-00903: invalid table name
The queries are executed using the cx_Oracle python module from inside a Django app.
Can this be done or should I make a new db connection?
Does the user that you are using to connect to the database (user A in this example) have SELECT access on the objects in the PCT schema? Assuming that A does not have this access, you would get the "table or view does not exist" error.
Most likely, you need your DBA to grant user A access to whatever tables in the PCT schema that you need. Something like
GRANT SELECT ON pct.pi_int
TO a;
Once that is done, you should be able to refer to the objects in the PCT schema using the syntax pct.pi_int as you demonstrated initially in your question. The bracket syntax approach will not work.
In addition to grants, you can try creating synonyms. It will avoid the need for specifying the table owner schema every time.
From the connecting schema:
CREATE SYNONYM pi_int FOR pct.pi_int;
Then you can query pi_int as:
SELECT * FROM pi_int;
Depending on the schema/account you are using to connect to the database, I would suspect you are missing a grant to the account you are using to connect to the database.
Connect as PCT account in the database, then grant the account you are using select access for the table.
grant select on pi_int to Account_used_to_connect