Atikh's DBA blog
  • Home
  • Oracle
  • MySQL
  • MongoDB
  • PostgreSQL
  • Snowflake
  • About Me
  • Contact Us

Oracle DBA Scripts

 Atikh Shaikh     oracle     8 comments   


Below are some Oracle scripts used in day to day activities note that below script will generate sql statements and then we need to run those statements

Script to capture object level privileges for schema

set head off
set verify off
set feedback off
set echo off
Select 'grant '||privilege||' on '||owner||'."'||table_name||'" to '||grantee||';' from dba_tab_privs where grantor in ('&SCHEMA_NAME');

Script to capture system level privileges for schema

select 'grant '||privilege||' to '||grantee||';' from dba_sys_privs where grantee in ('&SCHEMA_NAME');

Compile INVALID objects in particular schema

select 'alter '||object_type||' ' ||owner||'.'||object_name||' compile;' from dba_objects where status='INVALID' and owner in (‘&SCHEMA_NAME’);

To refresh SELECT Role

select 'Grant select on &SCHEMA_NAME.'||object_name|| ' to SELECT_ROLE_NAME;' from dba_objects where owner='&SCHEMA_NAME' and object_type in ('TABLE','VIEW','SYNONYM','MATERIALIZED VIEW');

To refresh UPDATE role

select 'Grant insert,update,delete on SCHEMA_NAME.'||object_name|| ' to UPDATE_SCHEMA_NAME;' from dba_objects where owner=’SCHEMA_NAME' and object_type in ('TABLE','VIEW','SYNONYM','MATERIALIZED VIEW')
union
select 'Grant execute on SCHEMA_NAME.'||object_name|| ' to UPDATE_ROLE_NAME;' from dba_objects where owner='SCHEMA_NAME' and object_type in ('PROCEDURE','FUNCTION','PACKAGE');

To Enable and Disable constraints on a table

select 'alter table ' || owner || '.' ||'"'|| TABLE_NAME||'"'|| ' disable constraint ' ||'"'|| CONSTRAINT_NAME ||'"'|| ';' from dba_constraints where OWNER='SCHEMA_NAME';

select 'alter table ' || owner || '.' ||'"'|| TABLE_NAME||'"'|| ' enable constraint ' ||'"'|| CONSTRAINT_NAME ||'"'|| ';' from dba_constraints where OWNER='SCHEMA_NAME';

To truncate tables of a schema

select 'truncate TABLE ' ||owner||'.'||object_name||';' from dba_objects where owner='SCHEMA_NAME' and object_type='TABLE'  order by 1 desc;

To kill the sessions

db Level
select 'alter system kill session '''||sid ||','||serial#||''';' from v$session where sid in (2331,1552,261);

OS level
select 'kill -9 '||p.spid from v$session s, v$process p where s.paddr=p.addr and s.sid in (2331,1552,261);

Synonym creation on all the tables of particular schema

select 'create synonym '||object_name||' for ' ||owner||'.'||object_name||';' from dba_objects where owner in ('SCHEMA_NAME') and object_type in ('TABLE');


I will keep this article updated with new scripts. Keep eye on this.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Instagram
  •  Pin
  •  linkedin
  •  reddit
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

8 comments:

  1. Vijayakash27 March 2020 at 13:38

    Top technologies to learn

    Excellent blog with lots of information. I have to thank for this. Do share more.

    ReplyDelete
    Replies
    1. Unknown2 March 2022 at 04:01

      Great Article Artificial Intelligence Projects

      Project Center in Chennai

      JavaScript Training in Chennai

      JavaScript Training in Chennai Project Centers in Chennai

      Delete
      Replies
        Reply
    2. Reply
  2. Vijayakash10 August 2020 at 12:00

    DevOps Training in Chennai

    I am glad that I have visited this blog. Really helpful, eagerly waiting for more updates

    ReplyDelete
    Replies
      Reply
  3. Vijayakash24 October 2020 at 15:45

    Nice blog was really feeling good to read it. Thanks for this information.
    devops interview questions and answers
    devops interview questions and answers for experienced
    java interview questions for freshers
    selenium interview questions and answers pdf download
    digital marketing interview questions and answers for freshers
    hadoop interview questions and answers pdf
    oracle pl sql interview questions

    ReplyDelete
    Replies
      Reply
  4. Vijayakash6 February 2021 at 12:41

    it was so good to read and useful

    Data Science course in Tambaram
    Data Science Training in Anna Nagar
    Data Science Training in T Nagar
    Data Science Training in Porur
    Data Science Training in OMR
    Data Science course in Chennai

    ReplyDelete
    Replies
      Reply
  5. Rupesh Kumar29 August 2023 at 12:15

    I found so many interesting stuff in your blog especially its discussion. Looking for the best way to enhance your spoken English skills in Kuwait? Look no further than Ziyyara Edutech's exceptional online spoken English classes.
    For more info visit Spoken english language Class in kuwait fahaheel

    ReplyDelete
    Replies
      Reply
  6. Anonymous6 November 2023 at 10:49

    Excellent blog, good to see someone is posting quality information. Thanks for sharing this useful information. Are you facing challenges in speaking English fluently? We have the perfect solution for you with our English language classes and courses in Qatar.
    For more info visit English language Class in Qatar

    ReplyDelete
    Replies
      Reply
  7. Anonymous9 November 2023 at 12:40

    I would like to thank you for the wonderful information. Amazing post!. Join the best online English language courses, embark on a journey to fluency, and watch your language skills soar with us!
    Book a free demo today. Learn english online in bahrain

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Author

