Grant truncate

Hi,
on 11G R2,
We want to grant truncate any table to a user.
How ?
We should create the following procedure ?
1. Create the procedure to truncate the table.
create or replace procedure truncate_table (
table_name varchar2,
storage_type varchar2)
as
crsor integer;
rval integer;
begin
dbms_output.put_line('Truncating Table : '|| table_name ||
' Storage : '|| storage_type);
crsor := dbms_sql.open_cursor;
dbms_sql.parse(crsor, 'truncate table '|| table_name ||
' '|| storage_type ,dbms_sql.v7);
rval := dbms_sql.execute(crsor);
dbms_sql.close_cursor(crsor);
end;
grant execute on <procedure_name> to <user>Is it for only one table ? If yes how to do that for all tables ? Or the tables of a schema ?
Thank you.

Pl see previous discussions on this topic - use the search feature to find threads like these -
Privilege for truncating a table
Truncate table in another schema without drop any table privilege
HTH
Srini

Similar Messages

  • Can grant truncate table permission to a user?

    Whether can grant  truncate table permission to a user separately.
    I know that the role db_ddladmin can do,but the create,alter and drop permissions will be granted the same time(These permissions are not what we want to
    grant to user).
    Is there any solution?
    Best regards!!
    If you haven't all the things you want,be grateful for the things you don't have that you didn't want.

    You can't grant truncate because for whatever reason, that permission doesn't exist.  What you can do is use a stored procedure and use EXECUTE AS OWNER to get around it.
    create database foo
    go
    create login foobar with password = 'alkdsfji9eorngv';
    go
    use foo
    go
    create user foobar from login foobar;
    go
    create table test(rowid int identity)
    go
    insert into test default values;
    go
    select * from test
    go
    create procedure dbo.truncate_test
    with execute as owner
    as
    truncate table test
    go
    grant execute on dbo.truncate_test to foobar
    go
    execute as login='foobar'
    execute dbo.truncate_test
    revert
    go
    select * from test
    go
    use master
    go
    drop database foo
    drop login foobar
    This keeps your database safe and allows you to grant execute on the truncate procedure to allow them to truncate the table.Jonathan Kehayias
    http://sqlblog.com/blogs/jonathan_kehayias/
    http://www.twitter.com/SQLSarg
    http://www.sqlclr.net/
    Please click the Mark as Answer button if a post solves your problem!

  • Sql query to grant TRUNCATE permission to a table

    Need help to write sql query to grant TRUNCATE permission to a table

    sujnan wrote:
    Need help to write sql query to grant TRUNCATE permission to a tableThis would require DROP ANY TABLE privilege.
    However, this is a rather powerful privilege and should not be granted to non admin users.
    Alternatively you can create a stored procedure in table owner's schema which would truncate specified table.
    Grant execute rights on this SP only to required users.
    See an example below:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1458414958491
    You could(rather should) put in more validations in this SP to prevent users from truncating tables that they are not supposed to.

  • Can I give access to truncate one table only ?

    Hi,
    We have system where it is deleting one table and inserting records using pro-cobol in a table owned by another schema. It means user b is inserting records in a's table i.e. t. Can I give access to truncate only a.t ? delete any table or drop any table will give access to b to truncate any table in 'a'. I do not want this. How can I achive this ?
    thanks & regards
    PJP

    As Justin already said there is no separate right to simple GRANT TRUNCATE ON TABLE to user.
    From the docs: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10006.htm#sthref9966
    To truncate a table or cluster, the table or cluster must be in your schema or you must have DROP ANY TABLE system privilege.
    So the best way would be to encapsulate this login in a packaged procedure as described by Justin.

  • Provide truncate table permission for a user

    Please let me know the best possible way to provide truncate table permission to a SQL Server Database user (ddl_admin role cannot be granted to the user in my case)

    Grant CONTROL permissions on table, user will be able to truncate table.
    GRANT CONTROL ON user_table TO User
    http://www.sqlservercentral.com/blogs/steve_jones/2011/03/07/sql-server-truncate-table-permissions/
    Other ways check this:
    Grant Truncate Table Permissions in SQL Server without ALTER Table  
    http://www.mssqltips.com/sqlservertip/2583/grant-truncate-table-permissions-in-sql-server-without-alter-table/
    The ALTER permission provides the access required to alter the schema of a tables, this includes truncating the data in the table.
    http://www.jasonstrate.com/2013/05/security-questions-truncate-table-permissions/

  • Truncate Privilge

    Hi all,
    I want to truncate a Table of USER A from USER B.
    Could any body tell what is GRANT permission to give for truncating a table..?
    Thanks.

    It's the only way to grant truncate privilge to a user, an alternative method can be :
    - logged as userA (which owns the table you want to truncate) : you create a procedure that realize the truncate operation :
    create procedure trunc_t is
    begin
    execute immediate ('truncate table t');
    end;
    /and grant execute privilege to userB on this procedure :
    grant execute on trunc_t to userB;- logged as userB :
    connect userb/userb
    execute usera.trunc_t;

  • Help with truncating a table using plsql procedure in different schema

    I have a plsql procedure in schema A that truncates a table that is given in as parameter.
    create or replace procedure truncate_table(schema, table_name)
    EXECUTE IMMEDIATE 'TRUNCATE TABLE '||schema||'.'||table_name;
    end;
    The above procedure has public execute grant.
    I need to truncate a table in schema B. I have a plsql procedure in schema B that calls the truncate_table procedure and passes in the schema B table name.
    Since the table is in schema B, should the delete grant on the table be given to user A or user B to truncate the table in schema B?
    Thanks in advance.

    Procedure created in schema A
    create or replace
    procedure truncate_table(l_schema varchar2, table_name varchar2) authid current_user
    as
    begin
    EXECUTE IMMEDIATE 'TRUNCATE TABLE '||l_schema||'.'||table_name;
    end;from schema B
    grant delete on table1 to Schema_A
    from schema A
    exec truncate_table('Schema_B','Table1');
    Hope this helps.
    Alvinder

  • TRUNCATE TABLE NOT WORKING AFTER DROPPING CONSTRAINTS

    Hi,
    I have a table with a foreign key constraint. I know you can't truncate tables when there are foreign key constraints. So I drop the constraints before running the TRUNCATE TABLE command. But SQL Server is still stating there are foreign key constraints
    even after they have just been dropped.
    When I use SQL Server Management Studio to generate a drop & create script on this table or any other table with an FK consttaint, the generated script fails stating that there are still foreign key constraints??
    I have the same problem for every table that has FK constraints, for those without FK, TRUNCATE table works without issues.
    The end goal is to reset the identity value of the primary key. Since DBCC does not work on Azure, TRUNCATE TABLE is the only way left, especially if you can't even drop and recreate tables with FK constraints.
    What am I missing here?
    Peter

    Hi,
    Thanks for posting here.
    TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.
    TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes, and so on remain. To remove the table definition in addition to its data, use the DROP TABLE statement.
    If the table contains an identity column, the counter for that column is reset to the seed value defined for the column. If no seed was defined, the default value 1 is used. To retain the identity counter, use DELETE instead.
    Restrictions
    You cannot use TRUNCATE TABLE on tables that:
    •Are referenced by a FOREIGN KEY constraint. (You can truncate a table that has a foreign key that references itself.)
    •Participate in an indexed view.
    •Are published by using transactional replication or merge replication.
    For tables with one or more of these characteristics, use the DELETE statement instead.
    TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. For more information, see CREATE TRIGGER (Transact-SQL).
    Truncating Large Tables
    Microsoft SQL Server has the ability to drop or truncate tables that have more than 128 extents without holding simultaneous locks on all the extents required for the drop.
    Permissions--------------------------------------------------------------------------------
     The minimum permission required is ALTER on table_name. TRUNCATE TABLE permissions default to the table owner, members of the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and are not transferable. However, you
    can incorporate the TRUNCATE TABLE statement within a module, such as a stored procedure, and grant appropriate permissions to the module using the EXECUTE AS clause.
    You cannot truncate a table which has an FK constraint on it.
    Typically my process for this is:
    Drop the constraints
    Trunc the table
    Recreate the constraints.
    Hope this helps you.
    Girish Prajwal

  • Bug 3.2.20.09 Build MAIN-09.87 - Using GUI to truncate - Wrong table

    Here is what I am running into with this version of SQL developer. I can repeat this issue every time with these steps.
    From Connections, open a connection, list tables.
    Right click on table, select Privileges - Grant. Select the user ID, the actions & Apply. (you do not need to take these action, just go through the motions)
    At this point it does not seem to matter if I stay within this connection or select a different connection.
    Select a different table by clicking on it so it opens a new tab.
    Select Actions - Table - Truncate.
    At this point you would expect the pop-up to display the table you are trying to take action on, instead what happens is you are presented with the last table you took Privilege actions on. This will even open a closed connection to take these actions on.
    So if you are not paying careful attention, you are about to truncate the wrong table!
    I am also able to repeat this with 3.1.07.42 where you are presented with the last table you went through the motions on for Privileges. (you do not have to take any actions.
    Edited by: user2794298 on Jan 31, 2013 2:55 PM

    Now all I need to know is when this gets corrected so I can download a updated version of SQL Developer to reduce the change of accidently truncating the wrong table again due to a software bug.

  • Privilege for truncating a table of other schema

    Hi friends
    I need to truncate a table of other schema. What privilege the other user has to give to carry out it.
    Thanks
    Edited by: user12892846 on 01-abr-2010 15:59

    DROP ANY TABLEWhile technically correct, above is somewhat dangerous because every schema could be impacted; even SYS.
    Assume SCHEMA_A owns TABLE_A & procedure below.
    CREATE & REPLACE PROCEDURE TRUNCATE_TABLE_A
    AS
    BEGIN
    EXECUTE IMMEDIATE 'TRUNCATE TABLE TABLE_A';
    END TRUNCATE_TABLE_A;
    GRANT EXECUTE ON TRUNCATE_TABLE_A TO SCHEMA_B;
    By doing as above SCHEMA_A can control who & which table(s) can be impacted (in is own schema only).
    Edited by: sb92075 on Apr 1, 2010 7:06 PM

  • Truncate db throws exception

    Hi All,
    I have two processes, one creates environement in RW mode, creates a transactional database(s), writes n records, and closes it.
    Another process opens the same env (by this I means same directory), in RO mode (I understand this gives snapshot view as of open time), finds all databases in that environment (getDatabaseNames), if works on that data put in by process 1, and truncates the db. Truncate throws foll. error.
    com.sleepycat.je.DeadlockException: (JE 3.2.13) Lock expired. Locker 250_main_Txn: waited for lock on database=_jeNameMap node=34 type=WRITE grant=WAIT_PROMOTION timeoutMillis=500 startTime=1187817739998 endTime=1187817740998
    Owners: [<LockInfo locker="250_main_Txn" type="READ"/>, <LockInfo locker="-1_main_BasicLocker" type="READ"/>]
    Waiters: []
    Transaction 250_main_Txn owns 34 <LockInfo locker="250_main_Txn" type="READ"/>
    Transaction 250_main_Txn waits for node 34
    How to address this ?
    Logically this is what I am trying to do. Process 1 accumulates new data and Process 2 processes the data once a number of new records created by P1 reach a threshold. Once processed, it wants to drop those records. I thought easiest way is to do truncate.
    P1 uses databases in a circular fashion (much like redo logs). Say there are 5 databases to start with, P1 places records into DB1, then DB2, ..and uses DB1 again after DB5. In the mean time, P2 should have emptied records from DB1 etc when P1 returns to it. P2 cannot open the databases in RW mode for obvious reasons, so it cant delete records. P1 closes db soon it writes threshold # of records.
    Any suggestions on how I might go about this ?
    Thanks
    Vissu

    Hi Vissu,
    Truncating a database is a write operation, so you can't do it in a read-only environment.
    If you must write the data in one process and read/truncate it in another, then the only ways I think of doing that are:
    1) The writer process must close the environment while the reader/truncator process truncates it. This is difficult since it requires coordinating the two processes.
    2) Instead of rotating through 5 databases, rotate through 5 environments (each with a single database). That way, the reader/truncator can open the environment read-write, after it has been closed by the writer.
    I recommend trying (2). Of course, things will be much simpler if you can use a single process for reading, reading and truncating.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • URL truncated from text file

    Hi,
    I have stored my url into a text file. it seems that my url
    are truncate if there are bigest than 132 or 134 caracters.
    I don't think it is a '&' problem because I have replaced
    all them with the '%26' char .
    I call a generic asp page and pass it a url with arguments
    Is there any limitation in Flash with url ?
    Do I have to use xml file to workaround this problem ?
    See the content of my text file here
    Thanks a lot for all your reply

    i created a directory object mani as /king/heep on oracle database server, granted read, write access on mani to myusernow i created a text file ( abc.txt ) using utl_file package .
    thence i want to display this text file in web browser using web.show_document(url, '_blank') .
    what should be url for this file to be displayed ???>
    To make the file available over a URL you need a web server and your file has to be hosted on that web server.
    BTW, that has nothing to do with Forms, the subject of this forum.

  • Invalid grants in omwb generated ddl

    The sybase database I am migrating from appears to have granted 'update statistics', 'delete statistics', and 'truncate table' privileges on specific tables. The omwb generated grant statements for these privileges in the ddl which is invalid. I likely will be generating scripts for this database as well as others quite a bit over the next few months I was wondering if there is a way to configure either before/after capturing the source to prevent it from making its way into the generated ddl.
    thanks

    Hello,
    After your capture /convert, you can generate the migration scripts to a file instead of creating the database directly from the OMWB.
    Action > Generate Migration Scripts
    You can then modify the script to your needs . Then run it in SQL*Plus to create your database.
    I hope this helps
    Dermot

  • How to truncate  schema1 table from schema 2 -URGENT

    Hi all
    Please tell me is there any grant like that
    regards

    IS this
    grant drop any table to schema 2
    only way PapinRTFM: http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_107a.htm
    Prerequisites
    To truncate a table or cluster, the table or cluster must be in your schema or you must have DROP ANY TABLE system privilege. :)

  • Execute immediate    : permition denied  for TRUNCATE talble

    Hi
    In my package I have Execute immedidate
      EXECUTE IMMEDIATE 'TRUNCATE TABLE  MYTABLE'; Return me permission denied , I must to veirfy with DBA my permissions
    My ask is : is there some statment in package/procedure that I do not rembember that let it with permissions ?
    I remember something like authid
    Somebody know ?

    SQL> create user u1 identified by u1;
    User created.
    SQL> grant dba to u1;
    Grant succeeded.
    SQL> connect u1/u1
    Connected.
    SQL> exec execute immediate 'truncate table scott.emp1';
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2  procedure p1
      3  is
      4  begin
      5  execute immediate 'truncate table scott.emp1';
      6  end;
      7  /
    Procedure created.
    SQL> exec p1
    BEGIN p1; END;
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "U1.P1", line 4
    ORA-06512: at line 1
    SQL> connect / as sysdba
    Connected.
    SQL> grant drop any table to u1;
    Grant succeeded.
    SQL> connect u1/u1
    Connected.
    SQL> exec p1
    PL/SQL procedure successfully completed.
    SQL> SY.

Maybe you are looking for

  • Recovering Deleted iCloud Calendars

    I accidentally deleted my iCloud Home and Work calendars in Outlook on my work PC.  I honestly had not thought that it would delete them from iCloud and not just Outlook.  My mistake.  I tried to restore them by searching for "calendars" in Spotlight

  • Slow downloads

    I contacted Apple because upon trying to update my iPad Air 2 to ios 8.1.3 the download time was in excess of 24 hours!  This is using a MacBook Pro Retina on a wired 20Mbps DSL line.  I was told that this was normal!  I think not!!!!  Especially whe

  • Unattended.xml : remove a child item containing a value

    Hi all, I have in a section :         <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xml

  • Refund on OSX Mountain Lion?

    Hello! Help! I just (10 mins ago) bought OSX Mountain Lion from the app store, and I only bought my Macbook air a few days ago, so I assumed that it would just be free - with the up to date program. I then checked my bank and the $20.99 has come out,

  • Raid support on 3120

    �X     The Sun StorEdge 3120 SCSI Array is a JBOD system that appears to acts like a RAID 1 storage device. What happens when disk fails? Does it failover to the other drive with it��s data intact? If so, how does this happen?