how to access another user1s table in sql developer database? - sql

BBMA.SALES_BKP TABLE IS THERE IN BBMP SCHEMA(user)
I WANT TO ACCESS "SALES_BKP TABLE" through DUMMY(its different user)

Here's how.
SQL> create user dummy identified by dummy
2 default tablespace user_data
3 temporary tablespace temp
4 quota unlimited on user_data;
User created.
SQL> grant create session, create table to dummy;
Grant succeeded.
SQL> create user bbma identified by bbma
2 default tablespace user_data
3 temporary tablespace temp
4 quota unlimited on user_data;
User created.
SQL> grant create session to bbma;
Grant succeeded.
Now, create table and let another user select from it.
SQL> connect dummy/dummy#orcl
Connected.
SQL> create table sales_bkp(id number, value number);
Table created.
SQL> insert into sales_bkp values (1, 100);
1 row created.
SQL> grant select on sales_bkp to bbma; --> this
Grant succeeded.
SQL> connect bbma/bbma#orcl
Connected.
SQL> select * from dummy.sales_bkp; --> note owner name
ID VALUE
---------- ----------
1 100
SQL>

Related

Can I prevent execute immediate from inserting on a read-only user

I have a read-only user that has to have the execute privileges to specific packages.
These packages sometimes use execute immediate to insert values into tables.
I can see why it was built this way, however I need the package to throw an Insufficient Privileges error instead of just executing the modifying statements.
Is it possible to change the behaviour or build a workaround without changing the executed packages?
So read only user has:
GRANT SELECT ON table to READ_ONLY_USER;
GRANT EXECUTE, DEBUG ON package to READ_ONLY_USER;
Package contains:
query = 'INSERT INTO table VALUES (value)';
execute immediate query;
And I need an error when the user executes the package.
Check the following example. Shortly, keyword is AUTHID CURRENT_USER while creating that PL/SQL program unit.
Connected as MIKE (who owns table and procedure and grant SCOTT privileges to use them):
SQL> show user
USER is "MIKE"
SQL>
SQL> create table test (id number);
Table created.
SQL> create or replace procedure p_test
2 authid current_user
3 is
4 begin
5 execute immediate 'insert into mike.test values (1)';
6 end;
7 /
Procedure created.
SQL> exec p_test;
PL/SQL procedure successfully completed.
SQL> select * from test;
ID
----------
1
SQL> grant select on test to scott;
Grant succeeded.
SQL> grant execute on p_test to scott;
Grant succeeded.
SQL>
Connected as SCOTT:
SQL> show user
USER is "SCOTT"
SQL>
SQL> select * From mike.test;
ID
----------
1
SQL> exec mike.p_test;
BEGIN mike.p_test; END;
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "MIKE.P_TEST", line 5
ORA-06512: at line 1
SQL>
Without it, SCOTT is able to insert values into MIKE's table:
SQL> connect mike/lion#orcl
Connected.
SQL> create or replace procedure p_test
2 is --> no more authid current_user
3 begin
4 execute immediate 'insert into mike.test values (2)';
5 end;
6 /
Procedure created.
SQL> connect scott/tiger#orcl
Connected.
SQL> exec mike.p_test;
PL/SQL procedure successfully completed.
SQL> select * From mike.test;
ID
----------
1
2
SQL>

User with no privileges can alter table in oracle

