GRANT to EXECUTE execute immediate truncate table in Oracle - oracle

My user is owner of a simple schema in an instance of Oracle in my Job, let´s call my USER E, with some resctinct privileges.
Also I have an USER E_ETL, to receive information of another database with ETL techonology.
My user E is the owner of some tables and a procedure DO_TRUNCATE (E.DOCUMENT_TASKS and E.DO_TRUNCATE), and the user E_ETL uses every day the procedure E.DO_TRUNCATE to clean all data inside my E.DOCUMENT_TASKS and insert the flash new information. But I´m having problems to GRANT user E_ETL to execute immediate the function to truncate table E.DOCUMENT_TASKS, the code and the error is those:
E.DOCUMENT_TASKS
CREATE TABLE "E"."DOCUMENT_TASKS"
(
"DOCUMENT" VARCHAR2(20 BYTE),
"REVISION" VARCHAR2(5 BYTE),
"TITLE" VARCHAR2(300 BYTE),
"STATUS" VARCHAR2(50 BYTE),
"TASK" VARCHAR2(120 BYTE),
"ETL_DATE" TIMESTAMP (6) DEFAULT SYSDATE NOT NULL ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "E_D_01" ;
The E.DO_TRUNCATE procedure code is:
create PROCEDURE DO_TRUNCATE ( ptname in varchar2)
as
begin
execute immediate 'truncate table '||upper(ptname);
end;
I alread gave some grants for E_ETL user:
GRANT SELECT, DELETE, INDEX, INSERT, REFERENCES, UPDATE ON E.DOCUMENT_TASKS TO E_ETL;
GRANT EXECUTE ON DO_TRUNCATE TO E_ETL;
But I still have this error information:
Database driver error...
Function Name : executeDirect
SQL Stmt : call DO_TRUNCATE ('DOCUMENT_TASKS')
Oracle Fatal Error
Database driver error...
Function Name : ExecuteDirect
Thanks all!!!

The error Database driver error... suggests that you might have an error connecting to the database; if so then you will need to sort that (but since you have not provided the error message then we cannot make suggestions).
Other issues could be:
Change CALL to Oracle's BEGIN END syntax:
BEGIN DO_TRUNCATE ('DOCUMENT_TASKS'); END;
If you are not connecting as the E user who owns the procedure and tables then make sure you include the schema name:
BEGIN E.DO_TRUNCATE ('E.DOCUMENT_TASKS'); END;

This is not Oracle error. Also it is saying about "executeDirect". Please elaborate more about the error

Related

As a system user I have this error: ORA-01031: insufficient privileges

I have a stored procedure for deleting partitions. Before starting, I have to delete a constraint.
I installed the stored procedure on system user. When I test the procedure I have this error: 'ORA-01031: insufficient privileges'.
This is a piece of code that I wrote:
BEGIN
EXECUTE IMMEDIATE 'ALTER TABLE USER_NAME.TABLE_NAME DISABLE CONSTRAINT CONSTRAINT_NAME';
EXCEPTION
WHEN OTHERS THEN
O_sCodError := 'NO_OK';
O_sDesError := 'Error at DISABLE CONSTRAINT_NAME: ' || SQLERRM || ';';
RETURN;
END;
Well, as I execute the stored procedure as system, I do not understand the reason for I have that error. And I think I eventually think the same error when I try to delete a partition.
Works for me on 11g XE:
SQL> show user
USER is "SCOTT"
SQL>
SQL> create table test
2 (id number constraint pk_test primary key,
3 name varchar2(20)
4 );
Table created.
SQL> connect system
Enter password:
Connected.
SQL> begin
2 execute immediate 'alter table scott.test disable constraint pk_test';
3 return;
4 end;
5 /
PL/SQL procedure successfully completed.
SQL>
Please, follow that example and execute it in your database. Post the result (by editing the question, not as a comment).
First, you should never install custom code in an Oracle default schema like SYSTEM. Put your code in a dedicated application schema. Since it contains dynamic SQL (execute immediate) you might want to consider making it an "invoker's rights" procedure, then granting execute privileges on it to the user that will execute it.
That said, in Oracle 11g whoever's privileges are used to run the PL/SQL block must have direct permissions on the underlying table, not inherited permissions through a role like DBA. If the procedure has "definer's rights" then the schema that owns the procedure must have direct privileges on the table. If "invoker's rights" then the user executing the procedure must have the privileges.
See this link for additional details:
Execute immediate within Oracle Procedure
You must grant SYSTEM account direct privilege (not with a role) to run ALTER TABLE on the target table because roles are not enabled in stored procedures by default: https://asktom.oracle.com/Misc/RolesAndProcedures.html.
Try:
grant alter any table to system;
or
grant alter table on user_name.table_name to system;

Using Oracle partition and storage options with Redgate Schema Compare fails

I'm trying to introduce new audit tables for our project. In the deployment process we use redgate's Schema Compare for Oracle (version 4.0.8.420).
The table looks something like this:
create table MY_SCHEMA.MY_TEST_AUDT (
TEST_ID NUMBER(19),
-- all sorts of business fields, omitted for clarity
AUDT_CRT_DTM TIMESTAMP DEFAULT SYSTIMESTAMP,
AUDT_ACTN_CODE VARCHAR2(1),
AUDT_CRT_USR_NM VARCHAR2(128) DEFAULT USER,
AUDT_CLIENT_IDENTIFIER VARCHAR2(256),
AUDT_CLIENT_INFO VARCHAR2(256)
)
TABLESPACE MY_TABLESPACE
PCTFREE 0
INITRANS 10
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
COMPRESS FOR OLTP
NOCACHE
PARTITION BY RANGE (AUDT_CRT_DTM)
INTERVAL(interval '1' month)
(
PARTITION P0 VALUES LESS THAN (date '2018-11-01')
PCTFREE 0
INITRANS 10
)
/
The first time I ran it I got an error concerning the storage clause
Parsing failed with message SyntaxError. Unexpected token 'K'
When I got rid of the storage clause (since I can use the defaults) it started complaining about the partitioning clause and that's where I am not very happy with the software.
Parsing failed with message SyntaxError. Unexpected token 'PARTITION' (Line 35, Col 1) symbol Id
I tried turning all the storage options on and off, nothing worked. I tried the latest version 5.2 with a simple compare of files and it didn't work either. I tried to post it on the redgate forums and my post has been stuck as drafted for two days now.
I'm using the scripts folder comparison, the above mentioned file for source and no file for the target, Oracle 11g scripts.
I have managed to get it working without the partition. I had to replace the slash with a semicolon and switch the 8K and 1M to the full values. But I'm still not able to create partitions.
create table MY_SCHEMA.MY_TEST_AUDT (
TEST_ID NUMBER(19),
-- all sorts of business fields, omitted for clarity
AUDT_CRT_DTM TIMESTAMP DEFAULT SYSTIMESTAMP,
AUDT_ACTN_CODE VARCHAR2(1),
AUDT_CRT_USR_NM VARCHAR2(128) DEFAULT USER,
AUDT_CLIENT_IDENTIFIER VARCHAR2(256),
AUDT_CLIENT_INFO VARCHAR2(256)
)
TABLESPACE MY_TABLESPACE
PCTFREE 0
INITRANS 10
STORAGE (
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
COMPRESS FOR OLTP
NOCACHE;
Any help is very much appreciated.
Alain
For completeness here's my DatabaseInformation.xml file
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<ScriptsFolderInformation version="2" type="ScriptsFolderInformation">
<DatabaseVersion>ElevenG</DatabaseVersion>
</ScriptsFolderInformation>
I asked the redgate support and got a reply.
It seems to work just fine when you work with the schemas directly (haven't tried it myself). The problem only happens when you do the scripts folder to scripts folder comparison.
To get the partition working you have to drop the NOCACHE keyword. Then everything is working.
Redgate now has a bug report for the support of those keywords (OC-1026)
Here's the version that works:
create table MY_SCHEMA.MY_TEST_AUDT (
TEST_ID NUMBER(19),
-- all sorts of business fields, omitted for clarity
AUDT_CRT_DTM TIMESTAMP DEFAULT SYSTIMESTAMP,
AUDT_ACTN_CODE VARCHAR2(1),
AUDT_CRT_USR_NM VARCHAR2(128) DEFAULT USER,
AUDT_CLIENT_IDENTIFIER VARCHAR2(256),
AUDT_CLIENT_INFO VARCHAR2(256)
)
TABLESPACE MY_TABLESPACE
PCTFREE 0
INITRANS 10
STORAGE (
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
COMPRESS FOR OLTP;

error sql at level 1 insufficient privilage oracle

SQL> flashback table ticket to timestamp TO_TIMESTAMP('13-11-2018 22:30:56',
'dd-mm-yyyy hh24:mi:ss');
flashback table ticket to timestamp TO_TIMESTAMP('13-11-2018 22:30:56',
* 'dd-mm-yyyy hh24:mi:ss')
ERROR at line 1:
ORA-00604 : error occurred at recursive SQL level 1
ORA-01031 : insufficient privileges
P.S. : I already added flashback any table system privilege.
Most probably you have a trigger such as after event type which contains some operations that prevent you perform your command line operations related with them. Try to disable those triggers, and then retry flashback table ...
To detect the obstacle, use :
select owner, trigger_name
from user_triggers -- for current schema, might be replaced with "dba_triggers" for the whole
where trigger_type = 'AFTER EVENT';

What is Oracle error ORA-01536?

I got the following error on Oracle: ORA-01536
What is the problem?
The online documentation includes a book with explanations and resolutions for all the error messages. Some of them are a bit cryptic but it is the place to start. Find out more.
Anyhoo, here is an illustrated solution for ORA-01536.
A DBA creates a new user:
SQL> create user fox_in_socks identified by tweetlebeetle
2 default tablespace users quota 1M on users
3 /
User created.
SQL> grant create session, create table to fox_in_socks
2 /
Grant succeeded.
SQL>
In another session our brave user creates a table...
SQL> conn fox_in_socks/tweetlebeetle
Connected.
SQL> create table t23 (col1 varchar2(4000))
2 /
Table created.
SQL>
.. and does some work....
SQL> begin
2 for i in 1..1000 loop
3 insert into t23 values (rpad('a', 4000, 'a'));
4 commit;
5 end loop;
6 end;
7 /
begin
*
ERROR at line 1:
ORA-01536: space quota exceeded for tablespace 'USERS'
ORA-06512: at line 3
SQL>
Uh-oh! So our user goes to their tame DBA and asks for more quota, which they get:
SQL> alter user fox_in_socks
2 quota 10M on users
3 /
User altered.
SQL>
Work proceeds:
SQL> begin
2 for i in 1..1000 loop
3 insert into t23 values (rpad('a', 4000, 'a'));
4 commit;
5 end loop;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL>
If the user were an application owner then the DBA could have decided to give them unlimited quota (especially if they were the only user with privileges on that tablespace):
alter user fox_in_socks
quota unlimited on users
/
(in real life this situation is unlikely to be true for the USERS tablespace).
Users can check their current quota using the appropriate view:
SQL> select * from user_ts_quotas
2 /
TABLESPACE_NAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS DRO
------------------------------ ---------- ---------- ---------- ---------- ---
USERS 9437184 10485760 1152 1280 NO
SQL>
ORA-01536: space quota exceeded for tablespace 'string'
Cause: The space quota for the segment owner in the tablespace has been exhausted and the operation attempted the creation of a new segment extent in the tablespace.
Action: Either drop unnecessary objects in the tablespace to reclaim space or have a privileged user increase the quota on this tablespace for the segment owner.

MView problem after dropping it

i,
I have one Materialized view on one server which is created by DB link .
There is one job running on that Mview.(craeted with dbms_refresh.make earlier).
Now I have craeted 3 new fields in original table.
there was job running on the Mview, I dropped the job by DBMS_refresh.destroy.
Then dropped the Mview ( i forgot to drop Indexes on view)
Now when i am trying to create the Mview with SQL which i sxtracted before,
It is giving error as :-
Error starting at line 1 in command:
CREATE MATERIALIZED VIEW TTMU_LAVORAZIONE_TT
TABLESPACE "TTSTAT_DATA"
LOGGING
PCTFREE 10
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE
(
INITIAL 5M
NEXT 5M
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
)
NOCACHE NOPARALLEL BUILD IMMEDIATE
USING INDEX
REFRESH ON DEMAND FAST
WITH ROWID
DISABLE QUERY REWRITE AS
SELECT T288.C1,C2,C3,C4,C5,C6,C7,C8,C536870915,C536870916,C536870917,
C536870918,C536870919,C536870920,C536870921,C536870922,C536870927,
C536870928,C536870929,C536870930,C536870931,C536870932,C536870933,
C536870937,C536870939,C536870940,C536870941,C536870942,C536870945,
C536870951,C536870952,C536870953,C536870954,C536870955,C536870956,
C536870957,C536870959,C536870961,C536870962,C536870965,C536871100
FROM T288#STAT2TTM.WORLD
Error at Command Line:1 Column:0
Error report:
SQL Error: ORA-00600: internal error code, arguments: [17113], [0x000000000],
[], [], [], [], [], []
00600. 00000 - "internal error code, arguments: [%s], [%s], [%s], [%s],
[%s], [%s], [%s], [%s]"
*Cause: This is the generic internal error number for Oracle program
exceptions. This indicates that a process has encountered an
exceptional condition.
*Action: Report as a bug - the first argument is the internal error number
Error starting at line 26 in command:
CREATE UNIQUE INDEX I_SNAP$_TTMU_LAVORAZIONE_T
ON TTMU_LAVORAZIONE_TT (M_ROW$$ ASC)
TABLESPACE "TTSTAT_DATA"
LOGGING
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE
(
INITIAL 5M
NEXT 5M
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
)
Error at Command Line:26 Column:0
Error report:
SQL Error: Closed Connection
the action is pretty clear:
*Action: Report as a bug - the first argument is the internal error number
This is an internal error. Follow instructions from Note [ID 153788.1] Troubleshoot an ORA-600 or ORA-7445 Error Using the Error Lookup Tool on Oracle support site.
You must:
- drop the snapshot/mview
- drop the snapshot log on the master table
- create a new snapshot log on the master table
- recreate your mview and simplify your create statement to the following:
CREATE MATERIALIZED VIEW TTMU_LAVORAZIONE_TT
TABLESPACE "TTSTAT_DATA"
REFRESH FAST START WITH SYSDATE NEXT SYSDATE + 5/1440
WITH ROWID
AS
SELECT T288.C1,C2,C3,C4,C5,C6,C7,C8,C536870915,C536870916,C536870917,
C536870918,C536870919,C536870920,C536870921,C536870922,C536870927,
C536870928,C536870929,C536870930,C536870931,C536870932,C536870933,
C536870937,C536870939,C536870940,C536870941,C536870942,C536870945,
C536870951,C536870952,C536870953,C536870954,C536870955,C536870956,
C536870957,C536870959,C536870961,C536870962,C536870965,C536871100
FROM T288#STAT2TTM.WORLD;
The above will add a refresh dbms_job that brings the table up-to-date every 5 minutes. You can change it to meet your requirements.
After you create it you must run:
exec dbms_snapshot.refresh("TTMU_LAVORAZIONE_TT",'C');
exec dbms_snapshot.refresh("TTMU_LAVORAZIONE_TT",'F');
That should take care of it. You will need to use an alternate method if the table is massive. I don't know the size so i'm assuming not too big.
Check the alert log for the database for clues as to what may be happening in your database. That will likely point you at one or more trace files where more information on the problem can be found. Sometimes you can resolve the problem on your own.

Resources