home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / db / rdbms71 / catprc.sql < prev    next >
Text File  |  1994-08-07  |  41KB  |  1,243 lines

  1. rem 
  2. rem $Header: catprc.sql 7010400.1 94/06/04 18:23:25 cli Generic<base> $ prctrg.sql 
  3. rem 
  4. Rem Copyright (c) 1990 by Oracle Corporation
  5. Rem NAME
  6. Rem    CATPRC.SQL
  7. Rem FUNCTION
  8. Rem    Creates data dictionary views for stored procedures and triggers. 
  9. Rem NOTES
  10. Rem    Must be run while connected to sys or internal.
  11. Rem
  12. Rem MODIFIED
  13. Rem     jbellemo   04/27/94 -  #199905: fix security in ALL_ERRORS
  14. Rem     jbellemo   11/09/93 -  #170173: change uid to userenv schemaid
  15. Rem     tpystyne   10/28/92 -  use create or replace view 
  16. Rem     glumpkin   10/20/92 -  Renamed from PRCTRG.SQL 
  17. Rem     mmoore     10/15/92 - #(131033) add trigger column views for marketing 
  18. Rem     mmoore     09/29/92 - #(131033) add more info to the triggers view 
  19. Rem     jwijaya    08/17/92 -  add sequence to error$ 
  20. Rem     jwijaya    07/17/92 -  remove database link owner from name 
  21. Rem     mmoore     06/03/92 - #(111923) change trigger view names 
  22. Rem     mmoore     06/02/92 - #(96526) remove v$enabledroles 
  23. Rem     mroberts   06/01/92 -  change privileges for all_errors view 
  24. Rem     rkooi      04/15/92 -  test tools 
  25. Rem     rkooi      01/18/92 -  add synonym 
  26. Rem     rkooi      01/18/92 -  add object_sizes views 
  27. Rem     rkooi      01/10/92 -  synchronize with catalog.sql 
  28. Rem     rkooi      12/23/91 -  testing 
  29. Rem     rkooi      10/20/91 -  add public_dependency 
  30. Rem     jwijaya    07/14/91 -  remove LINKNAME IS NULL 
  31. Rem     rkooi      05/22/91 -  get rid of _object in some catalog names 
  32. Rem     rkooi      05/22/91 - change *_references to *_dependencies
  33. Rem     rkooi      05/05/91 - fix up permissions on all* cats 
  34. Rem     jwijaya    04/12/91 - remove LINKNAME IS NULL 
  35. Rem     rkooi      03/29/91 - add views for pcode & diana 
  36. Rem     Kooi       03/12/91 - Creation
  37. Rem     Kooi       03/12/91 - Creation
  38. Rem
  39.  
  40.  
  41. remark
  42. remark    FAMILY "ERRORS"
  43. remark    Errors for stored objects - currently these are
  44. remark    PL/SQL packages, package bodies, procedures and functions.
  45. remark
  46.  
  47. create or replace view USER_ERRORS
  48. (NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  49. as
  50. select o.name,
  51. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  52. 11, 'PACKAGE BODY', 'UNDEFINED'),
  53. e.sequence, e.line, e.position, e.text
  54. from sys.obj$ o, sys.error$ e
  55. where o.obj# = e.obj#
  56.   and o.type in (4, 7, 8, 9, 11)
  57.   and o.owner# = userenv('SCHEMAID')
  58. /
  59. comment on table USER_ERRORS is
  60. 'Current errors on stored objects owned by the user'
  61. /
  62. comment on column USER_ERRORS.NAME is
  63. 'Name of the object'
  64. /
  65. comment on column USER_ERRORS.TYPE is
  66. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  67. /
  68. comment on column USER_ERRORS.SEQUENCE is
  69. 'Sequence number used for ordering purposes'
  70. /
  71. comment on column USER_ERRORS.LINE is
  72. 'Line number at which this error occurs'
  73. /
  74. comment on column USER_ERRORS.POSITION is
  75. 'Position in the line at which this error occurs'
  76. /
  77. comment on column USER_ERRORS.TEXT is
  78. 'Text of the error'
  79. /
  80. drop public synonym USER_ERRORS
  81. /
  82. create public synonym USER_ERRORS for USER_ERRORS
  83. /
  84. grant select on USER_ERRORS to public with grant option
  85. /
  86.  
  87. remark
  88. remark  User is allowed to see errors on any object that they own
  89. remark  or could have created.
  90. remark
  91.  
  92. create or replace view ALL_ERRORS
  93. (OWNER, NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  94. as
  95. select u.name, o.name,
  96. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  97. 11, 'PACKAGE BODY', 'UNDEFINED'),
  98. e.sequence, e.line, e.position, e.text
  99. from sys.obj$ o, sys.error$ e, sys.user$ u
  100. where o.obj# = e.obj#
  101.   and o.owner# = u.user#
  102.   and o.type in (4, 7, 8, 9, 11)
  103.   and
  104.   (
  105.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  106.     or
  107.     (
  108.       (
  109.          (
  110.           (o.type = 7 or o.type = 8 or o.type = 9)
  111.           and
  112.           o.obj# in (select obj# from sys.objauth$
  113.                      where grantee# in (select kzsrorol from x$kzsro)
  114.                        and privilege#  = 12 /* EXECUTE */)
  115.         )
  116.         or
  117.         (
  118.           o.type = 4
  119.           and
  120.           o.obj# in (select obj# from sys.objauth$
  121.                      where grantee# in (select kzsrorol from x$kzsro)
  122.                        and privilege# in (3 /* DELETE */,   6 /* INSERT */,
  123.                                             7 /* LOCK */,     9 /* SELECT */,
  124.                                           10 /* UPDATE */))
  125.         )
  126.         or
  127.         exists
  128.         (
  129.           select null from sys.sysauth$
  130.           where grantee# in (select kzsrorol from x$kzsro)
  131.           and
  132.           (
  133.             (
  134.               /* procedure */
  135.               (o.type = 7 or o.type = 8 or o.type = 9)
  136.               and
  137.               (
  138.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  139.                 or
  140.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  141.               )
  142.             )
  143.         or
  144.             (
  145.               /* package body */
  146.               o.type = 11 and
  147.               privilege# = -141 /* CREATE ANY PROCEDURE */
  148.             )
  149.             or
  150.             (
  151.               /* view */
  152.               o.type = 4
  153.               and
  154.               (
  155.                 privilege# in     ( -91 /* CREATE ANY VIEW */,
  156.                                     -45 /* LOCK ANY TABLE */,
  157.                                     -47 /* SELECT ANY TABLE */,
  158.                                     -48 /* INSERT ANY TABLE */,
  159.                                     -49 /* UPDATE ANY TABLE */,
  160.                                     -50 /* DELETE ANY TABLE */)
  161.               )
  162.             )
  163.           )
  164.         )
  165.       )
  166.     )
  167.   )
  168. /
  169. comment on table ALL_ERRORS is
  170. 'Current errors on stored objects that user is allowed to create'
  171. /
  172. comment on column ALL_ERRORS.OWNER is
  173. 'Owner of the object'
  174. /
  175. comment on column ALL_ERRORS.NAME is
  176. 'Name of the object'
  177. /
  178. comment on column ALL_ERRORS.TYPE is
  179. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  180. /
  181. comment on column ALL_ERRORS.SEQUENCE is
  182. 'Sequence number used for ordering purposes'
  183. /
  184. comment on column ALL_ERRORS.LINE is
  185. 'Line number at which this error occurs'
  186. /
  187. comment on column ALL_ERRORS.POSITION is
  188. 'Position in the line at which this error occurs'
  189. /
  190. comment on column ALL_ERRORS.TEXT is
  191. 'Text of the error'
  192. /
  193. drop public synonym ALL_ERRORS
  194. /
  195. create public synonym ALL_ERRORS for ALL_ERRORS
  196. /
  197. grant select on ALL_ERRORS to public with grant option
  198. /
  199.  
  200. create or replace view DBA_ERRORS
  201. (OWNER, NAME, TYPE, SEQUENCE, LINE, POSITION, TEXT)
  202. as
  203. select u.name, o.name,
  204. decode(o.type, 4, 'VIEW', 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  205. 11, 'PACKAGE BODY', 'UNDEFINED'),
  206. e.sequence, e.line, e.position, e.text
  207. from sys.obj$ o, sys.error$ e, sys.user$ u
  208. where o.obj# = e.obj#
  209.   and o.owner# = u.user#
  210.   and o.type in (4, 7, 8, 9, 11)
  211. /
  212. comment on table DBA_ERRORS is
  213. 'Current errors on all stored objects in the database'
  214. /
  215. comment on column DBA_ERRORS.NAME is
  216. 'Name of the object'
  217. /
  218. comment on column DBA_ERRORS.TYPE is
  219. 'Type of object: "VIEW", "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  220. /
  221. comment on column DBA_ERRORS.SEQUENCE is
  222. 'Sequence number used for ordering purposes'
  223. /
  224. comment on column DBA_ERRORS.LINE is
  225. 'Line number at which this error occurs'
  226. /
  227. comment on column DBA_ERRORS.POSITION is
  228. 'Position in the line at which this error occurs'
  229. /
  230. comment on column DBA_ERRORS.TEXT is
  231. 'Text of the error'
  232. /
  233.  
  234.  
  235. remark
  236. remark    FAMILY "SOURCE"
  237. remark    SOURCE for stored objects - currently these are 
  238. remark    PL/SQL packages, package bodies, procedures and functions.
  239. remark
  240.  
  241. create or replace view USER_SOURCE
  242. (NAME, TYPE, LINE, TEXT)
  243. as
  244. select o.name,
  245. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  246. 11, 'PACKAGE BODY', 'UNDEFINED'),
  247. s.line, s.source
  248. from sys.obj$ o, sys.source$ s
  249. where o.obj# = s.obj#
  250.   and o.type in (7, 8, 9, 11)
  251.   and o.owner# = userenv('SCHEMAID')
  252. /
  253. comment on table USER_SOURCE is
  254. 'Source of stored objects accessible to the user'
  255. /
  256. comment on column USER_SOURCE.NAME is
  257. 'Name of the object'
  258. /
  259. comment on column USER_SOURCE.TYPE is
  260. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  261. /
  262. comment on column USER_SOURCE.LINE is
  263. 'Line number of this line of source'
  264. /
  265. comment on column USER_SOURCE.TEXT is
  266. 'Source text'
  267. /
  268. drop public synonym USER_SOURCE
  269. /
  270. create public synonym USER_SOURCE for USER_SOURCE
  271. /
  272. grant select on USER_SOURCE to public with grant option
  273. /
  274.  
  275. create or replace view ALL_SOURCE
  276. (OWNER, NAME, TYPE, LINE, TEXT)
  277. as
  278. select u.name, o.name,
  279. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  280. 11, 'PACKAGE BODY', 'UNDEFINED'),
  281. s.line, s.source
  282. from sys.obj$ o, sys.source$ s, sys.user$ u
  283. where o.obj# = s.obj#
  284.   and o.owner# = u.user#
  285.   and o.type in (7, 8, 9, 11)
  286.   and
  287.   (
  288.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  289.     or
  290.     (
  291.       (
  292.          (
  293.           (o.type = 7 or o.type = 8 or o.type = 9)
  294.           and
  295.           o.obj# in (select obj# from sys.objauth$
  296.                      where grantee# in (select kzsrorol from x$kzsro)
  297.                        and privilege#  = 12 /* EXECUTE */)
  298.         )
  299.         or
  300.         exists
  301.         (
  302.           select null from sys.sysauth$
  303.           where grantee# in (select kzsrorol from x$kzsro)
  304.           and
  305.           (
  306.             (
  307.               /* procedure */
  308.               (o.type = 7 or o.type = 8 or o.type = 9)
  309.               and
  310.               (
  311.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  312.                 or
  313.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  314.               )
  315.             )
  316.         or
  317.             (
  318.               /* package body */
  319.               o.type = 11 and
  320.               privilege# = -141 /* CREATE ANY PROCEDURE */
  321.             )
  322.           )
  323.         )
  324.       )
  325.     )
  326.   )
  327. /
  328. comment on table ALL_SOURCE is
  329. 'Current source on stored objects that user is allowed to create'
  330. /
  331. comment on column ALL_SOURCE.OWNER is
  332. 'Owner of the object'
  333. /
  334. comment on column ALL_SOURCE.NAME is
  335. 'Name of the object'
  336. /
  337. comment on column ALL_SOURCE.TYPE is
  338. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  339. /
  340. comment on column ALL_SOURCE.LINE is
  341. 'Line number of this line of source'
  342. /
  343. comment on column ALL_SOURCE.TEXT is
  344. 'Source text'
  345. /
  346. drop public synonym ALL_SOURCE
  347. /
  348. create public synonym ALL_SOURCE for ALL_SOURCE
  349. /
  350. grant select on ALL_SOURCE to public with grant option
  351. /
  352.  
  353. create or replace view DBA_SOURCE
  354. (OWNER, NAME, TYPE, LINE, TEXT)
  355. as
  356. select u.name, o.name,
  357. decode(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  358. 11, 'PACKAGE BODY', 'UNDEFINED'),
  359. s.line, s.source
  360. from sys.obj$ o, sys.source$ s, sys.user$ u
  361. where o.obj# = s.obj#
  362.   and o.owner# = u.user#
  363.   and o.type in (7, 8, 9, 11)
  364. /
  365. comment on table DBA_SOURCE is
  366. 'Source of all stored objects in the database'
  367. /
  368. comment on column DBA_SOURCE.NAME is
  369. 'Name of the object'
  370. /
  371. comment on column DBA_SOURCE.TYPE is
  372. 'Type of the object: "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  373. /
  374. comment on column DBA_SOURCE.LINE is
  375. 'Line number of this line of source'
  376. /
  377. comment on column DBA_SOURCE.TEXT is
  378. 'Source text'
  379. /
  380.  
  381. remark
  382. remark    FAMILY "TRIGGERS"
  383. remark    Database trigger definitions.
  384. remark    This family has no "ALL" member.
  385. remark
  386.  
  387. create or replace view USER_TRIGGERS
  388. (TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME, 
  389.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  390. as
  391. select trigobj.name,
  392. decode(t.type, 0, 'BEFORE STATEMENT',
  393.                1, 'BEFORE EACH ROW',
  394.                2, 'AFTER STATEMENT',
  395.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  396. decode(t.insert$*100 + t.update$*10 + t.delete$,
  397.                  100, 'INSERT',
  398.                  010, 'UPDATE',
  399.                  001, 'DELETE',
  400.                  110, 'INSERT OR UPDATE',
  401.                  101, 'INSERT OR DELETE',
  402.                  011, 'UPDATE OR DELETE',
  403.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  404. u.name, tabobj.name, 
  405. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  406. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  407. t.definition,t.action
  408. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t, sys.user$ u
  409. where trigobj.obj#   = t.obj#
  410.   and tabobj.obj#    = t.baseobject
  411.   and trigobj.owner# = userenv('SCHEMAID')
  412.   and tabobj.owner#  = u.user#
  413. /
  414. comment on table USER_TRIGGERS is
  415. 'Triggers owned by the user'
  416. /
  417. comment on column USER_TRIGGERS.TRIGGER_NAME is
  418. 'Name of the trigger'
  419. /
  420. comment on column USER_TRIGGERS.TRIGGER_TYPE is
  421. 'Type of the trigger (when it fires) - BEFORE/AFTER and STATEMENT/ROW'
  422. /
  423. comment on column USER_TRIGGERS.TRIGGERING_EVENT is
  424. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  425. /
  426. comment on column USER_TRIGGERS.TABLE_OWNER is
  427. 'Owner of the table that this trigger is associated with'
  428. /
  429. comment on column USER_TRIGGERS.TABLE_NAME is
  430. 'Name of the table that this trigger is associated with'
  431. /
  432. comment on column USER_TRIGGERS.REFERENCING_NAMES is
  433. 'Names used for referencing to OLD and NEW values within the trigger'
  434. /
  435. comment on column USER_TRIGGERS.WHEN_CLAUSE is
  436. 'WHEN clause must evaluate to true in order for triggering body to execute'
  437. /
  438. comment on column USER_TRIGGERS.STATUS is
  439. 'If DISABLED then trigger will not fire'
  440. /
  441. comment on column USER_TRIGGERS.DESCRIPTION is
  442. 'Trigger description, useful for re-creating trigger creation statement'
  443. /
  444. comment on column USER_TRIGGERS.TRIGGER_BODY is
  445. 'Action taken by this trigger when it fires'
  446. /
  447. drop public synonym USER_TRIGGERS
  448. /
  449. create public synonym USER_TRIGGERS for USER_TRIGGERS
  450. /
  451. grant select on USER_TRIGGERS to public with grant option
  452. /
  453.  
  454. create or replace view ALL_TRIGGERS
  455. (OWNER, TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME,
  456.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  457. as
  458. select triguser.name, trigobj.name,
  459. decode(t.type, 0, 'BEFORE STATEMENT',
  460.                1, 'BEFORE EACH ROW',
  461.                2, 'AFTER STATEMENT',
  462.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  463. decode(t.insert$*100 + t.update$*10 + t.delete$,
  464.                  100, 'INSERT',
  465.                  010, 'UPDATE',
  466.                  001, 'DELETE',
  467.                  110, 'INSERT OR UPDATE',
  468.                  101, 'INSERT OR DELETE',
  469.                  011, 'UPDATE OR DELETE',
  470.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  471. tabuser.name, tabobj.name, 
  472. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  473. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  474. t.definition,t.action
  475. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t, sys.user$ tabuser,
  476.      sys.user$ triguser
  477. where trigobj.obj#   = t.obj#
  478.   and tabobj.obj#    = t.baseobject
  479.   and trigobj.owner# = triguser.user#
  480.   and tabobj.owner#  = tabuser.user#
  481.   and
  482.   (
  483.     trigobj.owner# = userenv('SCHEMAID') or tabobj.owner# = userenv('SCHEMAID')
  484.     or
  485.     exists (select null from sys.sysauth$
  486.              where grantee# in (select kzsrorol from x$kzsro)
  487.                and privilege# = -152 /* CREATE ANY TRIGGER */)
  488.   )
  489. /
  490. comment on table ALL_TRIGGERS is
  491. 'Triggers accessible to the current user'
  492. /
  493. comment on column ALL_TRIGGERS.OWNER is
  494. 'Owner of the trigger'
  495. /
  496. comment on column ALL_TRIGGERS.TRIGGER_NAME is
  497. 'Name of the trigger'
  498. /
  499. comment on column ALL_TRIGGERS.TRIGGER_TYPE is
  500. 'When the trigger fires - BEFORE/AFTER and STATEMENT/ROW'
  501. /
  502. comment on column ALL_TRIGGERS.TRIGGERING_EVENT is
  503. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  504. /
  505. comment on column ALL_TRIGGERS.TABLE_OWNER is
  506. 'Owner of the table that this trigger is associated with'
  507. /
  508. comment on column ALL_TRIGGERS.TABLE_NAME is
  509. 'Name of the table that this trigger is associated with'
  510. /
  511. comment on column ALL_TRIGGERS.REFERENCING_NAMES is
  512. 'Names used for referencing to OLD and NEW values within the trigger'
  513. /
  514. comment on column ALL_TRIGGERS.WHEN_CLAUSE is
  515. 'WHEN clause must evaluate to true in order for triggering body to execute'
  516. /
  517. comment on column ALL_TRIGGERS.STATUS is
  518. 'If DISABLED then trigger will not fire'
  519. /
  520. comment on column ALL_TRIGGERS.DESCRIPTION is
  521. 'Trigger description, useful for re-creating trigger creation statement'
  522. /
  523. comment on column ALL_TRIGGERS.TRIGGER_BODY is
  524. 'Action taken by this trigger when it fires'
  525. /
  526. drop public synonym ALL_TRIGGERS
  527. /
  528. create public synonym ALL_TRIGGERS for ALL_TRIGGERS
  529. /
  530. grant select on ALL_TRIGGERS to public with grant option
  531. /
  532.  
  533. create or replace view DBA_TRIGGERS
  534. (OWNER, TRIGGER_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME,
  535.  REFERENCING_NAMES, WHEN_CLAUSE, STATUS, DESCRIPTION, TRIGGER_BODY)
  536. as
  537. select trigusr.name, trigobj.name,
  538. decode(t.type, 0, 'BEFORE STATEMENT',
  539.                1, 'BEFORE EACH ROW',
  540.                2, 'AFTER STATEMENT',
  541.                3, 'AFTER EACH ROW', 'UNDEFINED'),
  542. decode(t.insert$*100 + t.update$*10 + t.delete$,
  543.                  100, 'INSERT',
  544.                  010, 'UPDATE',
  545.                  001, 'DELETE',
  546.                  110, 'INSERT OR UPDATE',
  547.                  101, 'INSERT OR DELETE',
  548.                  011, 'UPDATE OR DELETE',
  549.                  111, 'INSERT OR UPDATE OR DELETE', 'ERROR'),
  550. tabusr.name, tabobj.name, 
  551. 'REFERENCING NEW AS '||t.refnewname||' OLD AS '||t.refoldname,
  552. t.whenclause,decode(t.enabled, 0, 'DISABLED', 1, 'ENABLED', 'ERROR'),
  553. t.definition,t.action
  554. from sys.obj$ trigobj, sys.obj$ tabobj, sys.trigger$ t,
  555.      sys.user$ tabusr, sys.user$ trigusr
  556. where trigobj.obj#   = t.obj#
  557.   and tabobj.obj#    = t.baseobject
  558.   and tabobj.owner#  = tabusr.user#
  559.   and trigobj.owner# = trigusr.user#
  560. /
  561. comment on table DBA_TRIGGERS is
  562. 'All triggers in the database'
  563. /
  564. comment on column DBA_TRIGGERS.OWNER is
  565. 'Owner of the trigger'
  566. /
  567. comment on column DBA_TRIGGERS.TRIGGER_NAME is
  568. 'Name of the trigger'
  569. /
  570. comment on column DBA_TRIGGERS.TRIGGER_TYPE is
  571. 'When the trigger fires - BEFORE/AFTER and STATEMENT/ROW'
  572. /
  573. comment on column DBA_TRIGGERS.TRIGGERING_EVENT is
  574. 'Statement that will fire the trigger - INSERT, UPDATE and/or DELETE'
  575. /
  576. comment on column DBA_TRIGGERS.TABLE_OWNER is
  577. 'Owner of the table that this trigger is associated with'
  578. /
  579. comment on column DBA_TRIGGERS.TABLE_NAME is
  580. 'Name of the table that this trigger is associated with'
  581. /
  582. comment on column DBA_TRIGGERS.REFERENCING_NAMES is
  583. 'Names used for referencing to OLD and NEW values within the trigger'
  584. /
  585. comment on column DBA_TRIGGERS.WHEN_CLAUSE is
  586. 'WHEN clause must evaluate to true in order for triggering body to execute'
  587. /
  588. comment on column DBA_TRIGGERS.STATUS is
  589. 'If DISABLED then trigger will not fire'
  590. /
  591. comment on column DBA_TRIGGERS.DESCRIPTION is
  592. 'Trigger description, useful for re-creating trigger creation statement'
  593. /
  594. comment on column DBA_TRIGGERS.TRIGGER_BODY is
  595. 'Action taken by this trigger when it fires'
  596. /
  597.  
  598. remark
  599. remark    USER_TRIGGER_COLS shows usage of columns in triggers owned by the
  600. remark    current user or in triggers on tables owned by the current user
  601. remark
  602.  
  603. create or replace view USER_TRIGGER_COLS
  604. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  605.     COLUMN_LIST, COLUMN_USAGE)
  606. as
  607. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  608.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  609.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  610.                               6,  2, -- one occurrence of old in
  611.                               9,  4, -- one occurrence of new out
  612.                              10,  8, -- one occurrence of old out (impossible)
  613.                              13,  5, -- one occurrence of new in out
  614.                              14, 10, -- one occurrence of old in out (imp.)
  615.                               null)
  616.                 ), -- result in the following combinations across occurrences
  617.            1, 'NEW IN',
  618.            2, 'OLD IN',
  619.            3, 'NEW IN OLD IN',
  620.            4, 'NEW OUT',
  621.            5, 'NEW IN OUT',
  622.            6, 'NEW OUT OLD IN',
  623.            7, 'NEW IN OUT OLD IN',
  624.           'NONE')
  625. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  626.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  627. where t.obj# = tc.obj#        -- find corresponding trigger definition
  628.   and o.obj# = t.obj#        --    and corresponding trigger name
  629.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  630.   and c.col# = tc.col#        --    the referenced column
  631.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  632.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  633.   and u.user# = o.owner#    -- and name of user who owns the trigger
  634.   and ((o.owner# = userenv('SCHEMAID') and u.user# = userenv('SCHEMAID')) -- triggers owned by the current user
  635.       or
  636.        (o2.owner# = userenv('SCHEMAID') and u2.user# = userenv('SCHEMAID'))) -- on the current user's tables
  637. group by u.name, o.name, u2.name, o2.name, c.name
  638. /
  639. comment on table USER_TRIGGER_COLS is
  640. 'Column usage in user''s triggers'
  641. /
  642. comment on column USER_TRIGGER_COLS.TRIGGER_OWNER is
  643. 'Owner of the trigger'
  644. /
  645. comment on column USER_TRIGGER_COLS.TRIGGER_NAME is
  646. 'Name of the trigger'
  647. /
  648. comment on column USER_TRIGGER_COLS.TABLE_OWNER is
  649. 'Owner of the table'
  650. /
  651. comment on column USER_TRIGGER_COLS.TABLE_NAME is
  652. 'Name of the table on which the trigger is defined'
  653. /
  654. comment on column USER_TRIGGER_COLS.COLUMN_NAME is
  655. 'Name of the column used in trigger definition'
  656. /
  657. comment on column USER_TRIGGER_COLS.COLUMN_LIST is
  658. 'Is column specified in UPDATE OF clause?'
  659. /
  660. comment on column USER_TRIGGER_COLS.COLUMN_USAGE is
  661. 'Usage of column within trigger body'
  662. /
  663. drop public synonym USER_TRIGGER_COLS
  664. /
  665. create public synonym USER_TRIGGER_COLS for USER_TRIGGER_COLS
  666. /
  667. grant select on USER_TRIGGER_COLS to public
  668. /
  669. remark
  670. remark    ALL_TRIGGER_COLS shows usage of columns in triggers owned by the
  671. remark    current user or in triggers on tables owned by the current user
  672. remark    or on all triggers if current user has CREATE ANY TRIGGER privilege
  673. remark    (either directly or through a role).
  674. remark
  675.  
  676. create or replace view ALL_TRIGGER_COLS
  677. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  678.     COLUMN_LIST, COLUMN_USAGE)
  679. as
  680. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  681.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  682.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  683.                               6,  2, -- one occurrence of old in
  684.                               9,  4, -- one occurrence of new out
  685.                              10,  8, -- one occurrence of old out (impossible)
  686.                              13,  5, -- one occurrence of new in out
  687.                              14, 10, -- one occurrence of old in out (imp.)
  688.                               null)
  689.                 ), -- result in the following combinations across occurrences
  690.            1, 'NEW IN',
  691.            2, 'OLD IN',
  692.            3, 'NEW IN OLD IN',
  693.            4, 'NEW OUT',
  694.            5, 'NEW IN OUT',
  695.            6, 'NEW OUT OLD IN',
  696.            7, 'NEW IN OUT OLD IN',
  697.           'NONE')
  698. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  699.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  700. where t.obj# = tc.obj#        -- find corresponding trigger definition
  701.   and o.obj# = t.obj#        --    and corresponding trigger name
  702.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  703.   and c.col# = tc.col#        --    the referenced column
  704.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  705.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  706.   and u.user# = o.owner#    -- and name of user who owns the trigger
  707.   and
  708.   ( o.owner# = userenv('SCHEMAID') or o2.owner# = userenv('SCHEMAID')
  709.     or
  710.     exists    -- an enabled role (or current user) with CREATE ANY TRIGGER priv
  711.      ( select null from sys.sysauth$ sa    -- does 
  712.        where privilege# = -152             -- CREATE ANY TRIGGER privilege exist
  713.        and (grantee# in                    -- for current user or public
  714.             (select kzsrorol from x$kzsro) -- currently enabled role
  715.            )
  716.       )
  717.    )
  718. group by u.name, o.name, u2.name, o2.name, c.name
  719. /
  720. comment on table ALL_TRIGGER_COLS is
  721. 'Column usage in user''s triggers or in triggers on user''s tables'
  722. /
  723. comment on column ALL_TRIGGER_COLS.TRIGGER_OWNER is
  724. 'Owner of the trigger'
  725. /
  726. comment on column ALL_TRIGGER_COLS.TRIGGER_NAME is
  727. 'Name of the trigger'
  728. /
  729. comment on column ALL_TRIGGER_COLS.TABLE_OWNER is
  730. 'Owner of the table'
  731. /
  732. comment on column ALL_TRIGGER_COLS.TABLE_NAME is
  733. 'Name of the table on which the trigger is defined'
  734. /
  735. comment on column ALL_TRIGGER_COLS.COLUMN_NAME is
  736. 'Name of the column used in trigger definition'
  737. /
  738. comment on column ALL_TRIGGER_COLS.COLUMN_LIST is
  739. 'Is column specified in UPDATE OF clause?'
  740. /
  741. comment on column ALL_TRIGGER_COLS.COLUMN_USAGE is
  742. 'Usage of column within trigger body'
  743. /
  744. drop public synonym ALL_TRIGGER_COLS
  745. /
  746. create public synonym ALL_TRIGGER_COLS for ALL_TRIGGER_COLS
  747. /
  748. grant select on ALL_TRIGGER_COLS to public
  749. /
  750. remark
  751. remark    DBA_TRIGGER_COLS shows usage of columns in all triggers defined
  752. remark    by any user, on any user's table.
  753. remark
  754.  
  755. create or replace view DBA_TRIGGER_COLS
  756. (TRIGGER_OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, COLUMN_NAME,
  757.     COLUMN_LIST, COLUMN_USAGE)
  758. as
  759. select /*+ ORDERED NOCOST */ u.name, o.name, u2.name, o2.name, c.name,
  760.    max(decode(tc.type,0,'YES','NO')) COLUMN_LIST,
  761.    decode(sum(decode(tc.type, 5,  1, -- one occurrence of new in
  762.                               6,  2, -- one occurrence of old in
  763.                               9,  4, -- one occurrence of new out
  764.                              10,  8, -- one occurrence of old out (impossible)
  765.                              13,  5, -- one occurrence of new in out
  766.                              14, 10, -- one occurrence of old in out (imp.)
  767.                               null)
  768.                 ), -- result in the following combinations across occurrences
  769.            1, 'NEW IN',
  770.            2, 'OLD IN',
  771.            3, 'NEW IN OLD IN',
  772.            4, 'NEW OUT',
  773.            5, 'NEW IN OUT',
  774.            6, 'NEW OUT OLD IN',
  775.            7, 'NEW IN OUT OLD IN',
  776.           'NONE')
  777. from sys.trigger$ t, sys.obj$ o, sys.user$ u, sys.user$ u2,
  778.      sys.col$ c, sys.obj$ o2, sys.triggercol$ tc
  779. where t.obj# = tc.obj#        -- find corresponding trigger definition
  780.   and o.obj# = t.obj#        --    and corresponding trigger name
  781.   and c.obj# = t.baseobject     -- and corresponding row in COL$ of
  782.   and c.col# = tc.col#        --    the referenced column
  783.   and o2.obj# = t.baseobject    -- and name of the table containing the trigger
  784.   and u2.user# = o2.owner#    -- and name of the user who owns the table
  785.   and u.user# = o.owner#    -- and name of user who owns the trigger
  786. group by u.name, o.name, u2.name, o2.name, c.name
  787. /
  788. comment on table DBA_TRIGGER_COLS is
  789. 'Column usage in all triggers'
  790. /
  791. comment on column DBA_TRIGGER_COLS.TRIGGER_OWNER is
  792. 'Owner of the trigger'
  793. /
  794. comment on column DBA_TRIGGER_COLS.TRIGGER_NAME is
  795. 'Name of the trigger'
  796. /
  797. comment on column DBA_TRIGGER_COLS.TABLE_OWNER is
  798. 'Owner of the table'
  799. /
  800. comment on column DBA_TRIGGER_COLS.TABLE_NAME is
  801. 'Name of the table on which the trigger is defined'
  802. /
  803. comment on column DBA_TRIGGER_COLS.COLUMN_NAME is
  804. 'Name of the column used in trigger definition'
  805. /
  806. comment on column DBA_TRIGGER_COLS.COLUMN_LIST is
  807. 'Is column specified in UPDATE OF clause?'
  808. /
  809. comment on column DBA_TRIGGER_COLS.COLUMN_USAGE is
  810. 'Usage of column within trigger body'
  811. /
  812.  
  813. remark
  814. remark    FAMILY "DEPENDENCIES"
  815. remark    Dependencies between database objects
  816. remark
  817.  
  818. create or replace view USER_DEPENDENCIES
  819.   (NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  820.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  821. as
  822. select o.name,
  823.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  824.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  825.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  826.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  827.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  828.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  829.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  830.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  831.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  832.        po.linkname
  833. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ pu
  834. where o.obj# = d.d_obj#
  835.   and po.obj# = d.p_obj#
  836.   and po.owner# = pu.user#
  837.   and o.owner# = userenv('SCHEMAID')
  838. /
  839. comment on table USER_DEPENDENCIES is
  840. 'Dependencies to and from a users objects'
  841. /
  842. comment on column USER_DEPENDENCIES.NAME is
  843. 'Name of the object'
  844. /
  845. comment on column USER_DEPENDENCIES.TYPE is
  846. 'Type of the object'
  847. /
  848. comment on column USER_DEPENDENCIES.REFERENCED_OWNER is
  849. 'Owner of referenced object (remote owner if remote object)'
  850. /
  851. comment on column USER_DEPENDENCIES.REFERENCED_NAME is
  852. 'Name of referenced object'
  853. /
  854. comment on column USER_DEPENDENCIES.REFERENCED_TYPE is
  855. 'Type of referenced object'
  856. /
  857. comment on column USER_DEPENDENCIES.REFERENCED_LINK_NAME is
  858. 'Name of dblink if this is a remote object'
  859. /
  860. drop public synonym USER_DEPENDENCIES
  861. /
  862. create public synonym USER_DEPENDENCIES for USER_DEPENDENCIES
  863. /
  864. grant select on USER_DEPENDENCIES to public with grant option
  865. /
  866.  
  867. create or replace view ALL_DEPENDENCIES
  868.   (OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  869.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  870. as
  871. select u.name, o.name,
  872.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  873.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  874.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  875.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  876.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  877.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  878.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  879.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  880.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  881.        po.linkname
  882. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ u, sys.user$ pu
  883. where o.obj# = d.d_obj#
  884.   and o.owner# = u.user#
  885.   and po.obj# = d.p_obj#
  886.   and po.owner# = pu.user#
  887.   and
  888.   (
  889.     o.owner# in (userenv('SCHEMAID'), 1 /* PUBLIC */)
  890.     or
  891.     (
  892.       (
  893.          (
  894.           (o.type = 7 or o.type = 8 or o.type = 9)
  895.           and
  896.           o.obj# in (select obj# from sys.objauth$
  897.                      where grantee# in (select kzsrorol from x$kzsro)
  898.                        and privilege#  = 12 /* EXECUTE */)
  899.         )
  900.         or
  901.         (
  902.           o.type = 4
  903.           and
  904.           o.obj# in (select obj# from sys.objauth$
  905.                      where grantee# in (select kzsrorol from x$kzsro)
  906.                        and privilege# in (3 /* DELETE */,   6 /* INSERT */,
  907.                                             7 /* LOCK */,     9 /* SELECT */,
  908.                                           10 /* UPDATE */))
  909.         )
  910.         or
  911.         exists
  912.         (
  913.           select null from sys.sysauth$
  914.           where grantee# in (select kzsrorol from x$kzsro)
  915.           and
  916.           (
  917.             (
  918.               /* procedure */
  919.               (o.type = 7 or o.type = 8 or o.type = 9)
  920.               and
  921.               (
  922.                 privilege# = -144 /* EXECUTE ANY PROCEDURE */
  923.                 or
  924.                 privilege# = -141 /* CREATE ANY PROCEDURE */
  925.               )
  926.             )
  927.         or
  928.             (
  929.               /* package body */
  930.               o.type = 11 and
  931.               privilege# = -141 /* CREATE ANY PROCEDURE */
  932.             )
  933.             or
  934.             (
  935.               /* view */
  936.               o.type = 4
  937.               and
  938.               (
  939.                 privilege# in     ( -91 /* CREATE ANY VIEW */,
  940.                     -45 /* LOCK ANY TABLE */,
  941.                                     -47 /* SELECT ANY TABLE */,
  942.                                     -48 /* INSERT ANY TABLE */,
  943.                                     -49 /* UPDATE ANY TABLE */,
  944.                                     -50 /* DELETE ANY TABLE */)
  945.               )
  946.             )
  947.           )
  948.         )
  949.       )
  950.     )
  951.     /* don't worry about tables, sequences, synonyms since they cannot */
  952.     /* depend on anything */
  953.   )
  954. /
  955. comment on table ALL_DEPENDENCIES is
  956. 'Dependencies to and from objects accessible to the user'
  957. /
  958. comment on column ALL_DEPENDENCIES.OWNER is
  959. 'Owner of the object'
  960. /
  961. comment on column ALL_DEPENDENCIES.NAME is
  962. 'Name of the object'
  963. /
  964. comment on column ALL_DEPENDENCIES.TYPE is
  965. 'Type of the object'
  966. /
  967. comment on column ALL_DEPENDENCIES.REFERENCED_OWNER is
  968. 'Owner of referenced object (remote owner if remote object)'
  969. /
  970. comment on column ALL_DEPENDENCIES.REFERENCED_NAME is
  971. 'Name of referenced object'
  972. /
  973. comment on column ALL_DEPENDENCIES.REFERENCED_TYPE is
  974. 'Type of referenced object'
  975. /
  976. comment on column ALL_DEPENDENCIES.REFERENCED_LINK_NAME is
  977. 'Name of dblink if this is a remote object'
  978. /
  979. drop public synonym ALL_DEPENDENCIES
  980. /
  981. create public synonym ALL_DEPENDENCIES for ALL_DEPENDENCIES
  982. /
  983. grant select on ALL_DEPENDENCIES to public with grant option
  984. /
  985.  
  986. create or replace view DBA_DEPENDENCIES
  987.   (OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME,
  988.    REFERENCED_TYPE, REFERENCED_LINK_NAME)
  989. as
  990. select u.name, o.name,
  991.        decode(o.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  992.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  993.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  994.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  995.        decode(po.linkname, null, pu.name, po.remoteowner), po.name,
  996.        decode(po.type, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
  997.                       4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE', 7, 'PROCEDURE',
  998.                       8, 'FUNCTION', 9, 'PACKAGE', 10, 'NON-EXISTENT',
  999.               11, 'PACKAGE BODY', 12, 'TRIGGER', 'UNDEFINED'),
  1000.        po.linkname
  1001. from sys.obj$ o, sys.obj$ po, sys.dependency$ d, sys.user$ u, sys.user$ pu
  1002. where o.obj# = d.d_obj#
  1003.   and o.owner# = u.user#
  1004.   and po.obj# = d.p_obj#
  1005.   and po.owner# = pu.user#
  1006. /
  1007. comment on table DBA_DEPENDENCIES is
  1008. 'Dependencies to and from objects'
  1009. /
  1010. comment on column DBA_DEPENDENCIES.OWNER is
  1011. 'Owner of the object'
  1012. /
  1013. comment on column DBA_DEPENDENCIES.NAME is
  1014. 'Name of the object'
  1015. /
  1016. comment on column DBA_DEPENDENCIES.TYPE is
  1017. 'Type of the object'
  1018. /
  1019. comment on column DBA_DEPENDENCIES.REFERENCED_OWNER is
  1020. 'Owner of referenced object (remote owner if remote object)'
  1021. /
  1022. comment on column DBA_DEPENDENCIES.REFERENCED_NAME is
  1023. 'Name of referenced object'
  1024. /
  1025. comment on column DBA_DEPENDENCIES.REFERENCED_TYPE is
  1026. 'Type of referenced object'
  1027. /
  1028. comment on column DBA_DEPENDENCIES.REFERENCED_LINK_NAME is
  1029. 'Name of dblink if this is a remote object'
  1030. /
  1031.  
  1032.  
  1033. remark
  1034. remark    PUBLIC_DEPENDENCIES
  1035. remark    Hierarchic dependency information by object number
  1036. remark
  1037.  
  1038. create or replace view PUBLIC_DEPENDENCY
  1039.   (OBJECT_ID, REFERENCED_OBJECT_ID)
  1040. as
  1041. select d.d_obj#, d.p_obj# from dependency$ d
  1042. /
  1043. comment on table PUBLIC_DEPENDENCY is
  1044. 'Dependencies to and from objects, by object number'
  1045. /
  1046. comment on column PUBLIC_DEPENDENCY.OBJECT_ID is
  1047. 'Object number'
  1048. /
  1049. comment on column PUBLIC_DEPENDENCY.REFERENCED_OBJECT_ID is
  1050. 'The referenced (parent) object'
  1051. /
  1052. drop public synonym PUBLIC_DEPENDENCY
  1053. /
  1054. create public synonym PUBLIC_DEPENDENCY for PUBLIC_DEPENDENCY
  1055. /
  1056. grant select on PUBLIC_DEPENDENCY to public with grant option
  1057. /
  1058.  
  1059. remark
  1060. remark    FAMILY "OBJECT_SIZE"
  1061. remark    Sizes of pl/sql items.
  1062. remark       source_size - this part must be in memory when the object
  1063. remark                     is compiled, or dynamically recompiled
  1064. remark       parsed_size - this part must be in memory when an object that
  1065. remark                     references this object is being compiled
  1066. remark       code_size   - this part must be in memory when this object
  1067. remark                     is executing
  1068. remark       error_size  - this part exists if the object has compilation
  1069. remark                     errors and need only be in memory until the
  1070. remark                     compilation completes
  1071. remark    Tables and views will also appear if they were ever referenced by
  1072. remark    a pl/sql object.  They will only have a parsed component.
  1073. remark
  1074.  
  1075. remark Define some of the supporting views
  1076.  
  1077. create or replace view CODE_PIECES
  1078. (OBJ#, BYTES)
  1079. as
  1080.   select i.obj#, i.length
  1081.   from sys.idl_ub1$ i
  1082.   where i.part in (1,2)
  1083. union all
  1084.   select i.obj#, i.length
  1085.   from sys.idl_ub2$ i
  1086.   where i.part in (1,2)
  1087. union all
  1088.   select i.obj#, i.length
  1089.   from sys.idl_sb4$ i
  1090.   where i.part in (1,2)
  1091. union all
  1092.   select i.obj#, i.length
  1093.   from sys.idl_char$ i
  1094.   where i.part in (1,2)
  1095. /
  1096.  
  1097. create or replace view CODE_SIZE
  1098. (OBJ#, BYTES)
  1099. as
  1100.   select c.obj#, sum(c.bytes)
  1101.   from sys.code_pieces c
  1102.   group by c.obj#
  1103. /
  1104.  
  1105. create or replace view PARSED_PIECES
  1106. (OBJ#, BYTES)
  1107. as
  1108.   select i.obj#, i.length
  1109.   from sys.idl_ub1$ i
  1110.   where i.part = 0
  1111. union all
  1112.   select i.obj#, i.length
  1113.   from sys.idl_ub2$ i
  1114.   where i.part = 0
  1115. union all
  1116.   select i.obj#, i.length
  1117.   from sys.idl_sb4$ i
  1118.   where i.part = 0
  1119. union all
  1120.   select i.obj#, i.length
  1121.   from sys.idl_char$ i
  1122.   where i.part = 0
  1123. /
  1124.  
  1125. create or replace view PARSED_SIZE
  1126. (OBJ#, BYTES)
  1127. as
  1128.   select c.obj#, sum(c.bytes)
  1129.   from sys.parsed_pieces c
  1130.   group by c.obj#
  1131. /
  1132.  
  1133. create or replace view SOURCE_SIZE
  1134. (OBJ#, BYTES)
  1135. as
  1136.   select s.obj#, sum(length(s.source))
  1137.   from sys.source$ s
  1138.   group by s.obj#
  1139. /
  1140.  
  1141. create or replace view ERROR_SIZE
  1142. (OBJ#, BYTES)
  1143. as
  1144.   select e.obj#, sum(e.textlength)
  1145.   from sys.error$ e
  1146.   group by e.obj#
  1147. /
  1148.  
  1149. create or replace view DBA_OBJECT_SIZE
  1150. (OWNER, NAME, TYPE, SOURCE_SIZE, PARSED_SIZE, CODE_SIZE, ERROR_SIZE)
  1151. as
  1152.   select u.name, o.name,
  1153.   decode(o.type, 2, 'TABLE', 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
  1154.     7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 11, 'PACKAGE BODY',
  1155.     'UNDEFINED'),
  1156.   nvl(s.bytes,0), nvl(p.bytes,0), nvl(c.bytes,0), nvl(e.bytes,0)
  1157.   from sys.obj$ o, sys.user$ u,
  1158.     sys.source_size s, sys.parsed_size p, sys.code_size c, sys.error_size e
  1159.   where o.type in (2, 4, 5, 6, 7, 8, 9, 11)
  1160.     and o.owner# = u.user#
  1161.     and o.obj# = s.obj# (+)
  1162.     and o.obj# = p.obj# (+)
  1163.     and o.obj# = c.obj# (+)
  1164.     and o.obj# = e.obj# (+)
  1165.     and nvl(s.bytes,0) + nvl(p.bytes,0) + nvl(c.bytes,0) + nvl(e.bytes,0) > 0
  1166. /
  1167. comment on table DBA_OBJECT_SIZE is
  1168. 'Sizes, in bytes, of various pl/sql objects'
  1169. /
  1170. comment on column DBA_OBJECT_SIZE.OWNER is
  1171. 'Owner of the object'
  1172. /
  1173. comment on column DBA_OBJECT_SIZE.NAME is
  1174. 'Name of the object'
  1175. /
  1176. comment on column DBA_OBJECT_SIZE.TYPE is
  1177. 'Type of the object: "TABLE", "VIEW", "SYNONYM", "SEQUENCE", "PROCEDURE",
  1178. "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  1179. /
  1180. comment on column DBA_OBJECT_SIZE.SOURCE_SIZE is
  1181. 'Size of the source, in bytes.  Must be in memory during compilation, or
  1182. dynamic recompilation'
  1183. /
  1184. comment on column DBA_OBJECT_SIZE.PARSED_SIZE is
  1185. 'Size of the parsed form of the object, in bytes.  Must be in memory when
  1186. an object is being compiled that references this object'
  1187. /
  1188. comment on column DBA_OBJECT_SIZE.CODE_SIZE is
  1189. 'Code size, in bytes.  Must be in memory when this object is executing'
  1190. /
  1191. comment on column DBA_OBJECT_SIZE.ERROR_SIZE is
  1192. 'Size of error messages, in bytes.  In memory during the compilation of the object when there are compilation errors'
  1193. /
  1194.  
  1195. create or replace view USER_OBJECT_SIZE
  1196. (NAME, TYPE, SOURCE_SIZE, PARSED_SIZE, CODE_SIZE, ERROR_SIZE)
  1197. as
  1198.   select o.name,
  1199.   decode(o.type, 2, 'TABLE', 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
  1200.     7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE', 11, 'PACKAGE BODY',
  1201.     'UNDEFINED'),
  1202.   nvl(s.bytes,0), nvl(p.bytes,0), nvl(c.bytes,0), nvl(e.bytes,0)
  1203.   from sys.obj$ o,
  1204.     sys.source_size s, sys.parsed_size p, sys.code_size c, sys.error_size e
  1205.   where o.type in (2, 4, 5, 6, 7, 8, 9, 11)
  1206.     and o.owner# = userenv('SCHEMAID')
  1207.     and o.obj# = s.obj# (+)
  1208.     and o.obj# = p.obj# (+)
  1209.     and o.obj# = c.obj# (+)
  1210.     and o.obj# = e.obj# (+)
  1211.     and nvl(s.bytes,0) + nvl(p.bytes,0) + nvl(c.bytes,0) + nvl(e.bytes,0) > 0
  1212. /
  1213. comment on table USER_OBJECT_SIZE is
  1214. 'Sizes, in bytes, of various pl/sql objects'
  1215. /
  1216. comment on column USER_OBJECT_SIZE.NAME is
  1217. 'Name of the object'
  1218. /
  1219. comment on column USER_OBJECT_SIZE.TYPE is
  1220. 'Type of the object: "TABLE", "VIEW", "SYNONYM", "SEQUENCE", "PROCEDURE",
  1221. "FUNCTION", "PACKAGE" or "PACKAGE BODY"'
  1222. /
  1223. comment on column USER_OBJECT_SIZE.SOURCE_SIZE is
  1224. 'Size of the source, in bytes.  Must be in memory during compilation, or
  1225. dynamic recompilation'
  1226. /
  1227. comment on column USER_OBJECT_SIZE.PARSED_SIZE is
  1228. 'Size of the parsed form of the object, in bytes.  Must be in memory when
  1229. an object is being compiled that references this object'
  1230. /
  1231. comment on column USER_OBJECT_SIZE.CODE_SIZE is
  1232. 'Code size, in bytes.  Must be in memory when this object is executing'
  1233. /
  1234. comment on column USER_OBJECT_SIZE.ERROR_SIZE is
  1235. 'Size of error messages, in bytes.  In memory during the compilation of the object when there are compilation errors'
  1236. /
  1237. drop public synonym USER_OBJECT_SIZE
  1238. /
  1239. create public synonym USER_OBJECT_SIZE for USER_OBJECT_SIZE
  1240. /
  1241. grant select on USER_OBJECT_SIZE to public with grant option
  1242. /
  1243.