I'm trying to do a test to prove the privileges of the users. I have one user with just one privilege (execute programs) but when I try this, this user can alter table:
SHOW USER;
CONNECT USER1/USER1;
CREATE TABLE TEST_TABLE (colum int); //Insufficient privileges
SHOW USER;
ALTER TABLE TABLE_TESTING ADD TESTING varchar(255);
So, I'm getting insufficient privileges on create table but when I do ALTER TABLE the user can do it and I don't know why because I select only the privilege of execute programs
This is how I see it: follow the example.
As a privileged user (SYS in my XE database), I'll create user and grant only two privileges: create session (so that user could connect to the database) and create table (so that it can create tables):
SQL> show user
USER is "SYS"
SQL>
SQL> create user timer identified by timer
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
SQL> grant create session, create table to timer;
Grant succeeded.
Connecting as newly created user and creating a simple table:
SQL> connect timer/timer
Connected.
SQL> create table test (id number);
Table created.
Back to SYS: this time, revoking create table privilege:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> revoke create table from timer;
Revoke succeeded.
Back to timer: creating table won't succeed (as I don't have that privilege any more):
SQL> connect timer/timer
Connected.
SQL> create table test_table (colum int);
create table test_table (colum int)
*
ERROR at line 1:
ORA-01031: insufficient privileges
But, I can still alter previously created tables. Why? Because I own them and I can do whatever I want with them:
SQL> alter table test add testing varchar2(20);
Table altered.
I suggest you talk to your DBA to see what's really going on.
That might be because the user has the rights to execute which means he's able to alter tables by executing code, but he is not allowed to create new tables explicitly. See: https://docs.oracle.com/cd/B19306_01/network.102/b14266/authoriz.htm#DBSEG5000

