home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / db / rdbms71 / catexp6.sql < prev    next >
Encoding:
Text File  |  1994-08-07  |  25.6 KB  |  673 lines

  1. rem 
  2. rem $Header: catexp6.sql 7010116.1 93/09/26 01:33:06 sylee Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      expvew6.sql - EXPort ViEWs for v6
  7. Rem    DESCRIPTION
  8. Rem      Creates V6.0-style export views against the V7 RDBMS so that EXP V6.0
  9. Rem      can be used to read out the data in a V7 RDBMS
  10. Rem    NOTES
  11. Rem    MODIFIED   (MM/DD/YY)
  12. Rem     vraghuna   08/26/93 -  bug 178457 - increase performance of exucol
  13. Rem     mmoore     11/05/92 -  update tabauth$ 
  14. Rem     vraghuna   11/04/92 -  add tabauth$ from catalog5.sql 
  15. Rem     glumpkin   10/20/92 -  Renamed from EXPVEW6.SQL 
  16. Rem     cheigham   06/25/92 -  redo exu7col, add exu7colnn for dict. changes 
  17. Rem     cheigham   06/23/92 -  fix exucol to accommodate dictionary changes 
  18. Rem     cheigham   03/06/92 -  fix to_date clauses to be language-independent 
  19. Rem     cheigham   02/27/92 -  exclude objects which are in hash clusters 
  20. Rem     cheigham   02/26/92 -  fix exutab query 
  21. Rem     cheigham   02/24/92 -  exclude snapshot,snapshot log tables,views 
  22. Rem     rkooi      01/30/92 -  add newline to end 
  23. Rem     cheigham   01/03/92 -  add _system_audit_options_ table 
  24. Rem     cheigham   01/02/92 -  truncate audit$ columns to 24 chars 
  25. Rem     cheigham   11/20/91 -  fix db link name selection 
  26. Rem     cheigham   10/01/91 -  fix exugrn 
  27. Rem     cheigham   09/25/91 -  create index for privilege views 
  28. Rem     cheigham   09/18/91 -  use distinct(), not group by's, in exudba,exures
  29. Rem     agupta     09/04/91 -  initial revision of file 
  30. Rem     agupta     08/28/91 -  Creation 
  31.  
  32. set echo on;
  33.  
  34. rem this index makes exu(res/dba/cnt) much faster
  35. create index i_sysauth2 on sysauth$(privilege#,grantee#);
  36.  
  37. rem
  38. rem  adding tabauth$ for exugrn
  39. rem Create the security views which emulate the v5 and v6 security tables.
  40. rem 
  41. drop view tabauth$
  42. /                                              
  43. create view tabauth$ (obj#, grantor#, grantee#, time, sequence#, alter$, 
  44.                       delete$,index$, insert$, select$, update$, references$) as
  45.   select obj#, grantor#, grantee#, max(null), min(sequence#),
  46.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  47.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 25, 2), 
  48.       '00', 0, '01', 2, '11', 3, 0),
  49.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  50.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 19, 2), 
  51.       '00', 0, '01', 2, '11', 3, 0),
  52.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  53.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 15, 2), 
  54.       '00', 0, '01', 2, '11', 3, 0),
  55.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  56.        decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  57.               13, 2), '01', 2, '11', 3, 
  58.          decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  59.                 12, '0'), 6, 1), '0', 0, 1)),
  60.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  61.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 7, 2), 
  62.       '00', 0, '01', 2, '11', 3, 0),
  63.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  64.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  65.              5, 2),'01', 2, '11', 3, 
  66.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  67.                  12, '0'), 2, 1), '0', 0, 1)),
  68.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  69.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  70.              3, 2), '01', 2, '11', 3, 
  71.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  72.                  12, '0'), 1, 1), '0', 0, 1))
  73.   from sys.objauth$
  74.   group by obj#, grantor#, grantee#
  75. /
  76. rem all tables 
  77. rem   NOTE: we exclude tables created by snapshots,snapshot logs
  78. rem   and tables in hash clusters since these aren't supported in v6.
  79. drop view exutab;
  80. CREATE VIEW exutab (objid,name, owner, ownerid, tablespace, fileno, blockno,
  81.             audit$, comment$, clusterflag, mtime, modified,
  82.                     pctfree$, pctused$, initrans, maxtrans) AS
  83.        SELECT o$.obj#,o$.name, u$.name, o$.owner#, ts$.name, t$.file#, 
  84.           t$.block#, substr(t$.audit$,1, 24), 
  85.           c$.comment$, NVL(t$.clu#, 0), o$.mtime,
  86.           t$.modified, t$.pctfree$, t$.pctused$, t$.initrans, t$.maxtrans
  87.        FROM sys.tab$ t$, sys.obj$ o$, sys.ts$ ts$, sys.user$ u$, sys.com$ c$,
  88.         sys.clu$ cl$
  89.        WHERE  t$.obj# = o$.obj# and t$.ts# = ts$.ts# and 
  90.               u$.user# = o$.owner# and o$.obj# = c$.obj#(+) 
  91.           and c$.col#(+) is null
  92.           and o$.name NOT LIKE 'SNAP$_%'
  93.           and o$.name NOT LIKE 'MLOG$_%'
  94.           and t$.clu# = cl$.obj#(+)
  95.           and (t$.clu#  is null or cl$.hashkeys = 0)
  96. /
  97. rem tables for incremental export: modified, altered or new
  98. drop view exutabi;
  99. CREATE VIEW exutabi AS 
  100.        SELECT t.* FROM exutab t,incexp i, incvid v
  101.        WHERE t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND
  102.              NVL(i.type,2) = 2 AND  
  103.              (t.modified = 1 OR t.mtime > i.itime OR 
  104.               NVL(i.expid,9999) > v.expid)
  105. /         
  106. rem tables for cumulative export: modified, last export was inc, altered or new
  107. drop view exutabc;
  108. CREATE VIEW exutabc AS 
  109.        SELECT t.* FROM exutab t,incexp i, incvid v
  110.        WHERE  t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND 
  111.              NVL(i.type,2) = 2 AND 
  112.               (t.modified = 1 OR i.itime > NVL(i.ctime,
  113.                                              TO_DATE('01-01-00','DD-MM-YY'))
  114.                OR t.mtime > i.itime OR NVL(i.expid,9999) > v.expid)
  115. /
  116. rem current user's tables 
  117. drop view exutabu;
  118. CREATE VIEW exutabu AS
  119.        SELECT * FROM exutab WHERE ownerid = uid
  120. /
  121. grant select on exutabu to public;
  122.  
  123. rem not null constraints on columns
  124. drop view exucolnn;
  125. CREATE view exucolnn (tobjid, colid, conname, isnull) AS
  126.       SELECT o$.obj#, c$.col#, 
  127.               DECODE(SUBSTR(con$.name,1,5), 'SYS_C', '', NVL(con$.name, '')),
  128.           1
  129.       FROM  sys.obj$ o$, sys.col$ c$, sys.con$ con$, sys.cdef$ cd$,
  130.             sys.ccol$ cc$
  131.       WHERE c$.obj# = o$.obj# and c$.obj# = cc$.obj# and 
  132.             c$.col# = cc$.col# and cc$.con# = cd$.con# and
  133.             cd$.con# = con$.con#(+) and cd$.type =7
  134. /
  135.  
  136. rem all columns  - map v7 type 96 (varchar2) to type 1 (char)
  137. drop view exucol_temp;
  138. CREATE VIEW exucol_temp (tobjid, towner, townerid, tname, name, length, 
  139.             precision, scale, type, isnull, conname, colid, 
  140.             comment$, --default$, 
  141.             dfltlen) AS
  142.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  143.               c$.precision, c$.scale, 
  144.           DECODE(c$.type#, 96, 1, c$.type#), NVL(cn.isnull,0), cn.conname,
  145.               c$.col#, com$.comment$, -- c$.default$, 
  146.           NVL(c$.deflength, 0)
  147.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$,
  148.         sys.com$ com$, sys.exucolnn cn
  149.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  150.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+) and
  151.          c$.obj# = cn.tobjid and c$.col# = cn.colid
  152.     union all
  153.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  154.               c$.precision, c$.scale, 
  155.           DECODE(c$.type#, 96, 1, c$.type#), 0, null,
  156.               c$.col#, com$.comment$, -- c$.default$, 
  157.           NVL(c$.deflength, 0)
  158.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$,
  159.         sys.com$ 
  160.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  161.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+) 
  162.          and not exists
  163.          (select null from sys.exucolnn cn
  164.         where c$.obj# = cn.tobjid and c$.col# = cn.colid)
  165. /
  166. drop view exucol;
  167. CREATE VIEW exucol (tobjid, towner, townerid, tname, name, length, precision, 
  168.             scale, type, isnull, conname, colid, comment$, default$, 
  169.                 dfltlen) AS
  170.     SELECT tobjid, towner, townerid, v$.tname, v$.name, v$.length, 
  171.            v$.precision, v$.scale, type, isnull, conname, colid, comment$,
  172.            default$, dfltlen
  173.     FROM exucol_temp v$, sys.col$ c$
  174.     WHERE c$.obj# = v$.tobjid and c$.col# = v$.colid
  175. /
  176. drop view exucolu;
  177. CREATE VIEW exucolu AS                   /* current user's columns */
  178.        SELECT * from exucol WHERE townerid = uid
  179. /
  180. grant select on exucolu to public;
  181.  
  182. rem all columns for index
  183. drop view exuico;
  184. CREATE VIEW exuico (tobjid, towner, townerid, tname, name, length, precision,
  185.             scale, type, isnull, conname, colid, comment$, default$, 
  186.             dfltlen) AS
  187.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, 0, 0, 0, 0, 0, '',
  188.               i$.pos#, NULL, NULL, 0
  189.        FROM sys.col$ c$, sys.icol$ i$, sys.obj$ o$, sys.user$ u$
  190.        WHERE c$.obj# = i$.bo# and c$.col# = i$.col# and 
  191.          i$.obj# = o$.obj# and o$.owner# = u$.user#
  192. /
  193. drop view exuicou;
  194. CREATE VIEW exuicou AS                   /* current user's columns */
  195.        SELECT * from exuico WHERE townerid = uid
  196. /
  197. grant select on exuicou to public;
  198.  
  199. rem all users with connect (create session priv)
  200. rem drop both table and view; either could be there
  201. drop table exucnt;
  202. drop view exucnt;
  203. create view exucnt as
  204. select distinct(grantee#) from sysauth$
  205. connect by privilege# = prior grantee#
  206. start with privilege#=-5
  207. /
  208. rem all users with resource (unlimited tablespace priv)
  209. drop table exures;
  210. drop view exures;
  211. create view exures as 
  212. select distinct(grantee#) from sysauth$
  213. connect by privilege# = prior grantee#
  214. start with privilege#=-15
  215. /
  216. rem all users with dba (alter system priv)
  217. drop table exudba;
  218. drop view exudba;
  219. create view exudba as
  220. select distinct(grantee#) from sysauth$
  221. connect by privilege# = prior grantee#
  222. start with privilege#=-3
  223. /
  224. drop view exuusr;
  225. CREATE VIEW exuusr (name, userid, passwd, privs, datats, tempts) AS
  226.         SELECT u.name, u.user#, DECODE(u.password, 'N', '', u.password),
  227.     DECODE(c.grantee#, NULL, 'N', 'Y')||
  228.     DECODE(d.grantee#, NULL, 'N', 'Y')||
  229.     DECODE(r.grantee#, NULL, 'N', 'Y'),
  230.         ts1.name, ts2.name       
  231.     FROM sys.user$ u, sys.ts$ ts1, sys.ts$ ts2, sys.exucnt c, 
  232.          sys.exures r, sys.exudba d
  233.         WHERE u.datats# = ts1.ts# 
  234.     and u.tempts# = ts2.ts# 
  235.     and u.user#=c.grantee#(+)
  236.     and u.user#=r.grantee#(+) 
  237.     and u.user#=d.grantee#(+)
  238. /
  239. drop view exuusru;
  240. CREATE VIEW exuusru AS                         /* current user */
  241.        SELECT * FROM exuusr WHERE userid = UID
  242. /
  243. grant select on exuusru to public;
  244.  
  245. rem all grants
  246. drop view exugrn;
  247. CREATE VIEW exugrn (objid, grantor, grantorid, grantee, privs,
  248.                     creatorid, sequence#) AS
  249.     SELECT t$.obj#, ur$.name, t$.grantor#, ue$.name,
  250.            DECODE(t$.alter$, 0, 'N', 2, 'Y', 'G') ||
  251.            DECODE(t$.delete$, 0, 'N', 2,  'Y', 'G') ||
  252.            DECODE(t$.index$, 0, 'N', 2, 'Y', 'G') ||
  253.            DECODE(t$.insert$, 0, 'N', 2, 'Y', 'G') ||
  254.            DECODE(t$.select$, 0, 'N', 2, 'Y', 'G') ||
  255.            DECODE(t$.update$, 0, 'N', 1, 'R', 2, 'Y', 'G') ||
  256.             DECODE(t$.references$, 0, 'N', 2, 'Y', 'G'), 
  257.            o$.owner#, t$.sequence#
  258.        FROM sys.tabauth$ t$, sys.obj$ o$, sys.user$ ur$,
  259.         sys.user$ ue$
  260.        WHERE o$.obj# = t$.obj# AND
  261.              t$.grantor# = ur$.user# AND t$.grantee# = ue$.user#
  262. /
  263. rem first level grants
  264. drop view exugrnu;
  265. CREATE VIEW exugrnu AS
  266.        SELECT * FROM exugrn WHERE grantorid = UID AND creatorid = UID
  267. /
  268. grant select on exugrnu to public;
  269.  
  270. rem all column grants
  271. drop view exucgr;
  272. CREATE VIEW exucgr (objid, grantor, grantorid, grantee, creatorid, cname, 
  273.                sequence#, wgo) AS
  274.        SELECT c$.obj#, ur$.name, c$.grantor#, ue$.name, o$.owner#, cl$.name,
  275.               c$.sequence#, NVL(c$.option$,0)
  276.        FROM sys.objauth$ c$, sys.obj$ o$, sys.user$ ur$, sys.user$ ue$,
  277.             sys.col$ cl$
  278.        WHERE c$.grantor# = ur$.user# AND c$.grantee# = ue$.user# AND
  279.              c$.obj# = o$.obj# AND c$.privilege# = 10 AND 
  280.              c$.obj# = cl$.obj# AND c$.col# = cl$.col#
  281. /
  282. rem first level grants
  283. drop view exucgru;
  284. CREATE VIEW exucgru AS
  285.        SELECT * FROM exucgr WHERE grantorid = UID AND creatorid = UID
  286. /
  287. grant select on exucgru to public;
  288.  
  289. rem all indexes
  290. drop view exuind;
  291. CREATE VIEW exuind (iobjid, iname, iowner, iownerid, ispace, ifileno, iblockno,
  292.             btname, btobjid, btowner, btownerid, unique$,
  293.             cluster$, pctfree$, initrans, maxtrans)  AS
  294.        SELECT i$.obj#, i$.name, ui$.name, i$.owner#, ts$.name, ind$.file#,
  295.           ind$.block#, t$.name, t$.obj#, ut$.name, t$.owner#,
  296.               ind$.unique$, DECODE(t$.type, 3, 1, 0), ind$.pctfree$, 
  297.           ind$.initrans, ind$.maxtrans
  298.        FROM  sys.obj$ t$, sys.obj$ i$, sys.ind$ ind$,
  299.          sys.user$ ui$, sys.user$ ut$, sys.ts$ ts$
  300.        WHERE ind$.bo# = t$.obj# AND ind$.obj# = i$.obj# AND
  301.          ts$.ts# = ind$.ts# AND i$.owner# = ui$.user# AND
  302.              t$.owner# = ut$.user# AND (unique$=0 OR 
  303.          NOT EXISTS (SELECT * from sys.con$ c$
  304.              WHERE c$.owner# = i$.owner#
  305.                          AND   c$.name = i$.name))
  306. /
  307. rem current user indexes
  308. drop view exuindu;
  309. CREATE VIEW exuindu AS
  310.        SELECT * FROM exuind WHERE iownerid = UID and btownerid = UID
  311. /
  312. grant select on exuindu to public;
  313.  
  314. rem all views 
  315. rem  we exclude views created by snapshot logs since they aren't supported
  316. rem  in v6
  317. drop view exuvew;
  318. CREATE VIEW exuvew (vobjid,vname, vlen, vtext, vowner, vownerid,
  319.             vtime, vaudit, vcomment, vcname) AS
  320.        SELECT o$.obj#, o$.name, v$.textlength, v$.text, u$.name, o$.owner#, 
  321.             TO_CHAR(o$.ctime, 'YYMMDDHH24MISS'), 
  322.           substr(v$.audit$, 1, 24), com$.comment$,
  323.               DECODE(SUBSTR(c$.name,1,5), 'SYS_C', '', NVL(c$.name, ''))
  324.        FROM sys.obj$ o$, sys.view$ v$, sys.user$ u$, sys.cdef$ cd$,
  325.             sys.con$ c$, sys.com$ com$
  326.        WHERE o$.obj# = v$.obj# AND o$.owner# = u$.user# AND
  327.          o$.obj# = cd$.obj#(+) AND cd$.con# = c$.con#(+) AND 
  328.              o$.obj# = com$.obj#(+) AND com$.col#(+) is null AND
  329.          o$.name not like 'MVIEW$_%'
  330. /
  331. rem views for incremental export: new or last export not valid
  332. rem cannot use union as in exutabi because of long field
  333. drop view exuvewi;
  334. CREATE VIEW exuvewi AS 
  335.        SELECT vw.* FROM exuvew vw, incexp i, incvid v
  336.        WHERE i.name(+) = vw.vname AND i.owner#(+) = vw.vownerid
  337.              AND v.expid < NVL(i.expid, 9999) AND NVL(i.type, 4) = 4
  338. /         
  339. rem views for cumulative export: new, last export was inc or not valid
  340. drop view exuvewc;
  341. CREATE VIEW exuvewc AS 
  342.        SELECT vw.* FROM exuvew vw, incexp i, incvid v
  343.        WHERE vw.vname = i.name(+) AND vw.vownerid = i.owner#(+) AND 
  344.              NVL(i.type,4) = 4 AND
  345.              (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  346.               v.expid < NVL(i.expid, 9999))
  347. /
  348. rem current user's view
  349. drop view exuvewu;
  350. CREATE VIEW exuvewu AS
  351.        SELECT *    FROM exuvew WHERE vownerid = UID
  352. /
  353. grant select on exuvewu to public;
  354.  
  355. rem all synonyms
  356. drop view exusyn;
  357. CREATE VIEW exusyn (synnam, syntab, tabown, tabnode,
  358.                 public$, synown, synownid, syntime) AS
  359.        SELECT o$.name, s$.name, s$.owner, s$.node,
  360.             DECODE(o$.owner#, 1, 1, 0),
  361.              uo$.name, o$.owner#, TO_CHAR(o$.ctime, 'YYMMDDHH24MISS')
  362.        FROM sys.obj$ o$, sys.syn$ s$, sys.user$ us$, sys.user$ uo$
  363.        WHERE s$.obj# = o$.obj# AND o$.owner# = uo$.user# AND
  364.          s$.owner = us$.name(+)
  365. /
  366. rem synonyms for incremental export: new or last export not valid
  367. drop view exusyni;
  368. CREATE VIEW exusyni AS 
  369.        SELECT s.* FROM exusyn s, incexp i, incvid v
  370.        WHERE s.synnam = i.name(+) AND s.synownid = i.owner#(+) AND 
  371.              NVL(i.type,5) = 5 AND NVL(i.expid,9999) > v.expid
  372. /         
  373. rem synonyms for cumulative export: new, last export was inc or not valid
  374. drop view exusync;
  375. CREATE VIEW exusync AS 
  376.        SELECT s.* FROM exusyn s, incexp i, incvid v
  377.        WHERE  s.synnam  = i.name(+) AND s.synownid = i.owner#(+) AND 
  378.               NVL(i.type,5) = 5 AND
  379.           (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  380.                NVL(i.expid,9999) > v.expid)
  381. /
  382. rem user's synnonyms
  383. drop view exusynu;
  384. CREATE VIEW exusynu AS
  385.        SELECT * FROM exusyn WHERE synownid = UID
  386. /
  387. grant select on exusynu to public;
  388.  
  389. rem clustered tables' columns
  390. drop view exucco;
  391. CREATE VIEW exucco(tname, towner, townerid, cluster$, tcolnam, seq) AS
  392.        SELECT t$.name, u$.name, t$.owner#, c$.name, tc$.name, cc$.col#
  393.        FROM sys.obj$ t$, sys.tab$ tab$, sys.obj$ c$,
  394.         sys.col$ tc$, sys.col$ cc$, sys.user$ u$
  395.        WHERE t$.type = 2 AND t$.obj# = tab$.obj# AND
  396.            tab$.clu# = cc$.obj# AND tab$.obj# = tc$.obj# AND 
  397.              tab$.clu# = c$.obj# AND 
  398.              cc$.segcol# = tc$.segcol# AND t$.owner# = u$.user#
  399. /
  400. rem current user's clustered tables' columns
  401. drop view exuccou;
  402. CREATE VIEW exuccou AS
  403.        SELECT * FROM exucco WHERE townerid = UID
  404. /
  405. grant select on exuccou to public;
  406.  
  407. rem all clusters except HASH clusters (not supported in v6)
  408. drop view exuclu;
  409. CREATE VIEW exuclu (objid, owner, ownerid, name, tblspace, size$, fileno,
  410.                 blockno, mtime, pctfree$, pctused$, initrans, maxtrans) AS
  411.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, ts$.name, 
  412.           NVL(c$.size$, -1), c$.file#, c$.block#, o$.mtime, c$.pctfree$, 
  413.               c$.pctused$, c$.initrans, c$.maxtrans
  414.        FROM sys.obj$ o$, sys.clu$ c$, sys.ts$ ts$, sys.user$ u$
  415.        WHERE o$.obj# = c$.obj# AND c$.ts# = ts$.ts# AND o$.owner# = u$.user#
  416.     AND c$.hashkeys = 0
  417. /
  418. rem clusters for incremental export: new or last export invalid
  419. rem altered cluster is not exported because this would require exporting all
  420. rem tables in it.
  421. drop view exuclui;
  422. CREATE VIEW exuclui AS 
  423.        SELECT c.* FROM exuclu c,incexp i, incvid v
  424.        WHERE c.name  = i.name(+) AND c.ownerid = i.owner#(+) AND
  425.          NVL(i.expid,9999) > v.expid
  426. /         
  427. rem clusters for cumulative export: last export was inc or new
  428. rem altered cluster is not exported because this would require exporting all
  429. rem tables in it.
  430. drop view exucluc;
  431. CREATE VIEW exucluc AS 
  432.        SELECT c.* FROM exuclu c,incexp i, incvid v
  433.        WHERE c.name = i.name(+) AND c.ownerid = i.owner#(+) AND 
  434.              NVL(i.type,3) = 3 AND
  435.           (i.itime > NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY'))
  436.              OR NVL(i.expid,9999) > v.expid)
  437. /
  438. rem current user's clusters
  439. drop view exucluu;
  440. CREATE VIEW exucluu AS
  441.        SELECT * FROM exuclu WHERE ownerid = UID
  442. /
  443. grant select on exucluu to public;
  444.  
  445. rem all storage parameters
  446. drop view exusto;
  447. CREATE VIEW exusto (ownerid, fileno, blockno, iniext, sext, minext,
  448.                     maxext, pctinc, blocks) AS
  449.        SELECT user#, file#, block#, iniexts, extsize, minexts, maxexts, 
  450.               extpct, blocks
  451.        FROM sys.seg$
  452.  
  453. rem storage parameters for current user's segments
  454. drop view exustou;
  455. CREATE VIEW exustou AS
  456.        SELECT * FROM exusto WHERE ownerid = UID
  457. /
  458. grant select on exustou to public;
  459.  
  460. rem all tablespaces
  461. drop view exutbs;
  462. CREATE VIEW exutbs (id, owner, name, isonline, iniext, sext, pctinc,
  463.             minext, maxext) AS
  464.        SELECT ts$.ts#, 'SYSTEM', ts$.name, 
  465.           DECODE(ts$.online$, 1, 'ONLINE', 'OFFLINE'), ts$.dflinit,
  466.              ts$.dflincr, ts$.dflextpct, ts$.dflminext, ts$.dflmaxext
  467.        FROM sys.ts$ ts$ 
  468.        WHERE ts$.online$ in (1, 2) and ts$.ts# != 0
  469. /
  470.  
  471. rem tablespace quotas
  472. drop view exutsq;
  473. CREATE VIEW exutsq(tsname, tsid, uname, maxblocks) AS
  474.        SELECT t$.name, q$.ts#, u$.name, q$.maxblocks
  475.        FROM  sys.ts$ t$, sys.tsq$ q$, sys.user$ u$
  476.        WHERE  q$.user# = u$.user# AND q$.ts# = t$.ts# AND q$.maxblocks != 0
  477. /
  478.  
  479. rem block size
  480. drop view exubsz;
  481. CREATE VIEW exubsz(blocksize) AS
  482.        SELECT ts$.blocksize
  483.        FROM   sys.ts$ ts$
  484. /
  485. grant select on exubsz to public;
  486.  
  487. rem all files
  488. drop view exufil;
  489. CREATE VIEW exufil(fname, fsize, tsid) AS
  490.        SELECT v$.name, f$.blocks, f$.ts#
  491.        FROM   sys.file$ f$, sys.v$dbfile v$
  492.        WHERE  f$.file# = v$.file#
  493. /
  494.  
  495. rem all database links
  496. rem in v7, db link names can be longer than in v6.  We compress the form
  497. rem  'x.y[.a.b]' to 'x'.  If the name is of form 'x', it is unchanged.
  498. drop view exulnk;
  499. CREATE VIEW exulnk (owner, ownerid, name, user$, passwd, host, public$) AS
  500.        SELECT DECODE(l$.owner#, 1, 'SYSTEM', u$.name), l$.owner#,
  501.     decode(instr(l$.name,'.'), 0, l$.name,
  502.            substr(l$.name, 1, instr(l$.name,'.')-1)),
  503.               l$.userid, l$.password, l$.host, DECODE(l$.owner#, 1, 1, 0)
  504.        FROM sys.user$ u$, sys.link$ l$
  505.        WHERE u$.user# = l$.owner#
  506. /
  507. drop view exulnku;
  508. CREATE VIEW exulnku AS                /* current user's database links */
  509.        SELECT * FROM exulnk WHERE ownerid = UID
  510. /
  511. grant select on exulnku to public;
  512.  
  513. rem all rollback segments
  514. drop view exursg;
  515. CREATE VIEW exursg (name, space$, fileno , blockno, minext, public$) AS 
  516.        SELECT r$.name, ts$.name, r$.file#, r$.block#, s$.minexts,
  517.              DECODE(r$.user#, 1, 1, 0)
  518.        FROM sys.ts$ ts$, sys.undo$ r$, sys.seg$ s$
  519.        WHERE r$.status$ != 1 AND r$.file# = s$.file# AND r$.block# = s$.block#
  520.              AND s$.ts# = ts$.ts# and r$.us# != 0
  521. /
  522.  
  523. rem info on deleted object
  524. drop view exudel;
  525. CREATE VIEW exudel (owner, name, type, type#) AS
  526.        SELECT u$.name, i$.name, DECODE(i$.type, 2, 'TABLE', 3, 
  527.               'CLUSTER', 4, 'VIEW', 5, 'SYNONYM'), i$.type
  528.        FROM sys.incexp i$, sys.user$ u$
  529.        WHERE i$.owner# = u$.user# AND
  530.              (i$.owner#, i$.name, i$.type) 
  531.              NOT IN (SELECT o$.owner#, o$.name, o$.type 
  532.              FROM   sys.obj$ o$
  533.                      WHERE  o$.linkname is null
  534.             )
  535. /
  536.  
  537. rem info on sequence number
  538. drop view exuseq;
  539. CREATE VIEW exuseq (owner, ownerid, name, objid, curval, minval, maxval, 
  540.             incr, cache, cycle, order$, audt) AS
  541.        SELECT u.name, u.user#, o.name, o.obj#, s.highwater, s.minvalue, 
  542.           s.maxvalue, s.increment$, s.cache, s.cycle, s.order$, 
  543.           substr(s.audit$, 1, 24)
  544.        FROM sys.obj$ o, sys.user$ u, sys.seq$ s
  545.        WHERE o.obj# = s.obj# AND o.owner# = u.user#
  546. /
  547. drop view exusequ;
  548. CREATE VIEW exusequ AS 
  549.        SELECT * FROM sys.exuseq WHERE UID = ownerid
  550. /
  551. grant select on sys.exusequ to public;
  552.  
  553. rem contraints on table
  554. drop view exucon;
  555. CREATE VIEW exucon (objid, owner, ownerid, tname, type, cname, cno, condition,
  556.                     condlength) AS
  557.        SELECT o.obj#, u.name, c.owner#, o.name, cd.type, 
  558.           DECODE(SUBSTR(c.name,1,5), 'SYS_C', '', NVL(c.name, '')),
  559.               c.con#, cd.condition, cd.condlength
  560.        FROM sys.obj$ o, sys.user$ u, sys.con$ c, sys.cdef$ cd
  561.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND cd.con# = c.con#
  562. /
  563. drop view exuconu;
  564. CREATE VIEW exuconu AS 
  565.        SELECT * FROM sys.exucon WHERE UID = ownerid
  566. /
  567. grant select on sys.exuconu to public;
  568.  
  569. rem referential constraints
  570. drop view exuref;
  571. CREATE VIEW exuref (objid, owner, ownerid, tname, rowner, rtname, cname, cno,
  572.                 rcno) AS
  573.        SELECT o.obj#, u.name, c.owner#, o.name, ru.name, ro.name, 
  574.               DECODE(SUBSTR(c.name, 1, 5), 'SYS_C', '', NVL(c.name, '')),
  575.           c.con#, cd.rcon#
  576.        FROM sys.user$ u, sys.user$ ru, sys.obj$ o, sys.obj$ ro, 
  577.             sys.con$ c, sys.cdef$ cd
  578.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND ro.obj# = cd.robj# AND
  579.              cd.con# = c.con# AND cd.type = 4 AND ru.user# = ro.owner#
  580. /
  581. drop view exurefu;
  582. CREATE VIEW exurefu AS SELECT * FROM sys.exuref WHERE UID = ownerid
  583. /
  584. grant select on sys.exurefu to public;
  585. rem referential constraints for incremental and cumulative export
  586. rem for tables just exported, i.expid will be greater than v.expid
  587. rem as v.expid is incremented only at the end of the incremental export
  588. rem but i.expid is incremented when the table is exported.
  589. rem USED ONLY WHEN REOCRD = YES
  590. drop view exurefic;
  591. CREATE VIEW exurefic AS
  592.        SELECT * FROM sys.exuref 
  593.        WHERE (ownerid, tname) in 
  594.              (SELECT i.owner#, i.name 
  595.               FROM sys.incexp i, sys.incvid v
  596.               WHERE i.expid > v.expid AND i.type = 2)
  597. /
  598. rem referentail constraints for incremental export
  599. rem exutabi will return the correct table name because RECORD = NO
  600. drop view exurefi;
  601. CREATE VIEW exurefi AS
  602.        SELECT * FROM sys.exuref
  603.        WHERE (ownerid, tname) in (SELECT ownerid, name FROM sys.exutabi)
  604. /
  605. rem referentail constraints for cumulative export, assuming
  606. rem exutabc will return the correct table name because RECORD = NO
  607. drop view exurefc;
  608. CREATE VIEW exurefc AS
  609.        SELECT * FROM sys.exuref
  610.        WHERE (ownerid, tname) in (SELECT ownerid, name FROM sys.exutabc)
  611. /
  612.  
  613. rem contraint column list
  614. drop view exuccl;
  615. CREATE VIEW exuccl (ownerid, cno, colname, colno) AS
  616.        SELECT o.owner#, cc.con#, c.name, cc.pos#
  617.        FROM sys.obj$ o, sys.col$ c, sys.ccol$ cc
  618.        WHERE o.obj# = cc.obj# AND c.obj# = cc.obj# AND cc.col# = c.col#
  619. /
  620. drop view exucclu;
  621. CREATE VIEW exucclu AS
  622.        SELECT * FROM sys.exuccl WHERE UID = ownerid
  623. /
  624. grant select on sys.exucclu to public;
  625. drop view exucclo;
  626. CREATE VIEW exucclo (ownerid, cno, colname, colno) AS
  627.     SELECT a.ownerid, a.cno, a.colname, a.colno
  628.     FROM sys.exuccl a, sys.con$ b , sys.cdef$ c
  629.     WHERE b.owner#=UID
  630.     AND   b.con# = c.con#
  631.     AND   c.rcon# = a.cno
  632. /
  633. grant select on sys.exucclo to public;
  634.  
  635. rem replication constraints
  636. drop view exurep;
  637. CREATE VIEW exurep (objid, owner, ownerid, tname, rowner, rtname, cname, 
  638.             sowner, sname, scname, cno, rcno) AS
  639.     SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  640.     FROM dual where 1=2
  641. /
  642. drop view exurepu;
  643. CREATE VIEW exurepu AS SELECT * FROM sys.exurep WHERE UID = ownerid
  644. /
  645. grant select on sys.exurepu to public;
  646.  
  647. rem replication constraints for incremental and cumulative export
  648. rem for tables just exported, i.expid will be greater than v.expid
  649. rem as v.expid is incremented only at the end of the incremental export
  650. rem but i.expid is incremented when the table is exported.
  651. rem USED ONLY WHEN REOCRD = YES
  652. drop view exurepic;
  653. CREATE VIEW exurepic AS
  654.     SELECT * from exurep
  655. /
  656. rem replication constraints for incremental export
  657. rem exutabi will return the correct table name because RECORD = NO
  658. drop view exurepi;
  659. CREATE VIEW exurepi AS
  660.     SELECT * FROM exurep
  661. /
  662. rem replication constraints for cumulative export, assuming
  663. rem exutabc will return the correct table name because RECORD = NO
  664. drop view exurepc;
  665. CREATE VIEW exurepc AS
  666.     SELECT * FROM exurep
  667. /
  668.  
  669. rem v6 export wants this table around; it was discontinued in v7
  670. create table "_system_auditing_options_" (a char(1))
  671. /
  672.