home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / CATALOG5.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  50.9 KB  |  1,184 lines

  1. rem 
  2. rem $Header: catalog5.sql 7020100.1 94/09/23 22:14:49 cli Generic<base> $ catalog5.sql 
  3. rem 
  4. Rem Copyright (c) 1988 by Oracle Corporation
  5. Rem NAME
  6. Rem   CATALOG5.SQL
  7. Rem FUNCTION
  8. Rem   Create V5 catalog views.
  9. Rem NOTES
  10. Rem
  11. Rem   This script must be run while connected to SYS.
  12. Rem
  13. Rem MODIFIED
  14. Rem     wmaimone   12/17/93 -  merge changes from branch 1.11.710.1
  15. Rem     wmaimone   10/08/93 -  #(176646) change type in tabauth$,colauth$ view
  16. Rem     dleary     11/12/92 -  add OER(2024) not exists error 
  17. Rem     mmoore     11/05/92 -  update tabauth$ 
  18. Rem     mmoore     06/02/92 - #(96526) remove v$enabledroles 
  19. Rem     rlim       07/31/91 - added remarks column to syscatalog view 
  20. Rem     rlim       07/30/91 - added remarks column to syscatalog_ & catalog
  21. Rem     mmoore     05/24/91 - fix security views (upgrade for v7 dict)
  22. Rem     rlim       04/29/91 - change char to varchar2 
  23. Rem   Chaudhr    06/04/90 - assorted bug fixes
  24. Rem                       - 28120: Add REMARKS & fix WIDTH col's in SYSCOLUMNS_
  25. Rem                       - 28121: In SYSTABAUTH & SYSUSERAUTH put ' ' for 'N'
  26. Rem   Chaudhr    01/29/90 - bug 29307
  27. Rem   Mendels    03/28/89 - bug 19583: sysindexes_ returns wrong value for seq
  28. Rem   Mendels    11/14/88 - fix bug 16011; create public synonyms
  29. Rem   Mendels    10/25/88 - fix not exists errors
  30. Rem   Bulchan    09/21/88 - Remove '#', ensure statements are < 2048 chars.
  31. Rem   Mendels    09/21/88 - remove public from system synonyms
  32. Rem   Mendels    09/12/88 - remove connect
  33. Rem   Mendels    09/08/88 - bug 15135
  34. Rem   Mendels    08/30/88 - fix bug 14772 (tab view returns indexes)
  35. Rem                         fix bug 9981 (decode type 69 as rowid)
  36. Rem   Peeler     07/26/88 - address compatibility issues
  37. Rem   Wijaya     07/22/88 - merge catsystem.sql
  38. Rem   Wijaya     06/21/88 - add clusters view
  39. Rem   Wijaya     04/27/88 - remove REMARKS and any references to comment$
  40. Rem                         comments are now stored in com$
  41. Rem   Mendels    03/25/88 - do not return dropped tablespaces (and their files)
  42. Rem                         or dropped rollback segments
  43. Rem   Mendels    03/22/88 - Fix audit_actions for v6; 
  44. Rem                         move sequence and constraint views to catalog.sql
  45. Rem   Harmon     03/22/88 - add sequence views
  46. rem Chris   22-mar-88 added sequence catalogs
  47. rem Mendels 15-Mar-88  Rename to catalog5.sql
  48. rem Hong    Revised 02-Mar-88  new undo status
  49. rem Wijaya  Revised 16-Feb-88  new dictionary table icol$
  50. rem Hong    Revised 01-Feb-88  Fix sysfiles to use actual file names and
  51. rem                            not to display invalid file entries
  52. rem Wijaya  Revised 20-Jan-88  Add views for constraints
  53. rem Wijaya  Revised 04-Dec-87  Add REMARKS column to view TAB
  54. rem Wijaya  Revised 20-Nov-87  Add views and synonyms for fixed tables
  55. rem Mendels Revised 05-Nov-87  Make sysfiles an outer-join.
  56. rem Wijaya  Revised 13-Oct-87  undo the fix below, because the bug is in cri.c
  57. rem Hong    Revised 13-Oct-87  fix sysindexes to consider cluster indexes with
  58. rem                   no entries in col$
  59. rem Wijaya  Revised 12-Oct-87  add VARCHAR consideration
  60. rem Hong    Revised 27-Aug-87  pctfree/pctused moved to tab$, clu$
  61. rem Hong    Revised 09-Aug-87  decode column types in 'col'
  62. rem Hong    Revised 05-Aug-87  add view 'freespace'
  63. rem Hong    Revised 27-Jul-87  modify view 'tabspaces' to consider users with
  64. rem                   resource priv has access to ALL tablespaces
  65. rem Hong    Revised 16-Jun-87  create views with names ended in underscore
  66. rem                   (e.g. syscatalog_). These views return user id
  67. rem                   and make views created using them more efficient
  68. rem Hong    Revised 10-Jun-87  dictionary updates
  69. rem Hong    Revised 15-Apr-87  audit$ moved from sys.obj$ to sys.tab$,sys.view$
  70. rem Hong    Revised 04-Apr-87  Add sysfiles, modify systaballoc, storage,
  71. rem                   (sys)extents, syscolumns, syscatalog,
  72. rem                   (sys)indexes, (sys)tabspacesb
  73. rem Hong    Revised 26-Mar-87  Rewrite for version 6 dict. 
  74. rem                   Combine catalog.ora and newcat.ora
  75. rem                   Remove spaces, partitions, progs, exptab, expvew
  76. rem                   Add tablespaces, tsquotas, undoseg, database
  77. rem Andy    Revised 24-Sept-86 Modify views synonyms, privatesyn, and publicsyn
  78. rem                   to show synonyms for non-existent, local tables
  79. rem Andy    Revised 17-Sept-86 Modify views synonyms, privatesyn, and 
  80. rem                   publicsyn to show synonyms for remote tables
  81. rem Derry   Revised 29-Jul-86  Create views for DBLINKS table, 5.2.
  82. rem Andy    Revised 25-Oct-85  Make view partitions an outer join.
  83. rem Andy    Revised 09-Oct-85  Replace sytemaudit, defaultaudit, and 
  84. rem                            systabaudit with SYSTEM_AUDIT, DEFAULT_AUDIT,
  85. rem                            and TABLE_AUDIT.  Added AUDIT_DBA, AUDIT_EXISTS,
  86. rem                            AUDIT_CONNECT, AUDIT_ACCESS.
  87. rem                            Deleted views syssessions and sysaudit_trail.
  88. rem                            Made sessions a synonym for audit_connect.
  89. rem Andy    Revised 15-Jul-85  Change ren$newname to new$name.
  90. rem Derry   Revised 11-Jun-85  Add views CLUSTERS and CLUSTERCOLUMNS.
  91. rem Andy    Revised 06-Jun-85  Add remarks columns to syscatalog, catalog,
  92. rem                            syscolumns, columns, col.  
  93. rem                            Add defaultval column to syscolumns, columns,
  94. rem                            and col.
  95. rem                            Add views and tables for auditing: defaultaudit,
  96. rem                            systemaudit, systabaudit, audit_actions,
  97. rem                            syssessions, sessions, sysaudit_trail, and
  98. rem                            audit_trail.
  99. rem Derry   Revised 24-May-85  Removed SESSIONS since SYS.SESSIONS no longer
  100. rem                   exists (AUDIT_TRAIL views needed).
  101. rem Andy    Revised 08-Feb-85  Qualify column references.
  102. rem                            Rewrite views SYNONYMS, PUBSYN, and PRIVSYN
  103. rem                            for correctness.
  104. rem                            Rewrite views CATALOG, SYSCATALOG, VIEWS,
  105. rem                            and SYSVIEWS for speed.
  106. rem                            Move views back to SYSTEM from SYS.
  107. rem                            Delete views IDX and COLIDX, since view INDEXES
  108. rem                            provides similar information efficiently.
  109. rem                            Rename PRIVSYN to PRIVATESYN and PUBSYN to
  110. rem                            PUBLICSYN.
  111. rem                            Add SET WORKSIZE 16
  112. rem Andy    Revised 26-Nov-84  Convert queries to use EXISTS
  113. rem Miner   Revised 13-Nov-84  Rewrite for new dictionary but it still
  114. rem                   looks much the same to users
  115. rem Dana    Revised 20-Jul-84  Rewrite for speed.  drop views before creating.
  116. rem                   Added COLIDX,IDX,PRIVSYN,PUBSYN,SYNONYMS.
  117. rem                   Renamed DEPENDENCIES to XREF.
  118. rem Dana    Revised 03-Jun-84  update for new V4 dictionary info
  119. rem Dana    Revised 23-May-84  fixed STORAGE not to return all users
  120. rem Clare   Revised 10-May-84  added SYSUSERLIST to DTAB:
  121. rem Clare   Revised 10-May-84  added SYSPROGS:
  122. rem Dana    Revised 23-Apr-84  for V4
  123. rem Weiss   Created 03-Feb-83
  124. rem
  125. rem 
  126. rem
  127. rem there may be no index on a table, therefore need outerjoin
  128. rem there may be more than one indexes, therefore need to max(d.xxxxxx)
  129. rem
  130. create or replace view systaballoc_ 
  131.     ( creator, creatorid, tname, d_blks, d_exts, i_blks, 
  132.                i_exts ) as
  133.   select
  134.     u.name, o.owner#, o.name, d.blocks, d.extents, i.blocks, i.extents
  135.   from sys.user$ u, sys.obj$ o, sys.tab$ t, sys.ind$ x, sys.seg$ d, sys.seg$ i
  136.   where t.obj# = o.obj#
  137.     and o.owner# = u.user#
  138.     and t.file# = d.file# 
  139.     and t.block# = d.block#
  140.     and x.bo# (+) = t.obj#
  141.     and x.file# = i.file# (+)
  142.     and x.block# = i.block# (+)
  143. /
  144. create or replace view systaballoc 
  145.     ( creator, tname, d_blks, d_exts, i_blks, i_exts ) as
  146.   select creator, tname, max(d_blks), max(d_exts), sum(i_blks), sum(i_exts)
  147.   from systaballoc_
  148.   group by creator, tname
  149. /
  150. create or replace view taballoc 
  151.     ( tname, d_blks, d_exts, i_blks, i_exts ) as
  152.   select tname, max(d_blks), max(d_exts), sum(i_blks), sum(i_exts)
  153.   from systaballoc_
  154.   where  creatorid = uid
  155.   group by tname
  156. /   
  157. grant select on taballoc to public with grant option;
  158. rem
  159. rem group all objects which occupies storage: tables, clusters, indexes
  160. rem
  161. create or replace view syssegobj 
  162.     (obj#, file#, block#, type, pctfree$, pctused$) as
  163.   select obj#, file#, block#, 'TABLE', pctfree$, pctused$ from sys.tab$
  164.   union
  165.   select obj#, file#, block#, 'CLUSTER', pctfree$, pctused$ from sys.clu$
  166.   union 
  167.   select obj#, file#, block#, 'INDEX', to_number(null), to_number(null)
  168.          from sys.ind$
  169. /
  170. create or replace view sysstorage_ 
  171.     (creator, creatorid, name, type, storage, extents) as
  172.   select u.name, o.owner#, o.name, so.type, s.blocks, s.extents
  173.   from  sys.user$ u, sys.seg$ s, sys.obj$ o, syssegobj so
  174.   where u.user# = o.owner#
  175.     and o.obj# = so.obj#
  176.     and s.file# = so.file#
  177.     and s.block# = so.block# 
  178. /
  179. create or replace view sysstorage 
  180.     (creator, name, type, storage, extents) as
  181.   select creator, name, type, sum(storage), sum(extents)
  182.   from sysstorage_
  183.   group by creator, name, type
  184. /
  185. create or replace view freespace 
  186.     (tablespace, fileno, starting, length) as
  187.   select ts.name, f.file#, f.block#, f.length
  188.   from sys.ts$ ts, sys.fet$ f
  189.   where f.ts# = ts.ts#
  190. /
  191. create or replace view storage
  192.     (name, type, storage, extents) as
  193.   select name, type, sum(storage), sum(extents)
  194.   from  sysstorage_
  195.   where creatorid = uid
  196.   group by name, type
  197. grant select on storage to public with grant option;
  198. create or replace view sysextents_ 
  199.     (creator, creatorid, name, type,  storage, starting, 
  200.              ending) as
  201.   select u.name, o.owner#, o.name, so.type, e.length, e.block#, 
  202.      e.block#+e.length-1
  203.   from sys.uet$ e, sys.seg$ s, sys.user$ u, sys.obj$ o, syssegobj so
  204.   where e.segfile# = s.file#
  205.     and e.segblock# = s.block#
  206.     and s.user# = u.user#
  207.     and e.segfile# = so.file#
  208.     and e.segblock# = so.block#
  209.     and so.obj# = o.obj#
  210. /
  211. create or replace view sysextents
  212.     (creator, name, which, storage, starting, ending) as
  213.   select creator, name, type, storage, starting, ending
  214.   from sysextents_
  215. /
  216. create or replace view extents
  217.     (name, which, storage, starting, ending) as
  218.   select name, type, storage, starting, ending
  219.   from sysextents_
  220.   where creatorid = uid
  221. /
  222. grant select on extents to public with grant option;
  223. create or replace view syscolumns_ 
  224.     (cname, tname, creator, creatorid, colno, coltype,
  225.             width, scale, precision, nulls, defaultval, remarks) as
  226.   select  c.name, t.name, u.name, t.owner#, c.col#, 
  227.       decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'VARCHAR',
  228.                           12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  229.                           69, 'ROWID', 'UNDEFINED'),
  230.       decode(c.type#, 2, c.precision, c.length),
  231.       c.scale, c.precision,
  232.           decode(c.null$, 0, 'NULL', 'NOT NULL'), c.default$, co.comment$
  233.   from    sys.user$ u, sys.col$ c, sys.obj$ t, sys.com$ co
  234.   where t.type in (2, 4)
  235.     and t.obj# = c.obj#
  236.     and c.obj# = co.obj# (+)
  237.     and c.col# = co.col# (+)
  238.     and    u.user# = t.owner#
  239.     and ( t.owner# = uid
  240.        or t.obj# in
  241.             (select oa.obj#
  242.              from sys.objauth$ oa
  243.              where grantee# in ( select kzsrorol
  244.                                  from x$kzsro
  245.                                ) 
  246.             )
  247.       )
  248. /
  249. create or replace view syscolumns 
  250.     (cname, tname, creator, colno, coltype,
  251.             width, scale, precision, nulls, defaultval, remarks) as
  252.   select cname, tname, creator, colno, coltype, width, scale, precision,
  253.          nulls, defaultval, remarks
  254.   from  syscolumns_
  255. /
  256. grant select on syscolumns to public with grant option;
  257. create or replace view columns 
  258.     (cname, tname, creator, colno, coltype,
  259.              width, scale, precision, nulls, defaultval, remarks) as
  260.   select cname, tname, creator, colno, coltype, width, scale, precision,
  261.          nulls, defaultval, remarks
  262.   from  syscolumns_
  263.   where creatorid not in (0,1)
  264. /
  265. grant select on columns to public with grant option;
  266. create or replace view syscatalog_ 
  267.     (tname, creator, creatorid, tabletype, remarks)
  268.   as  select o.name, u.name, o.owner#,
  269.          decode(o.type, 2, 'TABLE', 4, 'VIEW', 6, 'SEQUENCE','?'), c.comment$
  270.   from    sys.user$ u, sys.obj$ o, sys.com$ c
  271.   where u.user# = o.owner#
  272.     and    o.type in (2, 4, 6)
  273.     and o.obj# = c.obj#(+)
  274.     and ( o.owner# = uid
  275.           or o.obj# in
  276.             (select oa.obj#
  277.              from sys.objauth$ oa
  278.              where grantee# in ( select kzsrorol
  279.                                  from x$kzsro
  280.                                ) 
  281.             )
  282.         )
  283. /
  284. create or replace view syscatalog 
  285.     (tname, creator, tabletype, remarks) as
  286.   select tname, creator, tabletype, remarks
  287.   from syscatalog_
  288. /
  289. grant select on syscatalog to public with grant option;
  290. rem
  291. rem The catalog view returns almost all tables accessible to the user
  292. rem except tables in SYS and SYSTEM ("dictionary tables").
  293. rem 
  294. create or replace view catalog 
  295.     (tname, creator, tabletype, remarks) as
  296.   select tname, creator, tabletype, remarks
  297.   from    syscatalog_
  298.   where creatorid not in (0,2)
  299. /
  300. grant select on catalog to public with grant option;
  301. create or replace view sysindexes_ 
  302.     (iname, icreator, icreatorid, tname, ttype, creator, 
  303.             creatorid, colnames, indextype, compression, seq)  as
  304.   select  oi.name, ui.name, oi.owner#, ot.name, 
  305.       decode(ot.type, 2, 'TABLE', 3, 'CLUSTER', 'UNDEFINED'),
  306.       ut.name, ot.owner#, c.name,
  307.       decode(i.unique$, 1, 'UNIQUE', 'NON UNIQUE'), 
  308.       decode(i.compress$, 1, 'COMPRESS', 'NOCOMPRESS'), ic.pos#
  309.   from sys.user$ ui, sys.user$ ut, sys.ind$ i, sys.obj$ oi, sys.obj$ ot,
  310.        sys.icol$ ic, sys.col$ c
  311.   where i.obj# = oi.obj#
  312.     and i.bo# = ot.obj#
  313.     and i.obj# = ic.obj#
  314.     and ic.col# = c.col#
  315.     and c.obj# = i.bo#
  316.     and    oi.owner# = ui.user#
  317.     and    ot.owner# = ut.user#
  318.     and ot.type in (2, 3)
  319.     and (ot.owner# = uid
  320.          or oi.owner# = uid or
  321.          ot.obj# in ( select obj#
  322.                       from sys.objauth$
  323.                       where grantee# in ( select kzsrorol
  324.                                           from x$kzsro
  325.                                         )
  326.                      )
  327.         )
  328. /
  329. create or replace view sysindexes 
  330.     (iname, icreator, tname, ttype, creator, colnames,
  331.              indextype, compression, seq) as
  332.   select iname, icreator, tname, ttype, creator, colnames, 
  333.      indextype, compression, seq
  334.   from  sysindexes_
  335. /
  336. grant select on sysindexes to public with grant option;
  337. create or replace view indexes 
  338.     (iname, icreator, tname, ttype, creator, colnames,
  339.              indextype, compression, seq) as
  340.   select iname, icreator, tname, ttype, creator, colnames, 
  341.      indextype, compression, seq
  342.   from  sysindexes_
  343.   where    icreatorid = uid
  344.      or creatorid = uid
  345. /
  346. grant select on indexes to public with grant option;
  347. create or replace view clusters 
  348.     (clcreator, clname, tcreator, tname)
  349. as select cu.name, c.name, tu.name, t.name
  350. from sys.user$ tu, sys.user$ cu, sys.obj$ t, sys.obj$ c, sys.tab$ tab
  351. where c.type = 3
  352.   and t.type = 2
  353.   and t.obj# = tab.obj#
  354.   and tab.clu# = c.obj#
  355.   and c.owner# = cu.user#
  356.   and t.owner# = tu.user#
  357.   and (t.owner# = uid
  358.        or c.owner# = uid
  359.        or c.obj# in
  360.             (select oa.obj#
  361.              from sys.objauth$ oa
  362.              where grantee# in ( select kzsrorol
  363.                                  from x$kzsro
  364.                                ) 
  365.             )
  366.       )
  367. /
  368. grant select on clusters to public with grant option;
  369. create or replace view clustercolumns 
  370.     (clcreator, clname, clcol, tcreator, tname, tcol) as
  371.   select cu.name, c.name, cc.name, tu.name, t.name, tc.name
  372.   from   sys.col$ tc, sys.col$ cc, sys.user$ tu, sys.user$ cu,
  373.          sys.obj$ t,  sys.obj$ c, sys.tab$ tab
  374.   where c.type = 3 and t.type = 2
  375.     and    t.obj# = tab.obj#  and tab.clu# = c.obj#
  376.     and    c.obj# = cc.obj#   and t.obj# = tc.obj#
  377.     and    cc.segcol# = tc.segcol#
  378.     and c.owner# = cu.user# and t.owner# = tu.user#
  379.     and (t.owner# = uid or c.owner# = uid
  380.           or c.obj# in
  381.             (select oa.obj#
  382.              from sys.objauth$ oa
  383.              where grantee# in ( select kzsrorol
  384.                                  from x$kzsro
  385.                                ) 
  386.             )
  387.         )
  388. /
  389. grant select on clustercolumns to public with grant option;
  390.  
  391. create or replace view views
  392.     ( viewname, viewtext) as
  393.     select o.name, v.text
  394.     from  sys.view$ v, sys.obj$ o
  395.     where v.obj# = o.obj# and 
  396.         (o.owner# = uid
  397.           or o.obj# in
  398.             (select oa.obj#
  399.              from sys.objauth$ oa
  400.              where grantee# in ( select kzsrorol
  401.                                  from x$kzsro
  402.                                ) 
  403.             )
  404.         )
  405. /
  406. grant select on views to public with grant option;
  407. create or replace view sysviews 
  408.     (viewname, vcreator) as
  409.   select tname, creator
  410.   from  syscatalog
  411.   where tabletype = 'VIEW'
  412. /
  413. grant select on sysviews to public with grant option;
  414. rem
  415. rem Create the security views which emulate the v5 and v6 security tables.
  416. rem 
  417. create or replace view tabauth$ 
  418.     (obj#, grantor#, grantee#, time, sequence#, alter$, 
  419.                       delete$,index$, insert$, select$, update$, references$) as
  420.   select obj#, grantor#, grantee#, to_date(max(null)), min(sequence#),
  421.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  422.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 25, 2), 
  423.       '00', 0, '01', 2, '11', 3, 0),
  424.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  425.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 19, 2), 
  426.       '00', 0, '01', 2, '11', 3, 0),
  427.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  428.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 15, 2), 
  429.       '00', 0, '01', 2, '11', 3, 0),
  430.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  431.        decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  432.               13, 2), '01', 2, '11', 3, 
  433.          decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  434.                 12, '0'), 6, 1), '0', 0, 1)),
  435.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  436.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 7, 2), 
  437.       '00', 0, '01', 2, '11', 3, 0),
  438.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  439.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  440.              5, 2),'01', 2, '11', 3, 
  441.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  442.                  12, '0'), 2, 1), '0', 0, 1)),
  443.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  444.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  445.              3, 2), '01', 2, '11', 3, 
  446.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  447.                  12, '0'), 1, 1), '0', 0, 1))
  448.   from sys.objauth$
  449.   group by obj#, grantor#, grantee#
  450. /
  451. create or replace view colauth$ 
  452.     (obj#, grantor#, grantee#, time, name, 
  453.                       update$, references$, select$, insert$) as
  454.   select oa.obj#, grantor#, grantee#, to_date(max(null)), max(c.name),
  455.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  456.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 5, 2), 
  457.       '00', 0, '01', 2, '11', 3, 0),
  458.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  459.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 3, 2), 
  460.       '00', 0, '01', 2, '11', 3, 0),
  461.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  462.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 7, 2), 
  463.       '00', 0, '01', 2, '11', 3, 0),
  464.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  465.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 13, 2), 
  466.       '00', 0, '01', 2, '11', 3, 0)
  467.   from col$ c, objauth$ oa
  468.   where oa.col# is not null and oa.obj# = c.obj# and oa.col# = c.col#
  469.   group by oa.obj#, oa.col#, grantor#, grantee#
  470. /
  471. create or replace view systabauth 
  472.     (grantor, grantee, creator, tname, timestamp,
  473.                 alt, del, ndx, ins, sel, upd, ref) as
  474.   select ur.name, ue.name, u.name, o.name, tau.time, 
  475.          decode(tau.alter$,  0, ' ', 2, 'Y', 'G'), 
  476.          decode(tau.delete$, 0, ' ', 2, 'Y', 'G'), 
  477.          decode(tau.index$,  0, ' ', 2, 'Y', 'G'), 
  478.          decode(tau.insert$, 0, ' ', 2, 'Y', 'G'), 
  479.          decode(tau.select$, 0, ' ', 2, 'Y', 'G'), 
  480.          decode(tau.update$, 0, ' ', 1, 'R',  2, 'Y', 'G'),
  481.          decode(tau.references$, 0, ' ', 1, 'R',  2, 'Y', 'G')
  482.   from sys.tabauth$ tau, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue
  483.   where tau.obj# = o.obj#
  484.     and o.owner# = u.user#
  485.     and tau.grantor# = ur.user#
  486.     and tau.grantee# = ue.user#
  487.     and (tau.grantor# = uid or tau.grantee# in (select kzsrorol
  488.                                                 from x$kzsro))
  489.   union
  490.   select u.name, u.name , u.name, o.name, to_date(null),
  491.          'G','G','G','G','G','G','G'
  492.   from user$ u, obj$ o
  493.   where u.user# = uid and o.owner# = uid
  494. /
  495. grant select on systabauth to public with grant option;
  496. create or replace view syscolauth 
  497.     (grantor, grantee, creator, tname, timestamp, 
  498.                 colname, upd, ref) as
  499.   select ur.name, ue.name, u.name, o.name, c.time, c.name, 
  500.      decode(c.update$, 2, 'Y', 'G'), decode(c.references$, 2, 'Y', 'G')
  501.   from  sys.colauth$ c, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue
  502.   where c.obj# = o.obj#
  503.     and o.owner# = u.user#
  504.     and c.grantor# = ur.user#
  505.     and c.grantee# = ue.user#
  506.     and (c.grantor# = uid or c.grantee# in (select kzsrorol
  507.                                             from x$kzsro))
  508. /
  509. grant select on syscolauth to public with grant option;
  510. create or replace view sysuserauth 
  511.     (userid, username, password, timestamp, connectauth, 
  512.                  dbaauth, resourceauth, tablespace, tempspace) as 
  513.   select u.user#, u.name, u.password, u.ctime, null, null, null,
  514.      ts.name, tmp.name
  515.   from  sys.user$ u, sys.ts$ ts, sys.ts$ tmp
  516.   where u.datats# = ts.ts# 
  517.     and u.tempts# = tmp.ts#
  518. /
  519. create or replace view sysuserlist 
  520.     (userid, username, timestamp, connectauth, dbaauth, 
  521.              resourceauth, tablespace, tempspace) as
  522.    select userid, username, timestamp, connectauth, dbaauth,  resourceauth, tablespace, tempspace
  523.    from  sysuserauth
  524. /
  525. grant select on sysuserlist to public with grant option;
  526. rem
  527. rem    The first two unioned query-expressions in the SYNONY MS view
  528. rem    could be combined into a single query-expression with the
  529. rem    term "tab$owner in (1,uid)."  This was not done because the
  530. rem    optimizer will not do or-optimization in the presence of
  531. rem    outer joins; this forces the access path selector to perform
  532. rem    a time-consuming, full-table scan of sys.tables s.
  533. rem
  534. create or replace view synonyms 
  535.     (sname, syntype, creator, tname, database, tabtype) as
  536.   select s.name, 
  537.      decode (s.owner#,1,'PUBLIC','PRIVATE'), t.owner, t.name, 'LOCAL', 
  538.      decode(ot.type, 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER', 4, 'VIEW',
  539.              5, 'SYNONYM', 6, 'SEQUENCE', 'UNDEFINED')
  540.   from  sys.obj$ s, sys.obj$ ot, sys.syn$ t, sys.user$ u
  541.   where s.obj# = t.obj#
  542.     and s.type = 5
  543.     and ot.name = t.name
  544.     and t.owner = u.name
  545.     and ot.owner# = u.user#
  546.     and s.owner# in (1,uid)
  547.     and t.node is null
  548. union
  549.   select s.name, decode(s.owner#, 1, 'PUBLIC', 'PRIVATE'),
  550.      t.owner, t.name, t.node, 'REMOTE'
  551.   from  sys.obj$ s, sys.syn$ t
  552.   where s.obj# = t.obj#
  553.     and s.type = 5
  554.     and s.owner# in (1, uid)
  555.     and t.node is not null
  556. /  
  557. grant select on synonyms to public with grant option;
  558. create or replace view publicsyn 
  559.     (sname, creator, tname, database, tabtype) as
  560.   select sname, creator, tname, database, tabtype
  561.   from  synonyms
  562.   where syntype = 'PUBLIC'
  563. /
  564. grant select on publicsyn to public with grant option;
  565. create or replace view privatesyn 
  566.     (sname, creator, tname, database, tabtype) as
  567.   select sname, creator, tname, database, tabtype
  568.   from  synonyms
  569.   where syntype = 'PRIVATE'
  570. /
  571. grant select on privatesyn to public with grant option;
  572. create or replace view tab 
  573.     (tname, tabtype, clusterid) as
  574.    select o.name,
  575.       decode(o.type, 2, 'TABLE', 3, 'CLUSTER', 
  576.              4, 'VIEW', 5, 'SYNONYM'), t.tab#
  577.   from  sys.tab$ t, sys.obj$ o
  578.    where o.owner# = uid and o.type >= 2 and o.type <=5
  579.      and o.obj# = t.obj# (+)
  580. /
  581. grant select on tab to public with grant option;
  582. create or replace view col 
  583.     (tname, colno, cname, coltype, width, scale, precision, nulls,
  584.                  defaultval, remarks) as
  585.   select t.name, c.col#, c.name, 
  586.      decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'VARCHAR',
  587.                          12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  588.                          69, 'ROWID', 'UNDEFINED'),
  589.          decode(c.type#, 2, c.precision, c.length),
  590.      c.scale, c.precision,
  591.      decode(c.null$, 0, 'NULL', 'NOT NULL'), c.default$, co.comment$
  592.    from  sys.col$ c, sys.obj$ t, sys.com$ co
  593.    where t.obj# = c.obj#
  594.    and   c.obj# = co.obj# (+)
  595.    and   c.col# = co.col# (+)
  596.    and     t.type in (2, 3, 4)
  597.    and     t.owner# = uid
  598. /
  599. grant select on col to public with grant option;
  600. create or replace view tabquotas 
  601.     (tname, type, objno, nextext, maxext, pinc,
  602.                pfree, pused) as
  603.   select t.name, so.type, t.obj#, s.extsize, s.maxexts, s.extpct, so.pctfree$,
  604.      so.pctused$
  605.   from  sys.seg$ s, sys.obj$ t, syssegobj so
  606.   where t.owner# = uid
  607.     and t.obj# = so.obj#
  608.     and so.file# = s.file# 
  609.     and so.block# = s.block#
  610. /
  611. grant select on tabquotas to public with grant option;
  612. rem   
  613. rem SYSTEM_AUDIT gives one row with the system auditing options.
  614. rem The table is only accessible to dba's.
  615. rem
  616. create or replace view SYSTEM_AUDIT 
  617.     (connect$,dba$,not_exists$,resource$) as
  618. select substr(t.audit$,1,1) || '/' || substr(t.audit$,2,1),
  619.        substr(t.audit$,3,1) || '/' || substr(t.audit$,4,1),
  620.        substr(t.audit$,5,1) || '/' || substr(t.audit$,6,1),
  621.        substr(t.audit$,7,1) || '/' || substr(t.audit$,8,1)
  622. from    sys.obj$ o, sys.tab$ t
  623. where o.owner# = 0 
  624.   and o.name = '_system_auditing_options_'
  625.   and o.obj# = t.obj#
  626. /
  627. rem
  628. rem DEFAULT_AUDIT gives one row with the default table auditing options.
  629. rem The table is accessible to public.
  630. rem
  631. create or replace view DEFAULT_AUDIT 
  632.     (alt,aud,com,del,gra,ind,ins,loc,ren,sel,upd) as
  633. select
  634.     substr(audit$,1,1) || '/' || substr(audit$,2,1),
  635.     substr(audit$,3,1) || '/' || substr(audit$,4,1),
  636.     substr(audit$,5,1) || '/' || substr(audit$,6,1),
  637.     substr(audit$,7,1) || '/' || substr(audit$,7,1),
  638.     substr(audit$,9,1) || '/' || substr(audit$,10,1),
  639.     substr(audit$,11,1) || '/' || substr(audit$,12,1),
  640.     substr(audit$,13,1) || '/' || substr(audit$,14,1),
  641.     substr(audit$,15,1) || '/' || substr(audit$,16,1),
  642.     substr(audit$,17,1) || '/' || substr(audit$,18,1),
  643.     substr(audit$,19,1) || '/' || substr(audit$,20,1),
  644.     substr(audit$,21,1) || '/' || substr(audit$,22,1)
  645. from  sys.obj$ o, sys.tab$ t
  646. where o.owner# = 0 
  647.   and o.name = '_default_auditing_options_'
  648.   and t.obj# = o.obj#
  649. /
  650. grant select on DEFAULT_AUDIT to public with grant option;
  651. rem
  652. rem TABLE_AUDIT lists auditing options for the user's own tables
  653. rem and views, or for all tables and views if a DBA.
  654. rem
  655. create or replace view TABLE_AUDIT 
  656.   (creator, tname, tabletype, alt,aud,com,del,gra,ind,ins,loc,ren,sel,upd) as
  657.   select u.name, o.name, 'TABLE',
  658.    substr(t.audit$,1,1) || '/' || substr(t.audit$,2,1),
  659.    substr(t.audit$,3,1) || '/' || substr(t.audit$,4,1),
  660.    substr(t.audit$,5,1) || '/' || substr(t.audit$,6,1),
  661.    substr(t.audit$,7,1) || '/' || substr(t.audit$,8,1),
  662.    substr(t.audit$,9,1) || '/' || substr(t.audit$,10,1),
  663.    substr(t.audit$,11,1) || '/' || substr(t.audit$,12,1),
  664.    substr(t.audit$,13,1) || '/' || substr(t.audit$,14,1),
  665.    substr(t.audit$,15,1) || '/' || substr(t.audit$,16,1),
  666.    substr(t.audit$,17,1) || '/' || substr(t.audit$,18,1),
  667.    substr(t.audit$,19,1) || '/' || substr(t.audit$,20,1),
  668.    substr(t.audit$,21,1) || '/' || substr(t.audit$,22,1)
  669.     from sys.obj$ o, sys.user$ u, sys.tab$ t
  670.     where o.type = 2 and o.name != '_default_auditing_options_'
  671.      and o.name != '_system_auditing_options_' and o.owner# = u.user#
  672.      and o.obj# = t.obj# and (o.owner# = uid or exists 
  673.                                (select null
  674.                                 from sys.v$enabledprivs
  675.                                 where priv_number = -47 /* SELECT ANY TABLE */)
  676.                              )
  677.   union
  678.   select u.name, o.name, 'VIEW',
  679.     substr(t.audit$,1,1) || '/' || substr(t.audit$,2,1),
  680.     substr(t.audit$,3,1) || '/' || substr(t.audit$,4,1),
  681.     substr(t.audit$,5,1) || '/' || substr(t.audit$,6,1),
  682.     substr(t.audit$,7,1) || '/' || substr(t.audit$,8,1),
  683.     substr(t.audit$,9,1) || '/' || substr(t.audit$,10,1),
  684.     substr(t.audit$,11,1) || '/' || substr(t.audit$,12,1),
  685.     substr(t.audit$,13,1) || '/' || substr(t.audit$,14,1),
  686.     substr(t.audit$,15,1) || '/' || substr(t.audit$,16,1),
  687.     substr(t.audit$,17,1) || '/' || substr(t.audit$,18,1),
  688.     substr(t.audit$,19,1) || '/' || substr(t.audit$,20,1),
  689.     substr(t.audit$,21,1) || '/' || substr(t.audit$,22,1)
  690.     from sys.obj$ o, sys.user$ u, sys.view$ t
  691.     where o.type = 4 and o.name != '_default_auditing_options_'
  692.      and o.name != '_system_auditing_options_' 
  693.      and o.owner# = u.user# and o.obj# = t.obj#
  694.      and (o.owner# = uid or exists 
  695.                              (select null
  696.                               from sys.v$enabledprivs
  697.                               where priv_number = -47 /* SELECT ANY TABLE */)
  698.          )
  699. /
  700. grant select on TABLE_AUDIT to public with grant option;
  701. rem
  702. rem audit_actions maps an action number to the action name.
  703. rem The table is accessible to public.
  704. rem
  705. drop table audit_actions;
  706. create table audit_actions(
  707.   action number not null, name varchar2(27) not null
  708. );
  709. grant select on audit_actions to public with grant option;
  710. insert into audit_actions values (0, 'UNKNOWN');
  711. insert into audit_actions values (1, 'CREATE TABLE');
  712. insert into audit_actions values (2, 'INSERT');
  713. insert into audit_actions values (3, 'SELECT');
  714. insert into audit_actions values (4, 'CREATE CLUSTER');
  715. insert into audit_actions values (5, 'ALTER CLUSTER');
  716. insert into audit_actions values (6, 'UPDATE');
  717. insert into audit_actions values (7, 'DELETE');
  718. insert into audit_actions values (8, 'DROP CLUSTER');
  719. insert into audit_actions values (9, 'CREATE INDEX');
  720. insert into audit_actions values (10, 'DROP INDEX');
  721. insert into audit_actions values (11, 'ALTER INDEX');
  722. insert into audit_actions values (12, 'DROP TABLE');
  723. insert into audit_actions values (13, 'CREATE SEQUENCE');
  724. insert into audit_actions values (14, 'ALTER SEQUENCE');
  725. insert into audit_actions values (15, 'ALTER TABLE');
  726. insert into audit_actions values (16, 'DROP SEQUENCE');
  727. insert into audit_actions values (17, 'GRANT OBJECT');
  728. insert into audit_actions values (18, 'REVOKE OBJECT');
  729. insert into audit_actions values (19, 'CREATE SYNONYM');
  730. insert into audit_actions values (20, 'DROP SYNONYM');
  731. insert into audit_actions values (21, 'CREATE VIEW');
  732. insert into audit_actions values (22, 'DROP VIEW');
  733. insert into audit_actions values (23, 'VALIDATE INDEX');
  734. insert into audit_actions values (26, 'LOCK');
  735. insert into audit_actions values (27, 'UNDEFINED');
  736. insert into audit_actions values (28, 'RENAME');
  737. insert into audit_actions values (29, 'COMMENT');
  738. insert into audit_actions values (30, 'AUDIT OBJECT');
  739. insert into audit_actions values (31, 'NOAUDIT OBJECT');
  740. insert into audit_actions values (32, 'CREATE DATABASE LINK');
  741. insert into audit_actions values (33, 'DROP DATABASE LINK');
  742. insert into audit_actions values (34, 'CREATE DATABASE');
  743. insert into audit_actions values (35, 'ALTER DATABASE');
  744. insert into audit_actions values (36, 'CREATE ROLLBACK SEG');
  745. insert into audit_actions values (37, 'ALTER ROLLBACK SEG');
  746. insert into audit_actions values (38, 'DROP ROLLBACK SEG');
  747. insert into audit_actions values (39, 'CREATE TABLESPACE');
  748. insert into audit_actions values (40, 'ALTER TABLESPACE');
  749. insert into audit_actions values (41, 'DROP TABLESPACE');
  750. insert into audit_actions values (42, 'ALTER SESSION');
  751. insert into audit_actions values (43, 'ALTER USER');
  752. insert into audit_actions values (49, 'ALTER SYSTEM');
  753. insert into audit_actions values (60, 'LOGON');
  754. insert into audit_actions values (61, 'LOGOFF');
  755. insert into audit_actions values (62, 'CLEANUP');
  756. insert into audit_actions values (63, 'SESSION');
  757. insert into audit_actions values (64, 'AUDIT SYSTEM');
  758. insert into audit_actions values (65, 'NOAUDIT SYSTEM');
  759. insert into audit_actions values (66, 'AUDIT DEFAULT');
  760. insert into audit_actions values (67, 'NOAUDIT DEFAULT');
  761. insert into audit_actions values (68, 'GRANT SYSTEM');
  762. insert into audit_actions values (69, 'REVOKE SYSTEM');
  763. insert into audit_actions values (70, 'CREATE PUBLIC SYNONYM');
  764. insert into audit_actions values (71, 'DROP PUBLIC SYNONYM');
  765. insert into audit_actions values (72, 'CREATE PUBLIC DATABASE LINK');
  766. insert into audit_actions values (73, 'DROP PUBLIC DATABASE LINK');
  767. insert into audit_actions values (80, 'USER COMMENT');
  768. commit;
  769. create unique index audact$uid on audit_actions(action,name) nocompress;
  770.  
  771. rem
  772. rem    AUDIT_TRAIL:  Lists audit trail entries on the user's objects
  773. rem                  or other pertinent entries.
  774. rem                  DBA sees all.
  775. rem
  776. create or replace view audit_trail as 
  777.   select userid, userhost, terminal, timestamp, obj$creator, obj$name,
  778.          t.action action, act.name action_name, new$name,
  779.          auth$privileges, auth$grantee, ses$actions,
  780.          logoff$time, logoff$lread, logoff$pread, logoff$lwrite, logoff$dead,
  781.          comment$text, sessionid, entryid, statement, returncode
  782.   from sys.aud$ t, audit_actions act
  783.   where t.action = act.action
  784.     and (t.obj$creator = user 
  785.          or (t.obj$creator is null and t.userid = user)
  786.          or exists (select null
  787.                     from sys.v$enabledprivs
  788.                     where priv_number = -47 /* SELECT ANY TABLE */)
  789.          )
  790. /
  791. grant select on audit_trail to public with grant option;
  792.  
  793. rem
  794. rem    AUDIT_DBA:  Lists audit trail entries produced by AUDIT DBA
  795. rem                (all operations with an action code of 24, 25, or
  796. rem                64 through 73).
  797. rem                This view is accessible to DBAs only.
  798. rem
  799. create or replace view AUDIT_DBA as  
  800.   select userid, userhost, terminal, timestamp,
  801.          obj$creator, obj$name, t.action action, act.name action_name, 
  802.          substr(auth$privileges,1,1) connect$,
  803.          substr(auth$privileges,2,1) dba$,
  804.          substr(auth$privileges,3,1) resource$,
  805.          auth$grantee, new$name,
  806.          sessionid, entryid, statement, returncode
  807.    from  sys.aud$ t, audit_actions act
  808.    where t.action = act.action
  809.      and (t.action between 24 and 25
  810.           or t.action between 64 and 73)
  811. /
  812. rem
  813. rem    AUDIT_EXISTS:  Lists audit trail entries produced by AUDIT NOT EXISTS.
  814. rem                   This is all audit trail entries with return codes of 942,
  815. rem                   943, 959, 1418, 1432, 1434, 1435, 2019, 2024 and 2289.
  816. rem                   This view is accessible to DBAs only.
  817. rem
  818. create or replace view AUDIT_EXISTS as
  819.   select userid, userhost, terminal, timestamp,
  820.          obj$creator, obj$name, t.action action, act.name action_name, 
  821.          auth$privileges, auth$grantee, new$name,
  822.          sessionid, entryid, statement, returncode
  823.   from sys.aud$ t, audit_actions act
  824.   where t.action = act.action
  825.     and returncode in (942, 943, 959, 1418, 1432, 1434, 1435, 2019, 2024, 2289)
  826. /
  827. rem
  828. rem  AUDIT_CONNECT: Lists the audit trail entries produced by AUDIT CONNECT.
  829. rem                 DBA's see all entries, while ordinary users only
  830. rem                 see entries for their own logins/logoffs.
  831. rem
  832. create or replace view AUDIT_CONNECT as
  833.   select userid, userhost, terminal, 
  834.          decode(action, 60, 'LOGON', 61, 'LOGOFF', 62, 'CLEANUP') action_name,
  835.          timestamp, logoff$time,
  836.          logoff$lread, logoff$pread, logoff$lwrite, logoff$dead,
  837.          sessionid, returncode
  838.   from sys.aud$
  839.   where action between 60 and 62
  840.     and (userid = user 
  841.          or exists (select null
  842.                     from sys.v$enabledprivs
  843.                     where priv_number = -47 /* SELECT ANY TABLE */)
  844.          )
  845. /
  846. grant select on AUDIT_CONNECT to public with grant option;
  847. rem
  848. rem  SESSIONS:  same as AUDIT_CONNECT but with different column names
  849. rem             for backward compatiblity.
  850. rem
  851. create or replace view SESSIONS 
  852.   (userid, userhost, terminal, status, logon, logoff, 
  853.               logread, physread, logwrite, deadlocks, sessionid, 
  854.               cleanup_error) as
  855.   select userid, userhost, terminal, 
  856.          decode(action, 60, 'LOGON', 61, 'LOGOFF', 62, 'CLEANUP'),
  857.          timestamp, logoff$time,
  858.          logoff$lread, logoff$pread, logoff$lwrite, logoff$dead,
  859.          sessionid, returncode
  860.   from sys.aud$
  861.   where action between 60 and 62
  862.     and (userid = user 
  863.          or exists (select null
  864.                     from sys.v$enabledprivs
  865.                     where priv_number = -47 /* SELECT ANY TABLE */)
  866.          )
  867. /
  868. grant select on SESSIONS to public with grant option;
  869. rem
  870. rem     AUDIT_ACCESS: Lists audit trail entries produced by 
  871. rem                   AUDIT <options> ON <table_name> ... 
  872. rem                   DBA's see all entries, while ordinary users only
  873. rem                   see entries for their own tables.
  874. rem
  875. create or replace view AUDIT_ACCESS as
  876.  select userid, userhost, terminal, timestamp,
  877.     obj$creator, obj$name, t.action action, act.name action_name, 
  878.     new$name, auth$privileges, auth$grantee,
  879.     substr(ses$actions,1,1) alt,
  880.     substr(ses$actions,2,1) aud,
  881.     substr(ses$actions,3,1) com,
  882.     substr(ses$actions,4,1) del,
  883.     substr(ses$actions,5,1) gra,
  884.     substr(ses$actions,6,1) ind,
  885.     substr(ses$actions,7,1) ins,
  886.     substr(ses$actions,8,1) loc,
  887.     substr(ses$actions,9,1) ren,
  888.     substr(ses$actions,10,1) sel,
  889.     substr(ses$actions,11,1) upd,
  890.     sessionid, entryid, statement, returncode
  891.  from sys.aud$ t, audit_actions act
  892.  where  t.action = act.action  
  893.    and t.action <= 63
  894.    and not (t.action in (1,4,5,8,11,12,13,14,19,20,21,22,24,25,60,61,62))
  895.    and (t.obj$creator = user 
  896.          or exists (select null
  897.                     from sys.v$enabledprivs
  898.                     where priv_number = -47 /* SELECT ANY TABLE */)
  899.          )
  900. grant select on AUDIT_ACCESS to public with grant option;
  901. create or replace view dblinks 
  902.     (name, type, host, userid) as
  903.   select name, decode(owner#, 1, 'PUBLIC', 'PRIVATE'), host, userid
  904.   from  sys.link$
  905.   where owner# in (1,uid)
  906. /
  907. grant select on dblinks to public with grant option;
  908. create or replace view sysdblinks 
  909.     (owner, name, host, userid) as
  910.   select u.name, l.name, l.host, l.userid
  911.   from  sys.user$ u, sys.link$ l
  912.   where u.user# = l.owner#
  913. /
  914. create or replace view systabspaces 
  915.     (tsname,  status, blocksize, dflminext,
  916.               dflmaxext, dflinitial, dflnext, dflpctinc) as
  917.   select ts.name, decode(ts.online$, 1, 'ONLINE', 2, 'OFFLINE', 'UNDEFINED'), 
  918.      ts.blocksize, ts.dflminext,
  919.      ts.dflmaxext, ts.dflinit, ts.dflincr, ts.dflextpct
  920.   from  sys.ts$ ts
  921.   where ts.online$ != 3
  922. /
  923. create or replace view tabspaces 
  924.     (tsname, status, blocksize, dflminext,
  925.                dflmaxext, dflinitial, dflnext, dflpctinc) as
  926.   select ts.name, decode(ts.online$, 1, 'ONLINE', 2, 'OFFLINE', 'UNDEFINED'), 
  927.      ts.blocksize, ts.dflminext,
  928.      ts.dflmaxext, ts.dflinit, ts.dflincr, ts.dflextpct
  929.   from  sys.ts$ ts
  930.   where ts.online$ != 3 and ts.ts# in 
  931.           (select ts# from sys.tsq$ 
  932.            where  user# in (uid, 1))
  933. /
  934. grant select on tabspaces to public with grant option;
  935. create or replace view sysfiles 
  936.     (tsname, fname, blocks) as
  937.   select ts.name, dbf.name, f.blocks
  938.   from  sys.ts$ ts, sys.file$ f, sys.v$dbfile dbf
  939.   where ts.ts# = f.ts#(+) and dbf.file# = f.file# and f.status$ = 2
  940. /
  941. create or replace view systsquotas_ 
  942.     (tsname, username, userid, blocks, maxblocks) as
  943.   select ts.name, u.name, tsq.user#, tsq.blocks, tsq.maxblocks
  944.   from  sys.user$ u, sys.tsq$ tsq, sys.ts$ ts
  945.   where u.user# = tsq.user#
  946.     and tsq.ts# = ts.ts#
  947. /
  948. create or replace view systsquotas 
  949.     (username, tsname, blocks, maxblocks) as
  950.   select username, tsname, blocks, maxblocks
  951.   from  systsquotas_
  952. /
  953. create or replace view tsquotas 
  954.     (tsname, blocks, maxblocks) as
  955.   select tsname, blocks, maxblocks
  956.   from  systsquotas_
  957.   where userid = uid
  958. /
  959. grant select on tsquotas to public with grant option;
  960. create or replace view sysrollbackseg 
  961.     (segname, tbaspace, segstatus) as
  962.   select u.name, ts.name, 
  963.      decode(u.status$, 2, 'AVAILABLE', 3, 'INUSE', 
  964.                4, 'OFFLINE', 5, 'NEED RECOVERY', 'UNDEFINED')
  965.   from  sys.undo$ u, sys.ts$ ts, sys.seg$ s
  966.   where u.status$ != 1 and u.file# = s.file# and u.block# = s.block#
  967.     and s.ts# = ts.ts#
  968. /
  969. drop table dtab;
  970. create table dtab(tname varchar2(14),remarks varchar2(64));
  971. insert into dtab values ('Reference Date',
  972.   'ORACLE catalog as of 10-Oct-85, installed on '||
  973.   to_char(sysdate,'dd-MON-yy hh24:mi:ss.'));
  974. insert into dtab values ('AUDIT_ACCESS',
  975.   'Audit entries for accesses to user''s tables/views (DBA sees all)');
  976. insert into dtab values ('AUDIT_ACTIONS',
  977.   'Maps auditing action numbers to action names');
  978. insert into dtab values ('AUDIT_CONNECT',
  979.   'Audit trail entries for user logon/logoff (DBA sees all users)');
  980. insert into dtab values ('AUDIT_DBA',
  981.    'Audit trail entries for DBA activities - for DBA use only');
  982. insert into dtab values ('AUDIT_EXISTS',
  983.    'Audit trail entries for objects which do NOT EXIST - DBA''s only');
  984. insert into dtab values ('AUDIT_TRAIL',
  985.    'Audit trail entries relevant to the user (DBA sees all)');
  986. insert into dtab values ('CATALOG',
  987.   'Tables and views accessible to user (excluding data dictionary)');
  988. insert into dtab values ('CLUSTERS',
  989.   'Clusters and their tables (either must be accessible to user)');
  990. insert into dtab values ('CLUSTERCOLUMNS',
  991.   'Maps cluster columns to clustered table columns');
  992. insert into dtab values ('COL',
  993.   'Specifications of columns in tables created by the user');
  994. insert into dtab values ('COLUMNS',
  995.   'Columns in tables accessible to user (excluding data dictionary)');
  996. insert into dtab values ('DBLINKS',
  997.   'Public and private links to external databases');
  998. insert into dtab values ('DEFAULT_AUDIT',
  999.    'Default table auditing options');
  1000. insert into dtab values ('DTAB',
  1001.   'Description of tables and views in Oracle Data Dictionary');
  1002. insert into dtab values ('EXTENTS',
  1003.   'Data structure of extents within tables');
  1004. insert into dtab values ('INDEXES',
  1005.   'Indexes created by user and indexes on tables created by user');
  1006. insert into dtab values ('FREESPACE',
  1007.   'Free extents available in the system - for DBA use only');
  1008. insert into dtab values ('PRIVATESYN',
  1009.   'Private synonyms created by the user');
  1010. insert into dtab values ('PUBLICSYN',
  1011.   'Public synonyms');
  1012. insert into dtab values ('SEQUENCES',
  1013.   'Sequences created by the user');
  1014. insert into dtab values ('SESSIONS',
  1015.   'Audit trail entries for the user''s sessions (DBA sees all)');
  1016. insert into dtab values ('STORAGE',
  1017.   'Data and Index storage allocation for user''s own tables');
  1018. insert into dtab values ('SYNONYMS',
  1019.   'Synonyms, private and public');
  1020. insert into dtab values ('SYSAUDIT_TRAIL',
  1021.   'Synonym for sys.audit_trail - for DBA use only');
  1022. insert into dtab values ('SYSCATALOG',
  1023.   'Profile of tables and views accessible to the user');
  1024. insert into dtab values ('SYSCOLAUTH',
  1025.   'Directory of column update access granted by or to the user');
  1026. insert into dtab values ('SYSCOLUMNS',
  1027.   'Specifications of columns in accessible tables and views');
  1028. insert into dtab values ('SYSDATABASE',
  1029.   'Parameters of databases');
  1030. insert into dtab values ('SYSDBLINKS',
  1031.   'All links to external databases - for DBA use only');
  1032. insert into dtab values ('SYSEXTENTS',
  1033.   'Data structure of tables throughout system - for DBA use only');
  1034. insert into dtab values ('SYSFILES',
  1035.   'Files allocation - for DBA use only');
  1036. insert into dtab values ('SYSINDEXES',
  1037.   'List of indexes, underlying columns, creator, and options');
  1038. insert into dtab values ('SYSCONSTRAINTS',
  1039.   'Constraint definitions');
  1040. insert into dtab values ('SYSCONSTRACOLS',
  1041.   'Columns of primary keys, unique keys, and foreign keys');
  1042. insert into dtab values ('SYSSEQUENCES',
  1043.   'List of accessible sequences');
  1044. insert into dtab values ('SYSSTORAGE',
  1045.   'Summary of all database storage - for DBA use only');
  1046. insert into dtab values ('SYSTABALLOC',
  1047.   'Data and index space allocations for all tables - for DBA''s');
  1048. insert into dtab values ('SYSTABAUTH',
  1049.   'Directory of access authorization granted by or to the user');
  1050. insert into dtab values('SYSTABSPACES',
  1051.   'Parameters of tablespaces - for DBA use only');
  1052. insert into dtab values ('SYSTSQUOTAS',
  1053.   'Space privileges granted to users - for DBA use only');
  1054. insert into dtab values ('SYSTEM_AUDIT',
  1055.   'System auditing options - for DBA use only');
  1056. insert into dtab values ('SYSROLLBACKSEG',
  1057.   'Rollback segments for tablespaces - for DBA use only');
  1058. insert into dtab values ('SYSUSERAUTH',
  1059.   'Master list of Oracle users - for DBA use only');
  1060. insert into dtab values ('SYSUSERLIST',
  1061.   'List of Oracle users' );
  1062. insert into dtab values ('SYSVIEWS',
  1063.   'List of accessible views' );
  1064. insert into dtab values ('TAB',
  1065.   'List of tables, views, clusters and synonyms created by the user');
  1066. insert into dtab values ('TABALLOC',
  1067.   'Data and index space allocations for all user''s tables');
  1068. insert into dtab values ('TABQUOTAS',
  1069.   'Table allocation (space) parameters for tables created by user');
  1070. insert into dtab values('TABSPACES',
  1071.   'Parameters of tablespaces accessible by current user');
  1072. insert into dtab values ('TABLE_AUDIT',
  1073.   'Auditing options of user''s tables and views (DBA sees all)');
  1074. insert into dtab values ('TSQUOTAS',
  1075.   'Space privileges granted to current user');
  1076. insert into dtab values ('VIEWS',
  1077.   'Defining SQL statements for views created by the user');
  1078. grant select on dtab to public with grant option;
  1079. create synonym system.taballoc for taballoc;
  1080. create public synonym taballoc for taballoc;
  1081. create synonym system.storage for storage;
  1082. create public synonym storage for storage;
  1083. create synonym system.extents for extents;
  1084. create public synonym extents for extents;
  1085. create synonym system.freespace for freespace;
  1086. create public synonym freespace for freespace;
  1087. create synonym system.syscolumns for syscolumns;
  1088. create public synonym syscolumns for syscolumns;
  1089. create synonym system.columns for columns;
  1090. create public synonym columns for columns;
  1091. create synonym system.syscatalog for syscatalog;
  1092. create public synonym syscatalog for syscatalog;
  1093. create synonym system.catalog for catalog;
  1094. create public synonym catalog for catalog;
  1095. create synonym system.sysindexes for sysindexes;
  1096. create public synonym sysindexes for sysindexes;
  1097. create synonym system.sysconstraints for sysconstraints;
  1098. create public synonym sysconstraints for sysconstraints;
  1099. create synonym system.sysconstracols for sysconstracols;
  1100. create public synonym sysconstracols for sysconstracols;
  1101. create synonym system.indexes for indexes;
  1102. create public synonym indexes for indexes;
  1103. create synonym system.views for views;
  1104. create public synonym views for views;
  1105. create synonym system.sysviews for sysviews;
  1106. create public synonym sysviews for sysviews;
  1107. create synonym system.sequences for sequences;
  1108. create public synonym sequences for sequences;
  1109. create synonym system.syssequences for syssequences;
  1110. create public synonym syssequences for syssequences;
  1111. create synonym system.systabauth for systabauth;
  1112. create public synonym systabauth for systabauth;
  1113. create synonym system.syscolauth for syscolauth;
  1114. create public synonym syscolauth for syscolauth;
  1115. create synonym system.sysuserlist for sysuserlist;
  1116. create public synonym sysuserlist for sysuserlist;
  1117. create synonym system.synonyms for synonyms;
  1118. create public synonym synonyms for synonyms;
  1119. create synonym system.publicsyn for publicsyn;
  1120. create public synonym publicsyn for publicsyn;
  1121. create synonym system.privatesyn for privatesyn;
  1122. create public synonym privatesyn for privatesyn;
  1123. create synonym system.tab for tab;
  1124. create public synonym tab for tab;
  1125. create synonym system.col for col;
  1126. create public synonym col for col;
  1127. create synonym system.tabquotas for tabquotas;
  1128. create public synonym tabquotas for tabquotas;
  1129. create synonym system.dtab for dtab;
  1130. create public synonym dtab for dtab;
  1131. create synonym system.sysfiles for sysfiles;
  1132. create public synonym sysfiles for sysfiles;
  1133. create synonym system.systaballoc for systaballoc;
  1134. create public synonym systaballoc for systaballoc;
  1135. create synonym system.sysstorage for sysstorage;
  1136. create public synonym sysstorage for sysstorage;
  1137. create synonym system.sysextents for sysextents;
  1138. create public synonym sysextents for sysextents;
  1139. create synonym system.sysuserauth for sysuserauth;
  1140. create public synonym sysuserauth for sysuserauth;
  1141. rem create public synonym sysdatabase for sysdatabase;
  1142. create synonym system.systabspaces for systabspaces;
  1143. create public synonym systabspaces for systabspaces;
  1144. create synonym system.tabspaces for tabspaces;
  1145. create public synonym tabspaces for tabspaces;
  1146. create synonym system.systsquotas for systsquotas;
  1147. create public synonym systsquotas for systsquotas;
  1148. create synonym system.tsquotas for tsquotas;
  1149. create public synonym tsquotas for tsquotas;
  1150. create synonym system.sysrollbackseg for sysrollbackseg;
  1151. create public synonym sysrollbackseg for sysrollbackseg;
  1152. create synonym system.system_audit for system_audit;
  1153. create public synonym system_audit for system_audit;
  1154. create synonym system.default_audit for default_audit;
  1155. create public synonym default_audit for default_audit;
  1156. create synonym system.table_audit for table_audit;
  1157. create public synonym table_audit for table_audit;
  1158. create synonym system.audit_actions for audit_actions;
  1159. create public synonym audit_actions for audit_actions;
  1160. create synonym system.audit_trail for audit_trail;
  1161. create public synonym audit_trail for audit_trail;
  1162. create synonym system.sysaudit_trail for sys.audit_trail;
  1163. create public synonym sysaudit_trail for sys.audit_trail;
  1164. create synonym system.audit_dba for audit_dba;
  1165. create public synonym audit_dba for audit_dba;
  1166. create synonym system.audit_exists for audit_exists;
  1167. create public synonym audit_exists for audit_exists;
  1168. create synonym system.audit_connect for audit_connect;
  1169. create public synonym audit_connect for audit_connect;
  1170. create synonym system.sessions for sessions;
  1171. create public synonym sessions for sessions;
  1172. create synonym system.audit_access for audit_access;
  1173. create public synonym audit_access for audit_access;
  1174. create synonym system.clusters for clusters;
  1175. create public synonym clusters for clusters;
  1176. create synonym system.clustercolumns for clustercolumns;
  1177. create public synonym clustercolumns for clustercolumns;
  1178. create synonym system.dblinks for dblinks;
  1179. create public synonym dblinks for dblinks;
  1180. create synonym system.sysdblinks for sysdblinks;
  1181. create public synonym sysdblinks for sysdblinks;
  1182.