Error creating nested table column storage table

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Seeking help from experts to resolve the following error:
CREATE TABLE "ABC"
(----
----
"STATUSES" "INTLIST" ,
----
"CHAIN_DETAILS" "CHAIN_CFG_LIST" ,
-----
)
NESTED TABLE "STATUSES" STORE AS "OP_STATUSES_NT"
RETURN AS VALUE
NESTED TABLE "CHAIN_DETAILS" STORE AS "op_chains"
RETURN AS VALUE;
Gives error message:
ORA-02320: Error creating nested table column storage table STATUSES
ORA-01950: no permissions for tablespace
My guess is the user has no quota on the default tablespace. You can find your default tablespace by querying user_users, or dba_users if checking a different user, and the quota from user_ts_quotas or dba_ts_quotas. A value of -1 means unlimited. Join these to see your quota for the default tablespace:
select u.username
, u.default_tablespace
, tq.max_bytes
from user_users u
left join user_ts_quotas tq
on tq.tablespace_name = u.default_tablespace;
This will be a problem for any table, but if deferred_segment_creation is set to true (the default) then the error will only appear when you attempt to add a row to the table, as this is the first request for storage.
Now that I check, it seems a nested table requires storage immediately, which could explain why you get the error for a nested table column.
Example using test user 'demo':
sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri May 11 10:41:51 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> create user demo identified by demo;
User created.
SQL> grant create session, create table, create type to demo;
Grant succeeded.
Connect as demo:
SQL> conn demo/demo
Connected.
SQL> col username format a15
SQL> col default_tablespace format a20
SQL> select u.username
2 , u.default_tablespace
3 , tq.max_bytes
4 from user_users u
5 left join user_ts_quotas tq
6 on tq.tablespace_name = u.default_tablespace;
USERNAME DEFAULT_TABLESPACE MAX_BYTES
--------------- -------------------- ----------
DEMO USERS
My default tablespace is USERS and I have no quota on it, but I can create a table:
SQL> create table demotable(id integer);
Table created.
I only have a problem when I need some actual storage:
SQL> insert into demotable values (1);
insert into demotable values (1)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'USERS'
Now try with a nested table:
SQL> create or replace type demo_tt as table of number(1);
2 /
Type created.
SQL> create table abc
2 ( id integer
3 , statuses demo_tt )
4 nested table statuses store as op_statuses_nt return as value;
create table abc
*
ERROR at line 1:
ORA-02320: failure in creating storage table for nested table column STATUSES
ORA-01950: no privileges on tablespace 'USERS'
My user demo needs a quota on tablespace USERS (normally you grant unlimited or nothing, but just for fun let's allocate 1MB...)
SQL> conn / as sysdba
Connected.
SQL> alter user demo quota 1M on users;
User altered.
SQL> conn demo/demo
Connected.
SQL> select u.username
2 , u.default_tablespace
3 , tq.max_bytes
4 from user_users u
5 left join user_ts_quotas tq
6 on tq.tablespace_name = u.default_tablespace;
USERNAME DEFAULT_TABLESPACE MAX_BYTES
--------------- -------------------- ----------
DEMO USERS 1048576
Retry the table creation:
SQL> create table abc
2 ( id integer
3 , statuses demo_tt )
4 nested table statuses store as op_statuses_nt return as value;
Table created.
SQL> insert into abc (id, statuses) values (1, demo_tt(1,2,3));
1 row created.

grant create view on Oracle 11g

I use SQL*Plus for school and I use the username Scott. I cannot create views because it says:
ORA-01031: insufficient privileges;
I've searched and searched, but nothing seems to get it right. Any help?
As the error states - your privileges are insufficient to create view - you will have to ask database administrator to grant you this privilege.
If you can log in as database administrator you will have to execute statement(I can't guarantee correctness, no oracle database at hand)
GRANT CREATE ANY VIEW TO Scott;
or
GRANT CREATE VIEW TO Scott;
You need to GRANT the CREATE VIEW privilege to the USER which is creating the view.
For example, I create a new user to let it create a session, a table and a view:
SQL> create user test identified by test;
User created.
SQL> grant create session, create table, create view to test;
Grant succeeded.
SQL> conn test/test#pdborcl;
Connected.
SQL> Create Table advanced
2 (Id varchar(15),
3 Name varchar(20),
4 Dept varchar(15),
5 Cgpa float,
6 Birth_date date,
7 Mob_no int,
8 Dist varchar(20),
9 Salary number(8));
Table created.
SQL> Create View advanced_data as
2 (
3 select name,dept,dist,salary from advanced
4 );
View created.
If I revoke the privilege, you will recieve ORA-01031: insufficient privileges:
SQL> revoke create view from test;
Revoke succeeded.
SQL> conn test/test#pdborcl;
Connected.
SQL> Create or replace View advanced_data as
2 (
3 select name,dept,dist,salary from advanced
4 );
Create or replace View advanced_data as
*
ERROR at line 1:
ORA-01031: insufficient privileges
step 1-conn ss/ss as sysdba;
step 2- GRANT CREATE ANY VIEW TO Scott;
step 3- conn scott/tiger
step 4-create or replace view v as select *from emp;
To log-in as DBA (database administrator) you can use:
sqlplus / as sysdba
or
sqlplus sys as sysdba

Oracle 9i auto increment trigger/sequence doesnt work

The following SQL, upon being executed on an Oracle 9i server, yields the the error " ORA-04098: trigger 'DBO.WTF_TRIGGER' is invalid and failed re-validation".
DROP TABLE "DBO".WTF;
CREATE TABLE "DBO".WTF
(id NUMBER PRIMARY KEY,
name VARCHAR2(30));
CREATE SEQUENCE "DBO".WTF_sequence
START WITH 1
INCREMENT BY 1;
CREATE OR REPLACE TRIGGER "DBO".WTF_trigger
BEFORE INSERT
ON "DBO".WTF
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT "DBO".WTF_sequence.nextval INTO :NEW.id FROM dual;
END;
INSERT INTO "DBO".WTF (name) VALUES ('asd');
Any ideas?
As APC points out, it would be helpful to do a SHOW ERRORS in SQL*Plus to print out the errors. The code you posted works perfectly for me if I create a DBO user with appropriate privileges.
SQL> conn / as sysdba
Connected.
SQL> create user dbo identified by dbo;
User created.
SQL> grant connect, resource, unlimited tablespace to dbo;
Grant succeeded.
SQL> conn dbo/dbo
Connected.
SQL> DROP TABLE "DBO".WTF;
DROP TABLE "DBO".WTF
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> CREATE TABLE "DBO".WTF
2 (id NUMBER PRIMARY KEY,
3 name VARCHAR2(30));
Table created.
SQL>
SQL> CREATE SEQUENCE "DBO".WTF_sequence
2 START WITH 1
3 INCREMENT BY 1;
Sequence created.
SQL>
SQL> CREATE OR REPLACE TRIGGER "DBO".WTF_trigger
2 BEFORE INSERT
3 ON "DBO".WTF
4 REFERENCING NEW AS NEW
5 FOR EACH ROW
6 BEGIN
7 SELECT "DBO".WTF_sequence.nextval INTO :NEW.id FROM dual;
8 END;
9 /
Trigger created.
SQL> INSERT INTO "DBO".WTF (name) VALUES ('asd');
1 row created.
SQL> select * from wtf;
ID NAME
---------- ------------------------------
1 asd