Skip to main content
Some useful query for Oracle DBA advance to novice



/* 
To show primary/foreign key relationships of all tables and views in a given schema 
*/

SELECT D.TABLE_NAME "Table name",
         D.CONSTRAINT_NAME "Constraint name",
         DECODE (D.CONSTRAINT_TYPE,
                 'P', 'Primary Key',
                 'R', 'Foreign Key',
                 'C', 'Check/Not Null',
                 'U', 'Unique',
                 'V', 'View Cons')
            "Type",
         D.SEARCH_CONDITION "Check Condition",
         P.TABLE_NAME "Ref Table name",
         P.CONSTRAINT_NAME "Ref by",
         M.COLUMN_NAME "Ref col",
         M.POSITION "Position",
         P.OWNER "Ref owner"
    FROM DBA_CONSTRAINTS D
         LEFT JOIN DBA_CONSTRAINTS P
            ON (D.R_OWNER = P.OWNER AND D.R_CONSTRAINT_NAME = P.CONSTRAINT_NAME)
         LEFT JOIN DBA_CONS_COLUMNS M
            ON (D.CONSTRAINT_NAME = M.CONSTRAINT_NAME)
   WHERE D.TABLE_NAME IN (SELECT TABLE_NAME
                            FROM DBA_TABLES
                           WHERE OWNER = UPPER ('STLBAS')
                          UNION ALL
                          SELECT VIEW_NAME
                            FROM DBA_VIEWS
                           WHERE OWNER = UPPER ('STLBAS'))
ORDER BY 1, 2, 3

/*
 To see all objects in a table space file
*/
SELECT D.OWNER,
       D.SEGMENT_NAME,
       D.SEGMENT_TYPE,
       D.TABLESPACE_NAME,
       D.HEADER_FILE,
       V.NAME
  FROM Dba_Segments D JOIN V$DATAFILE V ON (D.HEADER_FILE = V.FILE#)
 WHERE D.OWNER IN ('STLBAS')

/* To see size of your tables and indexes) */
SELECT SEGMENT_NAME, SEGMENT_TYPE, BYTES
  FROM USER_SEGMENTS
 WHERE segment_type IN ('TABLE', 'INDEX')


/* To see free spaces in table spaces */
  SELECT b.tablespace_name,
         b."Total MB",
         ROUND (b."Total MB" - a."Free MB", 2) "Used MB",
         a."Free MB",
         ROUND ( ( (b."Total MB" - a."Free MB") / b."Total MB") * 100, 2)
            "% used"
    FROM (   (  SELECT f.tablespace_name,
                       ROUND (SUM (f.bytes / (1024 * 1024)), 2) "Free MB"
                  FROM dba_free_space f
              GROUP BY f.tablespace_name) a
          RIGHT JOIN
             (  SELECT d.tablespace_name,
                       ROUND (SUM (d.bytes / (1024 * 1024)), 2) "Total MB"
                  FROM dba_data_files d
              GROUP BY d.tablespace_name) b
          ON a.tablespace_name = b.tablespace_name)
ORDER BY 1

/* Which user executing what type of command */
SELECT SID,
       SERIAL#,
       v.schemaname,
       DECODE (COMMAND,
               0, 'None',
               2, 'Insert',
               3, 'Select',
               6, 'Update',
               7, 'Delete',
               8, 'Drop',
               26, 'Lock Table',
               44, 'Commit',
               45, 'Rollback',
               47, 'PL/SQL Execute',
               'Other')
          command
  FROM V$SESSION v


-- cheers !!!

Comments

Popular posts from this blog

Checking operating system version: must be 5.0, 5.1 or 5.2 Actual 6.1 Failed

This error occurred when we are installing old oracle software in latest OS (Operating System).   Basically Its’s occurring on windows platform.

Oracle forms 11g default configuration file formsweb.cfg

#formsweb.cfg defines parameter values used by the FormsServlet # formsweb.cfg defines parameter values used by the FormsServlet (frmservlet) # This section defines the Default settings. Any of them may be overridden in the # following Named Configuration sections. If they are not overridden, then the # values here will be used. # The default settings comprise two types of parameters: System parameters, # which cannot be overridden in the URL, and User Parameters, which can. # Parameters which are not marked as System parameters are User parameters. # SYSTEM PARAMETERS

Windows 8 boot loader corrupted

Problem:     Installed Windows 7 and Windows 8 in EFI mode on a hard disk some days past. Today, the boot loader is absent or corrupted. At present have the Windows 8 installer on a flash drive and tried using the Automatic Repair option to repair the boot loader but it didn't do anything. The Startup Repair option is also absent in the Windows 8 installer. How I can repair or recreate the EFI boot loader from the Command Prompt? BCDEDIT   returns the following message: The requested system device cannot be found. Solution: Firstly, boot from a UEFI Windows 8 recovery disk (CD/DVD/USB) - I found that the automated recovery process didn't find the correct Windows partition, nor when I managed to add it to BCD settings would it make it reliably boot-able e.g. using BCDEDIT I got it to find and launch the Windows partition but it refused to cold boot or would not "keep" the settings after a 2nd reboot or power off. Go into the Advanced option