how to create Oracle DBLink in same SID - oracle

Please let me know how to create Oracle DBLink in the same SID for two schema? To make clear, I want to connect one schema to another schema in the same Oracle server (SID).
Let's say, I have two schema called sch1 and sch2. Now, I login as sch1 and what I want is to retrieve data from sch2 (as long as I'm in sch1).

If you want to access a table in one schema from another schema, try doing the following:
connect as schema2,
run grant select on sometable to schema1,
connect as schema1,
try select * from schema2.sometable.

Related

Change default Database in oracle

I'm working on C# Winform app and I have the query that select the list of tables but in but in the schema of the user I list there's no table listed.
This query should work in SQL Server
ALTER LOGIN [my_user_name] WITH DEFAULT_DATABASE = [new_default_database]
is there query like that on oracle?
Nope, there's not (as far as I can tell).
(Just a side note: what you call "database" in MS SQL Server is called "user" in Oracle, while "schema" = "user + all its objects").
Solution? Connect as user which owns tables you use.
Alternatively, if you can't have those credentials (username and password + database) for some reasons (such as security), you'll have to get access to those objects, somehow. One option is that owner grants (at least) select privilege. Suppose I'm the owner (user = "littlefoot"):
grant select on employees to kim;
("kim" is user you can connect to).
Then you'd precede table name with owner name:
select * From littlefoot.employees;
Or, you could create a synonym to all those tables so that you could avoid specifying owner name:
create synonym employees for littlefoot.employees;
select * from employees;
Or, if it really is a different database, you'll have to create a database link, but it presumes that you know login credentials so - I believe that this is not your case.

Reference a table in other schema omiting schema name

If I have a table sch1.tab1 is it possible to call it from schema/user sch2 just with
select * from tab1 (assume that we have all the privilegies)?
I am aware that in postgresql you can set the search path where db would look for tables which enables you to omit the schema when you are referencing a table but I do not know if this exists in oracle.
Thank you.
You can create a synonym, but you'd have to make one for each table you wanted to access; from sch2:
create synonym tab1 for sch1.tab1;
A more general method is to switch your current schema:
alter session set current_schema = 'SCH1';
You're still connected with your original user account and only have those privileges still, but you don't have to qualify objects in that schema any more. But now you would have to qualify any of your own tables (back in sch2), if you have objects in both schemas.

Importing a stored procedure from oracle to Informatica

I have to import a stored procedure from Oracle database into Informatica.
But when I try to use the Stored Procedure Transformation I cannot view the respective stored procedure.
I am using the correct oracle driver since I don't have any trouble in importing target database tables.
I tried viewing the stored procedures in the oracle database using
select * from all_objects where object_type='FUNCTION' but could not find the
function I am looking for.
Please advise me on these:
Can we view the list and code of Stored procedure(s)/function(s) in Oracle
What am I missing in Informatica stored procedure transformation?
If you don't get any results from this..
select * from all_objects where object_type='FUNCTION'
It either means you don't have any functions or the current user does not have the privileges to execute any functions. Find out which user owns the function and grant the following.
example :
grant execute on <owner>.<function_name> to ETL_USER;
To avoid confusion, make sure the username in the informatica connection and the one you are using when connecting to the database are the same.
While importing object into Informatica, listed objects are always owned by the "connecting" user. If your object is owned by some other user, you wont see it. To see objects not owned by connecting user, you'd have to choose "All" in the schema text box, while connecting.
You should be looking for object_type='PROCEDURE' and not "FUNCTION". Therefore, your query should read as select * from all_objects where object_type='PROCEDURE'
If all this is done and you still dont see the object, check privileges on that object to your connecting user. For this, the best course is
a. ask your dba to grant execute privileges on that object to your connecting user. OR
b. connect to database as the owner of that object and run the following command
grant execute on <object_name> to <connecting_user>

Oracle new table is not accessible with only table name

I have inherited a Oracle 10.2 database witch I have to extend with new tables...
On the test database I just add table and grant select privileges to the "non root" user and it works.
I do the same on the production database and I can't select from the table. It only works if I do "select * from table_space.tablename" not "select * from tablename".
Do I have to add some kind of alias or something?
You probably need a synonym for the table.
See here and here
Also, try a select * from all_synonyms; first to see if a generic user is accessing the table through a synonym (as I suspect).

How should I read the data from different oracle schema using ado.net?

The database user has got two schemas. I need to read the data from a specific schema using ado.net. I am using OleDbConnection object to create the connection to database. Appreciate your answers.
Use SCHEMA_NAME.TABLE_NAME in your queries.
If you don't specify a schema, Oracle will look into the current schema. The schema is by default the connexion user (so if you connect with USER1 and query TABLE1, Oracle will look for the table USER1.TABLE1). You can change your current schema at any time during a session with:
ALTER SESSION SET CURRENT_SCHEMA=SCHEMA2;
You can also use synonyms to point to the correct table.

Resources