SQL Using a Select Grant in Oracle - sql

I'm using Oracle 11g R2. Our setup is an ODS and a Data Warehouse.
I need to write a query which joins tables from the ODS to tables in the DW. My Query is fine however i am getting an error "table or view does not exist". I've been told this is because i need to use a Grant Select on my query to allow the DW to 'see' the tables in the ODS. I've looked online but my attempts to integrate it just isn't working.
I've been using
grant select on ODS_Product to DW;
grant select on ODS_History to DW;
I get the script output saying grant succeeded but then when i go to the DW SQL worksheet and execute my query i get the error.
Anyone able to advise/or provide an example?

These need to be fully qualified grants executed either by the owner of the tables or a database user whom has the "grant select" privilege.
As an example, a user logged in to the schema owning the ods tables will need to execute this:
grant select on ods_schema.ODS_Product to DW;
grant select on ods_schema.ODS_History to DW;

Related

Create a SQL Server view with different permissions

I have created a view in Database A that looks at tables in Database B that the users in Database A do not have access to (HR Data).
Is there a way I can grant anybody calling the view in Database A permissions to see the results, without giving access to the underlying tables?
Both databases are on the same instance, SQL Server 2019
You can just
GRANT SELECT ON OBJECT::[schema].[theView] TO User1,User2
in your Database A? This way you'd just give SELECT permissions to the view itself, and not the tables.
If you have a lot of cases like this, you can also consider creating a special schema for this and do:
GRANT select ON Schema :: [DBO] TO User1
instead.

Grant to select on synonym through database_link

I have administrative problem on my database.
I need to give permission to other schema to my View. My View have data from one table and view. This Second view is using private database link.
How can i grant select on that View, to other schema and in the same time grant view that is using database link?
While trying making simple
grant select on myView to otherSchema;
i have error ORA-02021: DDL operations are not allowed on a remote database
DDL operations of any kind, such as grants, are not allowed to be executed through a database link. You need to connect to the remote database where the source objects are located, and grant select on them to the user/schema who connects by dblink. As you don't provide any code, consider the option that you might need to use grant select on xxxx with grant option.

Grant permission for creating stored procedure, view and using Select query

I'm new to SQL Server.
User already exist in a database and now he is requesting access for creating sp, views and fetching data using select query. Please tell me how to grant using ssms or t-sql
P.S: I already googled and it's really confusing since some of the sites using "Alter Schema" too
GRANT CREATE PROCEDURE TO [login];
GRANT CREATE VIEW TO [login];
GRANT SELECT TO [login];
And so on
select user login ID: SECURITY : - LOGINS or if not there create new user id in server role as public.. under user mapping select database then select membership as db_datareader

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

Permissions denied on sql query

I'm trying to execute the following query through classic asp recordset -
SQL = "Select P_Name as P_Name, P_Description as P_Description
from L_PagePermission
inner join A_Permission on p_permissionID = pp_PermissionID
inner join A_Page on P_PageID = PP_PageID
where P_PageID = 85
order by p_Name"
Although I've ran into a problem with permissions. So the error that i am receiving is -
Microsoft OLE DB Provider for ODBC
Drivers error '80040e09'
[Microsoft][ODBC SQL Server
Driver][SQL Server]SELECT permission
denied on object 'A_Permission',
database 'HRWB_3_0', schema 'dbo'.
How would I go about executing this query without changing permission settings. How can I do this with a stored procedure? (Can someone provide an example too)
I can't change the database settings I have to deal with what I got. I've looked through a lot of the websites files and it seems to be mostly dependent on stored procedures.
You're not going to be able to get around that permissions error unless you grant select access on the L_PagePermission and A_Permission tables to the login that you are using to connect to the database, or unless you use a different login that already has select access to those tables.
Another approach would be to write a new stored procedure and grant EXECUTE access to that stored procedure. The SQL to grant permissions in either case is simple:
To grant SELECT access to a table:
GRANT SELECT ON [TableName] TO [loginName]
To grant EXECUTE access to a stored procedure:
GRANT EXECUTE ON [procedureName] TO [loginName]
One more approach that could work but has obvious security implications is to add the login you are using to the db_owner role for that database. That should work, but is NOT recommended unless you are comfortable with the security risks that presents.
If you don't have permission to select from the table, there won't be any way to work around the absence of permission other than connecting to the DBMS as a user who has permission to select from the table. That's the point of the permissions system - to prevent the unauthorized from doing what they are not allowed to do.