I cant access another users table within java application - sql

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?

Related

how to get FID of the user in oracle sql developer

In my database, i have one procedure which has been accessed by two other users through FID (outside of the database).
i need to log the FID of the user who are all using my procedure.
Is there any SQL Query to get the FID in oracle??
You didn't specify how exactly your users are identified (there is no "FID thing" in Oracle RDBMS).
Oracle knows only about two layers of identification:
Session user (for example scott#). This is how to get connected user:
select sys_context('userenv','session_user') from dual;
Proxy user (for example proxy[scott]#). This is how to get connected proxy user:
select sys_context('userenv','proxy_user') from dual;
If your user identification is happening outside Oracle, then you can't catch it in PLSQL. You should add another IN parameter to PLSQL procedure and pass it by your outside app when calling stored procedure.

in oracle SQL developer How do I display list of all tables from current user/schema

I m working in oracle SQL developer database where I want to display list of all tables from current user/schema
You see the list of tables as owned by the current schema user in the Tree view of the connection under "tables". If you login as sys, then you see sys owned (of course).
If you want to see the schema of a different user, you need to have select permissions on the tables (and maybe some more in SQL Developer). Then you can see the tables of the other schema under <Connection>/Other Users/<User>/Tables/*.
If you don't see tables there, then you need to check for Synonyms, global synonyms or views. Finally if none of them are showing the expected tables (and you are aure you logged into the correct instance and CDB) then there might be a different active default schema for your user active after logon (typical case of a logon trigger). In this case the statement from before applies: look under the user who owns them.
SQL Developer internally used the ALL_* and USER_ system views. For example your tables owned by you: select TABLE_NAME from user_tables. More complete description of that is here.

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

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?

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

SQL server : Login issue while querying

I have a web application running with a SQL server 2005 DB as back end.I took the db back of the production site and restored in my development machine.Then i tried to query this database using the login "sa".When trying to execute the "select * from Customers" query, i am getting a message like "Invalid object name 'Customers"
But when i run "SELECT * FROM [352974_mg4l1].[Customers]", It is returning records.
352974_mg4l1 is a user for this database present when i restored the db backup from production.
What i have to do for getting the records using with simple select query which i used initially("select * from Customers" ). I know it is something related to login issue.Can any one tell me how to solve this ?
The Customers database object is not owned by the dbo schema.
And by referencing Customers as 'sa' you are looking for [dbo].[Customers] ?
I would suggest to:
either provide the object's full name
either change it's schema
Edit:
To alter the schema of said table try this:
ALTER SCHEMA dbo TRANSFER [352974_mg4l1].Customers;
Reference: http://msdn.microsoft.com/en-us/library/ms173423.aspx
Look up sp_changeobjectowner in Books on line. That will help you change the owner. The real question is how the object got created to a specific owner to begin with. If this is true on prod, you could have some major issues with other people accesssing the database.