Atikh Shaikh
View my complete profile

Categories

  • MongoDB (18)
  • Oracle 12c (30)
  • Oracle12cR2 New Feature (3)
  • PostgreSQL (20)
  • RMAN (10)
  • Snowflake (8)
  • mysql (23)
  • oracle (74)

Blog Archive

  • ▼  2018 (38)
    • ▼  November (25)
      • Introduction On MySQL
      • SQL Modes in MySQL
      • MySQL Version explained
      • MySQL Storage Engines (Part 1)
      • MySQL Storage Engines (Part 2)
      • Login to MySQL Database on Linux
      • Error Code: 1419. You do not have the SUPER privil...
      • Create MySQL database on Linux
      • Create New User in MySQL Database
      • MySQL Default database | MySQL System Database
      • Oracle ASM Basic Commands
      • Oracle Database Schema Refresh
      • Create User in Oracle Database Pre-12c and 12c
      • RMAN Disk backup and List or Report RMAN Backup
      • RMAN Backup of Single Datafile and List Backup
      • Difference Between User, Service account and Schem...
      • Create MySQL Database Backup | mysqldump mysqlbackup
      • Switching between ARCHIVELOG Mode and NOARCHIVELOG...
      • Introduction to MongoDB
      • Introduction to PostgreSQL
      • Installation of PostgreSQL 9.6 on Windows
      • Installation of MongoDB on Windows
      • Oracle DBA Scripts
      • Databases, Collections and Documents in MongoDB
      • CRUD (Create, Read, Update, Delete) Operations in ...
    • ►  December (13)
  • ►  2019 (33)
    • ►  January (15)
    • ►  February (6)
    • ►  March (2)
    • ►  April (5)
    • ►  May (5)
  • ►  2020 (5)
    • ►  April (1)
    • ►  May (2)
    • ►  July (2)
  • ►  2021 (8)
    • ►  June (3)
    • ►  July (3)
    • ►  August (1)
    • ►  December (1)
  • ►  2022 (33)
    • ►  May (3)
    • ►  June (10)
    • ►  July (3)
    • ►  August (4)
    • ►  September (8)
    • ►  October (3)
    • ►  November (2)
  • ►  2023 (14)
    • ►  February (1)
    • ►  April (5)
    • ►  May (2)
    • ►  June (1)
    • ►  September (1)
    • ►  October (1)
    • ►  December (3)
  • ►  2024 (5)
    • ►  January (2)
    • ►  March (3)
  • ►  2025 (6)
    • ►  March (1)
    • ►  April (3)
    • ►  May (2)

Popular Posts

  • ORA-29283: invalid file operation: unexpected "LFI" error (1509)[29437]
    I was trying to export the schema in my windows PC, it got stuck with below error    C:\Users\shaik\Videos\technodba exp>expdp userid...
  • PostgreSQL : How to get data directory location for PostgreSQL instance
    Sometimes, you start working on a PostgreSQL instance but forget about the data directory, here we will discuss different methods to know th...
  • Oracle 23ai : Use of NOVALIDATE Constraints in IMPDP
    While performing impdp operations in the Oracle database, Oracle performs validation checks for every constraint on the imported table, that...
  • ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
    In previous articles, we have learned about user creation and grants  in MySQL in detail, but there are a few privileges called global priv...
  • Oracle Dataguard Broker Configuration (DGMGRL)
    Data Guard Broker is a command-line interface that makes managing primary and standby databases easy. DBA can use a single command to switch...

Labels

oracle Oracle 12c mysql PostgreSQL MongoDB oracle 19c Oracle23c oracle19c Orale PDB-CDB oracle12c python AWS Oracle ASM Virtualbox pluggable database storage engine

Pages

  • Disclaimer
  • Privacy Policy

Follow TechnoDBA

Copyright © Atikh's DBA blog | Powered by Blogger