vi editor for Solaris


Conventions

RETURN key
ESCAPE key
DELETE key
press key and type x
italics items to be replaced by your own
requirements

Entering/leaving vi

($ represents Solaris system prompt)
$ vi name open or create file name
$ vi +n name open file at line n
$ vi + name open file at end
$ vi -r list saved files
$ vi -r name recover file name
$ vi name1 name2 edit first file; edit the rest via :n
$ vi -t tag name open file name at tag
$ vi +/pat name open at first occurrence of pat
$ view name open file for read only
:w write changes to file
:w name write to file name
:w! name overwrite file name
:wq write changes and quit
:q quit
:q! quit without saving changes
ZZ exit from vi, saving changes
stop vi for later resumption

vi modes

Command normal and initial mode
(other modes return here when
terminated)
cancels partial command
Insert entered by a i A I o O c C s S R
terminate with
Last line reading input for : / ? or !
terminate with or to
execute

Moving around within the file

move cursor:
h or  to left
to left
to left
j or  to next line
to next line
k or  to previous line
l or  to right
to right
0 to beginning of line
$ to end of line
^ to first non-white on line
w right one word
W right one word past punctuation
b back one word
B back one word past punctuation
e to end of word
E to end of word past punctuation
H to top of screen
L to bottom of screen
M to middle of screen
page forward screenfull
page backward screenfull
scroll down half screenfull
scroll up half screenfull
nG go to line n
G go to last line
/pat go to next line matching pat
?pat go to previous line matching pat
n repeat last / or ?
N repeat last / or ? in reverse direction
/pat/ +n n’th line after pat
?pat? -n n’th line before pat
% find matching (){ or }
) move cursor to next sentence
} move cursor to next paragraph
( move cursor to last sentence
{ move cursor to last paragraph
]] move cursor to next section/function
[[ move cursor to last section/function
fx move to x forward in current line
Fx move to x backward in current line
tx move forward to character before x
Tx move back to character after x
; repeat last f F t T in same direction

, repeat last f F t T in reverse direction
n| move to column n in current line
+ move to next line, at first non-white
- move to previous line, at first non-white

Inserting text

a append text after cursor
A append text at end of line
i insert text before cursor
I insert text at beginning of line
o open line below, ready for text
O open line above, ready for text

Changing Text

cw change word (or part of word)
cc change line
C change part of line to right of cursor
s substitute string for character under cursor
S substitute entire line
rx replace character under cursor with x
r break line at cursor position
R overwrite text to right of cursor
J join line below to current line
xp transpose characters
~ change case of letter
u undo last change
U undo all changes to line
:u undo previous last-line command
. repeat last change

Corrections when adding text

erase last input character
erase last input character
erase last input character
erase all input to start of line
\ escape and
erase last input word
quote non-printing character
backs up one shiftwidth (autoindent)
^ kill autoindent on current line
0 kill all autoindentation
end insertion of text

Deleting text

x delete character under cursor
5x . . . and 4 characters to the right
X delete character before cursor
6X . . . and 5 characters to the left
dw delete word (or part of word)
3dw . . . and 2 complete words to the right
dd delete line
4dd . . . and the 3 following lines
D delete part of line to right of cursor
:5,10 d delete lines 5–10, inclusive
dG delete from current line to end of file

Copying and moving text

yy yank or copy line
3yy . . . and the 2 following lines
dd delete line
p put line below current line
P put line above current line
yw yank or copy word (or part of word)
3yw . . . and 2 complete words to the right
dw delete word (or part of word)
4dw . . . and 3 complete words to the right
p put word after cursor
P put word before cursor
"xy yank item to buffer x
"xd delete into buffer x
"xp put from buffer x, after cursor
"xP put from buffer x, before cursor
"dp retrieve d’th last line
:1,2 co 3 copy lines 1–2 and put after line 3
:4,5 m 6 move lines 4–5 and put after line 6

Searching and replacing

/pat go to next line matching pat
?pat go to previous line matching pat
n repeat last / or ?
N repeat last / or ? in reverse direction
:3,7s/ab/cd/ search lines 3–7 and replace ab by cd
:.,$ search from current line to end of file
:% search the whole file

Pattern-matching characters

^ beginning of line
$ end of line
. any character
\< beginning of word
\> end of word
[str] any character in str
[^str] any character not in str
[x-y] any character between x and y
* any number of preceding pattern

File manipulation

:sh run shell, then exit to return to vi
:!cmd run cmd, then to return to vi
:n edit next file in argument list
:n args specify new argument list
:e name edit file name
:e! re-edit, discarding changes
:e + name edit name, starting at end
:e +n name edit name, starting at line n
:e # edit alternate file
:f or show current file and line
:r name insert file after cursor
:n r name insert file after line n
:ta tag look in tags file for entry under tag
word under cursor is a tag;

Adjusting the screen

clear and redraw screen
re-type, eliminating @ lines
(dumb terminals only)
z redraw screen with current line at top
z- redraw screen with current line at bottom
z. redraw screen with current line at centre
/pat/z- redraw screen with pat line at bottom
zn. use n line window
scroll window down one line
scroll window up one line

Marking and returning

`` return to previous place after / ? G
´´ return after / ? G at first non-white
mx mark position with letter x
`x move cursor to mark x
´x move cursor to mark x at first non-white

Initializing options

EXINIT environment variable for setting options
.exrc startup file for vi; put options here
set x enable option
set nox disable option
set x=val set x to val
set show changed options
set all show all options
set x? show value of option x

Useful configuration options

full short meaning
autoindent ai supply indentation
autowrite aw writes before some commands
ignorecase ic in regular expression matching
list shows tabs as ^I,
end-of-line as $
magic enables metacharacters for
matching
number nu number lines
redraw simulate smart terminal
scroll sets number of lines for scrolling
shiftwidth sw sets number of spaces for
showmatch sm shows matching bracket or brace
slowopen slow prevents fast updating for screen
tabstop ts sets tab intervals
window specifies number of lines in
window
wrapscan ws search wraps round end of file
wrapmargin wm automatic line splitting
Specifying terminal type
(% and $ are system prompts)
% setenv TERM type csh and all Version 6
$ TERM=type; export TERM sh in Version 7
See also man tset
Some terminal types
2621 43 adm31 dw1 h19 vt100
2645 733 adm3a dw2 i100 sun
300s 745 c100 gt40 mime sun-cmd
33 act4 dm1520 gt42 owl
37 act5 dm2500 h1500 t1061
4014 adm3 dm3025 h1510 vt52

Process Scheduler Issue Chart

Process Scheduler Issue Chart

problem

Process scheduler is not booting up and throws following error "message error writing to HTTP stream"

cause

java library is not pinging to the proper directory in psprcs.cfg

solution

set the following parameter in psprcs.cfg:

jvm shared library=

* it should point the jvm.dll for windows environment and jvm.so for unix




Services Running Under Process Scheduler

PSPRCSRV:( PSPRCSRV.EXE)

  1. The server agent is responsible for starting all server processes
  2. Ever fifteen seconds it looks into the process request for server processes that are scheduled to run
  3. if nothing is scheduled the server agent "sleeps for 15 seconds and checks again
  4. if a server process is scheduled the server agent combines the data in the table (PROCESS REQUEST TABEL,PSPRCSRQST) with the process file information found in PSPRCS.CFG and launches the process then it sleeps again.

PSDSTSRV:( PSDSTSRV.EXE)

  1. The distribution agent posts the reports and system log files to the report repository
  2. when the PSPRCSSRV server detects that a process has finished it sends the post report "BEA TUXEDO" service request to the distribution agent to initiate the transfer of the report

PSAESRV:( PSAESRV.EXE)

  1. processes application engine requests
  2. this server must be configured to run if any application engine requests are to be processed by this process scheduler domain

PSAEOSRV: (PSAEOSRV.EXE)

  1. this is a specialized application engine server to run application engine based programs with a proces type of optimization engine.
  2. using a BEA TUXEDO request the PSAEOSRV server communication to the PSOPTENG service
  3. this process the majority of the programe logic

PSOPTENG(PSOPTENG.EXE)

  1. process the core tasks in an optimization engine program

PSDAEMON(PSDAEMON.EXE)

  1. A New daemon process that can be set upto run continuously
  2. when the process schedular is running and is intented for recurrent application engine jobs

Migration PS

Table of Contents

1. Overview. 4

2. Assumptions. 4

3. PeopleSoft Object Migration Steps. 4

4. How are objects tracked?. 6

5. Object Status. 7

6. Stamping a Database (Application Upgrade, Major Release) 8

7. Synchronize Physical Structures of your Tables. 8

8. Audit the Database. 9

9. Migration Paths. 9

10. Conclusion. 10

11. Appendix. 10

1. Overview

The PeopleSoft Object migration process is the method of “moving”, or migrating objects and lines of code from the development to the production environment in phases, after thorough functional testing.

The PeopleSoft Apps DBA generally performs migrations to the production environment at the request of an application developer or functional analyst. Developers are permitted to perform migrations between the development and test environments. Developers need DBA assistance when updating the database with new tables, views, and PeopleSoft Security other than non-development environment.

After unit testing the change in the Development environment, the Apps DBA is notified with a request to move the project from the Development environment to the Test environment. The Apps DBA uses the upgrade copy facility to copy the changed set of objects into the Test environment. The migrated project in the Test database undergoes more rigorous testing. Usually, one or more regression test sets are run to ensure that the issue is resolved and that the change does not adversely effect mainstream processing. Finally, the project is migrated into the Production database. If a problem is found at any stage in the process, then the issue is sent back to the developer and the process begins all over again. It is highly recommended that PeopleSoft objects move from development to test environment and then from Test to Production.

2. Assumptions

Listed below is a set of variables that are referred in the document and what they denote:

  1. DMO – Demo Database
  2. DEV – Development database
  3. TST – Test database
  4. PRD – Production database

3. PeopleSoft Object Migration Steps

The following section describes the steps for migrating changes and fixes to the production environment and the use of the various databases in each phase.

Step 1 – Copy PRD

In this step, the Apps DBA makes copies of the PRD database to create new DEV and TST databases. These databases should represent the current client configuration in the Production environment, with test transactions in place to facilitate the testing of changes and fixes.

Step 2 – Develop / Install Changes

Client-requested changes are developed and Unit Tested in the DEV database. PeopleSoft patches & fixes are installed and tested in DMO, then in DEV. The DEV environment is where problems and issues are identified and resolved, and where the Change Control scripts are developed which will ultimately be applied to TST, and PRD databases via change control.

Step 3 – Migrate Changes to TST

Using the Change Control scripts, the PS Apps DBA moves Objects, Lines of Code and translate values as per the request from the developer or as required by the PS patch/fix from DEV to TST.

Step 4 – Test Changes in TST

Perform Integration Testing of all changes in the “clean” TST database. This process tests the validity of the changes/fixes, and the validity of the Change Control scripts.

Step 5 – Create SYS/QA (Depending Upon Client dB standard)

Make a copy of the Production database (PRD) into SYS/QA. The SYS/QA database provides a final check of the changes and Change Control scripts using the “live” database contents.

In the absence of a SYS/QA database, all system and final testing will be done in TST. The TST database provides a final check of all changes and Change Control scripts using the “live” database contents. In such instance, using the Change Control scripts, the DBA moves all changes from DEV to TST.

Note: The database creation process may not be feasible if the Production database is very large compared to the overall system resources (disk space and processing capacity to build the database). In such cases, a “paired down” SYS/QA database with fewer transactional records may be required. If such an approach is attempted, care must be taken to insure that all “interrelated” data (by time periods, business units, etc.) are kept intact to insure a stable testing environment.

Step 6 – Run Scripts to SYS/QA (only if SYS/QA exists)

Using the Change Control scripts, the PS DBA moves all objects, lines of code and translate values from TST to SYS/QA.

Step 7 – Perform Final Testing in SYS/QA (only if SYS/QA exists)

This is similar to the testing done in Step4 in the TST database, only this time it is done against a snapshot copy of the live production database. This final test verifies once again that the migration scripts are correct, and that no changes have occurred in the production database that have escaped the Change Control process, such that the testing done in TST is invalid.

Step 8 – Run Scripts to PRD

Using the Change Control scripts, the PS Apps DBA moves all changes from TST to PRD.

Note: To “state the obvious”, it should be ensured that a successful backup copy is made of the PRD database before the migration scripts are run.

Step 9 – Delete SYS/QA (only if SYS/QA exists)

Once it is assured that all changes have been successfully installed in PRD, and the production system is stable and operating properly, the SYS/QA database may be deleted.

4. How are objects tracked?

In PeopleSoft 8.x, changes to objects are tracked using the contents of the PSRELEASE table, and the value of two fields, LASTUPDDTTM and LASTUPDOPRID, used in the PeopleTools tables.

The PSRELEASE table contains two fields, RELEASELABEL & RELEASEDTTM. The second field in this table, RELEASEDTTM, stores a date/time stamp for the current release level and all prior release levels.

The LASTUPDDTTM field in the PSDEFN tables—such as PSRECDEFN, PSPNLDEFN, and so on—stores a date/time stamp of when each object was last modified. The LASTUPDOPRID field stores the operator ID of the user who made the modification. If PeopleSoft made the modification, the proprietary ID "PPLSOFT" is used.

Note: Security Administrator prevents the creation of an operator named PPLSOFT.

If an object definition is defined differently in the source database than in the target, check to see whether either object definition has changed since the comparison release. If the object's

LASTUPDDTTM value is greater than the RELEASEDTTM value for the comparison release level (stored in PSRELEASE) the object has changed. If the object's LASTUPDDTTM value is equal to or less than RELEASEDTTM the object has not changed (since the comparison release).

Irrespective of whether the compared object has changed or not, check whether the object has ever been changed prior to the comparison release by an operator other than PeopleSoft (LASTUPDOPRID <> 'PPLSOFT'). If yes, the object is identified as a customization.

5. Object Status

After determining the Report Action, Application Designer defines the status—in both the source and the target—of each object to be Compared or Reported. The following table explains the various status types:

Unknown: Object has not been compared. This is the default status for all objects inserted manually into a project and the permanent status of all non-comparison objects.

Absent: The object was found in the other database, but not in this one. When upgrading to a new PeopleSoft release, all the new objects should have absent status in the target database.

Changed: The object has been compared, its LASTUPDOPRID value is 'PPLSOFT', and its LASTUPDTIME value is greater than the date/time stamp of the comparison release database. In other words, PeopleSoft modified the object since the comparison release.

Unchanged: The object has been compared, its LASTUPDOPRID value is 'PPLSOFT', and its LASTUPDTIME value is less than or equal to the date/time stamp of the comparison release database. In other words, PeopleSoft last modified the object prior to the comparison release.

*Changed: The object has been compared, its LASTUPDOPRID value is not 'PPLSOFT', and its LASTUPDTIME value is greater than the date/time stamp of the comparison release database. In this case, the customer has modified the object since the comparison release.

*Unchanged: The object has been compared, its LASTUPDOPRID value is not 'PPLSOFT', and its LASTUPDTIME value is less than or equal to the date/time stamp of the comparison release database. In this case, the customer last modified the object prior to the comparison release.

The object has been compared and is defined the same in both databases. When an object in one database has this status, so will its counterpart in the other database. This status would never be seen when performing a database comparison because in that case, the project is only populated with objects defined differently. However, it can occur when performing a project comparison because in a project comparison, the project contents are static; the project is not repopulated based on the comparison results.

Application Designer assigns default actions for each object, depending on what needs to be done to make the target database consistent with the source—the major goal of a comparison upgrade. These actions cannot be changed, although it can be decided whether or not to accept each action. Action types include:

Copy Object will be added / replaced to the target database.

Delete Object will be deleted from the target database.

None No Action

One of these action types is assigned to every object in a comparison project and in the Upgrade Reports. These actions are not necessarily carried out during the copy process, however. The Upgrade setting makes that determination.

6. Stamping a Database (Application Upgrade, Major Release)

After successfully copying a project into the target database, it should be "stamped" to reflect the fact that it has changed from its previous customer release level. This will help identify modifications made subsequent to current version of database.

Note: When upgrading to a new PeopleSoft release, this step is required, the database would be stamped with the new PeopleSoft release level

To stamp the target database when migrating from Test to QA only

1. In PS 8.x, Select Tools, Upgrade, and Stamp Database.

The Stamp Database dialog is displayed:

Stamp Database Dialog

Use this dialog to specify, and stamp the database, with a new Customer Release level.

2. Enter the de ASP Issues Reported Customer Release value and click Stamp. The stamp database option is selected as follows:


Tools>>Upgrade>>Stamp Database

Note: The new Customer Release value must be greater than or equal to the previous value.

7. Synchronize Physical Structures of your Tables

Once the copy has been completed, the physical structure of the tables will have to be synchronized with the new definitions and systems components that were merged into the database.

1. SQL Create Tables – This function should be used to create all new tables that were added to the target database during the upgrade copy

2. SQL Alter Records – This function should be used to alter all tables (without deleting)

8. Audit the Database

Run a SYSAUDIT / DDDAUDIT report on both databases before and after migration to see the difference, and to keep track of the status of the objects within the application.

This is to ensure that all the object definitions for the application in both the source and target databases are in sync. If there are any problems reported, fix these problems with top priority.

9. Migration Paths

The following flow chart illustrates the recommended migration path for patches, service packs, and PeopleSoft Hosting customizations as well as future upgrade releases.

10. Conclusion

The migration of PeopleSoft objects should be carried out with great care and accuracy. Care should be taken to ensure that any changes made to the objects, does not have any impact on the functionality of the existing application. If the object changes the functionality, then it should deliver the desired functionality. Hence, testing of the application after applying the changes is a vital step in the migration process.

Oracle Practicals


-------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------Control File----------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------



1 Where is the existing control file located and what is the name?
Hint:
Query the dynamic performance view
V$CONTROLFILE or
V$PARAMETER, or
execute the SHOW PARAMETER command to
display the name and the location of the control file.

SQL> COL name FORMAT a50
SQL>
SELECT * FROM v$controlfile;

STATUS NAME
------- --------------------------------------
/u01/home/db01/ORADATA/u01/ctrl01.ctl
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2 Try to start the database without any control files. (Simulate this by changing the
name of the control file in the parameter file or changing the control file name.)
What happens?

SQL> CONNECT / AS SYSDBA
SQL> SHUTDOWN IMMEDIATE
SQL> !cp $HOME/ORADATA/u01/ctrl01.ctl $HOME/ORADATA/u01/ctrl01.bak
SQL> !rm $HOME/ORADATA/u01/ctrl01.ctl
SQL> STARTUP
SQL> SHUTDOWN IMMEDIATE
SQL> !cp $HOME/ORADATA/u01/ctrl01.bak $HOME/ORADATA/u01/ctrl01.ctl
SQL> STARTUP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3 Multiplex the existing control file, using the directory u02, and name the new control
file ctrl02.ctl. Make sure that the Oracle Server is able to write to the new
control file. For example, on Unix use the command chmod 660. Confirm that both
control files are being used.

SQL> CONNECT / AS SYSDBA
SQL> ALTER SYSTEM SET control_files = '$HOME/ORADATA/u01/ctrl01.ctl',
'$HOME/ORADATA/u02/ctrl02.ctl' SCOPE=SPFILE;
SQL> SHUTDOWN IMMEDIATE;
SQL> !cp $HOME/ORADATA/u01/ctrl01.ctl $HOME/ORADATA/u02/ctrl02.ctl
SQL> !chmod 660 $HOME/ORADATA/u02/ctrl02.ctl
SQL> STARTUP
SQL> SELECT name FROM v$controlfile;
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 What a control file consist of
SQL>Alter database backup controlfile to trace;




-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------Redo Log File----------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------



1 List the number and location of existing log files and display the number of redolog file groups and members your database has.
SQL>SELECT member FROM v$logfile;
SQL> SELECT group#, members FROM v$log;
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 In which database mode is your database configured? Is archiving enabled?
SQL> SELECT log_mode FROM v$database;
SQL> SELECT archiver FROM v$instance;
SQL>ARCHIVE LOG LIST;
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 Add a redo log member to each group in your database located on u04, using the following naming conventions:
Add member to Group 1: log01b.rdo
Add member to Group 2: log02b.rdo
Verify the result.


C:\NEWWORLD\REDO01A.LOG
C:\NEWWORLD\REDO02A.LOG
C:\NEWWORLD\REDO03A.LOG

SQL> ALTER DATABASE ADD LOGFILE MEMBER
'C:\NEWWORLD\REDO01A.LOG' to Group 1,
'C:\NEWWORLD\REDO02A.LOG' to Group 2,
'C:\NEWWORLD\REDO03A.LOG' to Group 3;


SQL> COLUMN GROUP# FORMAT 99
SQL> COLUMN MEMBER FORMAT a40
SQL> SELECT * FROM v$logfile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 Add a redo log group in your database with two members located on u03 and u04 using the following naming conventions:
Add Group 3: log03a.rdo and log03b.rdo Verify the result.
SQL> ALTER DATABASE ADD LOGFILE GROUP 4('C:\NEWWORLD\REDO04.LOG', 'C:\NEWWORLD\REDO04A.LOG') SIZE 1024K;
SQL> COLUMN GROUP# FORMAT 99
SQL> COLUMN MEMBER FORMAT a40
SQL> SELECT * FROM v$logfile;
SQL> SELECT group#, members FROM v$log;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 Remove the redo log group created in step 4.
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> SELECT group#, members FROM v$log;
SQL> ALTER DATABASE DROP LOGFILE GROUP 4;
SQL> !rm $HOME/ORADATA/u03/log03a.rdo
SQL> !rm $HOME/ORADATA/u04/log03b.rdo
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 Resize all online redo log files to 1024 KB. (Because we cannot resize log files, we have to add new logs and drop the old.)

SQL> ALTER DATABASE ADD LOGFILE
GROUP 3( '$HOME/ORADATA/u03/log03a.rdo',
'$HOME/ORADATA/u04/log03b.rdo'
) SIZE 1024K,
GROUP 4( '$HOME/ORADATA/u03/log04a.rdo',
'$HOME/ORADATA/u04/log04b.rdo'
) SIZE 1024K;
Database altered.
SQL> SELECT group#, status FROM v$log;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> ALTER DATABASE DROP LOGFILE GROUP 1, GROUP 2;
SQL> SELECT group#, bytes FROM v$log;



------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------TableSpaces----------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------



1 Create permanent tablespaces with the following names and storage:

a DATA01 data dictionary managed.
SQL> CREATE TABLESPACE data01 DATAFILE 'F:\RAMA\data01.dbf' SIZE 2M EXTENT MANAGEMENT DICTIONARY;

SQL> COLUMN name FORMAT a50
SQL> SET LINESIZE 80
SQL> SET PAGESIZE 999
SQL> SELECT name, bytes, create_bytes FROM v$datafile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
b DATA02 locally managed with uniform sized extents (Ensure that every used extent size in the tablespace is a multiple of 100 KB.)
SQL> CREATE TABLESPACE data02 DATAFILE 'f:\rama\data02.dbf' SIZE 1M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 100K;
SQL> COLUMN name FORMAT a50
SQL> SET LINESIZE 80
SQL> SET PAGESIZE 999
SQL> SELECT name, bytes, create_bytes FROM v$datafile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c. INDX01 locally managed with uniform sized extents of 4K( Enable automatic extension of 500 KB when more extents are required with a
maximum size of 2 MB. )
SQL>CREATE TABLESPACE indx01 DATAFILE 'F:\RAMA\indx01.dbf' SIZE 1M AUTOEXTEND ON NEXT 500K MAXSIZE 2M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 4K;
SQL> COLUMN name FORMAT a50
SQL> SET LINESIZE 80
SQL> SET PAGESIZE 999
SQL> SELECT name, bytes, create_bytes FROM v$datafile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
d.RONLY for read-only tables with the default storage. DO NOT make the tablespace read only at this time.
SQL>CREATE TABLESPACE ronly DATAFILE '$HOME/ORADATA/u01/ronly01.dbf' SIZE 1M;
SQL> COLUMN name FORMAT a50
SQL> SET LINESIZE 80
SQL> SET PAGESIZE 999
SQL> SELECT name, bytes, create_bytes FROM v$datafile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 Allocate 500K more disk space to tablespace DATA02. Verify the result.

SQL> ALTER DATABASE DATAFILE 'F:\RAMA\data02.dbf' RESIZE 1500K;
SQL> COLUMN name FORMAT a40
SQL> SELECT name, bytes, create_bytes FROM v$datafile WHERE name LIKE '%data02%‘;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 Relocate tablespace INDX01 to subdirectory u06.
SQL> ALTER TABLESPACE indx01 OFFLINE;
SQL> SELECT name, status FROM v$datafile;
SQL> !mv $HOME/ORADATA/u02/indx01.dbf $HOME/ORADATA/u06/indx01.dbf
SQL> ALTER TABLESPACE indx01 RENAME DATAFILE '$HOME/ORADATA/u02/indx01.dbf' TO '$HOME/ORADATA/u06/indx01.dbf';
SQL> ALTER TABLESPACE indx01 ONLINE;
SQL> SELECT name, status FROM v$datafile;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 Create a table in tablespace RONLY. Make tablespace RONLY read-only.Attempt to create an additional table. Drop the first created table. What happens
and why?

SQL> CREATE TABLE table1 ( x CHAR(1)) TABLESPACE ronly;
SQL> ALTER TABLESPACE ronly READ ONLY;
SQL> SELECT name, enabled, status FROM v$datafile;
SQL>CREATE TABLE table2 ( y CHAR(1)) TABLESPACE ronly;
SQL> DROP TABLE table1;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 Drop tablespace RONLY and the associated datafile. Verify it.
SQL> DROP TABLESPACE ronly INCLUDING CONTENTS AND DATAFILES;
SQL> SELECT * FROM v$tablespace;
SQL>!ls $HOME/ORADATA/u01/*
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 Set DB_CREATE_FILE_DEST to $HOME/ORADATA/u05 in memory only. Create tablespace DATA03 size 5M. Do not specify a file location. Verify the creation of the
data file.

SQL> ALTER SYSTEM SET DB_CREATE_FILE_DEST='$HOME/ORADATA/u05' SCOPE=MEMORY;
SQL> CREATE TABLESPACE data03 DATAFILE SIZE 5M;
SQL> SELECT * FROM v$tablespace;
SQL> !ls $HOME/ORADATA/u05



-----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------Storage Structure and Relationships---------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------



1 As user SYSTEM, run the following script to create tables and indexes.
SQL> CONNECT system/manager
SQL> CREATE TABLE emp ( empno NUMBER(4),
ename VARCHAR2(30),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2) )
TABLESPACE data01
STORAGE ( INITIAL 100K
NEXT 100K
PCTINCREASE 0
MINEXTENTS 8
MAXEXTENTS 10 );

SQL> CREATE TABLE fragment1( a NUMBER )
TABLESPACE data01
STORAGE( INITIAL 10K );

SQL> CREATE TABLE dept ( deptno NUMBER,
dname VARCHAR2(15),
loc VARCHAR2(20) )
TABLESPACE data01
STORAGE( INITIAL 50K
NEXT 50K );

SQL> CREATE TABLE fragment2( a NUMBER )
TABLESPACE data01
STORAGE ( INITIAL 8K );
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 Identify the different types of segments in the database.
SQL> SELECT DISTINCT segment_type FROM dba_segments;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 Write a query to check which segments are within five extents short of the maximum extents. Ignore the bootstrap segment. This query is useful in identifying any segments that are likely to generate errors during future data load.
SQL> COLUMN segment_name FORMAT a20
SQL> COLUMN segment_type FORMAT a15
SQL> SELECT segment_name,segment_type, max_extents, extents FROM dba_segments WHERE extents+5 > max_extents AND segment_type<>'CACHE';
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 Which files have space allocated for the EMP table?
SQL> CONNECT system/manager
Connected.
SQL> SELECT DISTINCT f.file_name FROM dba_extents e,dba_data_files f WHERE e.segment_name='EMP' AND e.file_id=f.file_id;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 List the free space available by tablespace. The query should display the number of fragments, the total free space, and the largest free extent in each tablespace.
SQL> SELECT tablespace_name,COUNT(*) AS fragments, SUM(bytes) AS total,MAX(bytes) AS largest FROM dba_free_space GROUP BY tablespace_name;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 List segments that will generate errors because of lack of space when they try to allocate an additional extent.
SQL> SELECT s.segment_name, s.segment_type, s.tablespace_name,s.next_extent FROM dba_segments s WHERE NOT EXISTS (SELECT 1 FROM dba_free_space f
WHERE s.tablespace_name=f.tablespace_name HAVING max(f.bytes) > s.next_extent) ;



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------Managing Undo Data----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------



1 Connect as user SYS, and list the undo segments in tablespace UNDOTBS1.
SQL> CONNECT / AS SYSDBA
SQL> SELECT segment_name FROM dba_rollback_segs WHERE tablespace_name = 'UNDOTBS1';
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 Create undo tablespace UNDO2, size 15M, in $HOME/oradata/u03. List the rollback segments in tablespace UNDO2.
SQL> CREATE UNDO TABLESPACE undo2 DATAFILE 'F:\RAMA\DATA02.dbf' SIZE 15M;
SQL> SELECT segment_name FROM dba_---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rollback_segs WHERE tablespace_name = 'UNDO2';
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 In a new telnet session start SQL*Plus and connect as user HR and run script to insert a row into table DEPARTMENTS.
Do not commit, roll back, or exit the session.

SQL> CONNECT hr/hr
SQL> INSERT INTO departments (department_id, department_name) VALUES (9999,'x');
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 In the session in which you are connected as SYS, using the ALTER SYSTEM command, switch the UNDO tablespace from UNDOTBS to UNDO2 for the instance.
SQL> ALTER SYSTEM SET undo_tablespace='UNDO2' SCOPE=BOTH;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 As SYS drop tablespace UNDOTBS1. What happened? Why?
SQL> DROP TABLESPACE undotbs1 INCLUDING CONTENTS AND DATAFILES;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 List the undo segments in tablespace UNDOTBS1 and their status. Compare this list to the list in step 1.
SQL> SELECT segment_name FROM dba_rollback_segs WHERE tablespace_name = 'UNDOTBS1';
SQL> SELECT a.usn,a.name,b.status FROM v$rollname a, v$rollstat b WHERE a.name IN ( SELECT segment_name FROM dba_segments
WHERE tablespace_name = 'UNDOTBS') AND a.usn = b.usn;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 In the session connected as HR, roll back the transaction and exit the session.
SQL> ROLLBACK;
SQL> EXIT;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8 In the session connected as SYS drop tablespace UNDOTBS. What happened? Why?
SQL> DROP TABLESPACE undotbs;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9 As SYS issue the following command:
ALTER SYSTEM SET undo_retention=0 SCOPE=memory;
Now drop tablespace UNDOTBS. What happened? Why?
Note: There still may be a delay before the tablespace is drop.
SQL> ALTER SYSTEM SET undo_retention=0 SCOPE=MEMORY;
SQL> DROP TABLESPACE undotbs INCLUDING CONTENTS AND DATAFILES;



------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------Tables---------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------



1Create the following tables as user SYSTEM for an order entry system that you are implementing now.
SQL> CONNECT system/manager
SQL> CREATE TABLE customers ( cust_code VARCHAR2(3),
name VARCHAR2(50),
region VARCHAR2(5) )
TABLESPACE users;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SQL> CREATE TABLE orders2 ( ord_id NUMBER(3),
ord_date DATE,
cust_code VARCHAR2(3),
date_of_dely DATE )
TABLESPACE users;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2. Insert some records in OrderS2 table.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3 Find which files and blocks contain the rows for the orders table.

SQL> CONNECT system/manager
SQL> SELECT file_id, block_id, blocks
FROM dba_extents
WHERE owner = 'SYSTEM'
AND segment_name = 'ORDERS2'
AND segment_type = 'TABLE';
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 Check the number of extents used by the table ORDERS2.
SQL> SELECT count(*) FROM dba_extents WHERE segment_name='ORDERS2' AND owner='SYSTEM';
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL> CREATE TABLE orders
TABLESPACE users
STORAGE(MINEXTENTS 10)
AS
SELECT * FROM orders2;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL> SELECT count(*) FROM dba_extents WHERE segment_name='ORDERS' AND owner='SYSTEM';
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 Truncate table ORDERS without releasing space and check the number of extents to verify extents have not been deallocated.
SQL> TRUNCATE TABLE orders REUSE STORAGE;
SQL> SELECT count(*)
FROM dba_extents
WHERE segment_name='ORDERS'
AND owner='SYSTEM';
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9 Run the script to insert some rows into the ORDERS2 table.
insert into orders2 VALUES(3,'14-APR-04','D1','14-APR-04');
insert into orders2 VALUES(3,'14-APR-04','D1','14-APR-04');
insert into orders2 VALUES(3,'14-APR-04','D1','14-APR-04');
insert into orders2 VALUES(3,'14-APR-04','D1','14-APR-04');
-
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 View the columns for the ORDERS2 table. Then mark the DATE_OF_DELY column as UNUSED. View the columns for the ORDERS2 table again. What happens?
SQL> DESCRIBE orders2;
SQL> ALTER TABLE orders2 SET UNUSED COLUMN date_of_dely CASCADE CONSTRAINTS;
SQL> DESCRIBE orders2;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
11 Drop the unused column DATE_OF_DELY.
SQL> ALTER TABLE orders2 DROP UNUSED COLUMNS CHECKPOINT 1000;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12 Drop the ORDERS2 table.
SQL> DROP TABLE orders2;



--------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------Indexes----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------



1 You are considering creating indexes on the NAME and REGION columns of the CUSTOMERS table. What types of index are appropriate for the two columns? Create
the indexes, naming them CUST_NAME_IDX and CUST_REGION_IDX, respectively, and placing them in the appropriate tablespaces.

SQL> CONNECT system/manager
SQL> CREATE INDEX cust_name_idx
ON customers(name)
TABLESPACE indx01;
SQL> CREATE BITMAP INDEX cust_region_idx
ON system.customers(region)
TABLESPACE indx01;
-------------------------------------------------------Indexes----------------------------------------------------------------------------------------------------
2 Move the CUST_REGION_IDX index to another tablespace.
SQL> ALTER INDEX cust_region_idx REBUILD TABLESPACE indx;
--------------------------------------------------------Indexes----------------------------------------------------------------------------------------------------
3 Note the files and blocks used by the extents by CUST_REGION_IDX index.
SQL> SELECT file_id, block_id, blocks FROM dba_extents WHERE segment_name='CUST_REGION_IDX' AND owner='SYSTEM';
---------------------------------------------------------------------------------------------Indexes----------------------------------------------------------------------------------------------------
4 Re-create the CUST_REGION_IDX index without dropping and re-creating it, and retain it in the same tablespace as before. Does the new index use the same
blocks that were used earlier?
SQL> ALTER INDEX cust_region_idx REBUILD;
SQL> SELECT file_id, block_id, blocks FROM dba_extents WHERE segment_name='CUST_REGION_IDX' AND owner='SYSTEM';
------------------------------------------------------Indexes----------------------------------------------------------------------------------------------------
2 Query the data dictionary to:

a Check for constraints, whether they are deferrable, and their status.
SQL> COLUMN constraint_name FORMAT a25
SQL> COLUMN table_name FORMAT a10
SQL> COLUMN constraint_type FORMAT a1
SQL> COLUMN deferrable FORMAT a15
SQL> COLUMN status FORMAT a10
SQL> SELECT constraint_name, table_name,constraint_type, deferrable, status FROM dba_constraints WHERE table_name IN
('PRODUCTS','ORDERS','CUSTOMERS') AND owner='SYSTEM';
-----------------------------------------------------Indexes----------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------MANAGING USERS------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------


1 Create a user bob with password bob and assign bob the default table space and temporary tablespace
sql> create user bob identified by bob
default tablespace users
temporary tablespace temp
quota 1m on users
quota 1m on temp;
sql> grant create session to bob;

2 Create a user Emi with a password of MARY. Make sure that any objects and sort
segments created by Emi are not created in the system tablespace.

sql> CREATE USER emi
IDENTIFIED BY mary
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;

3. Display the information on Bob and Emi from the data dictionary.
Hint: This can be obtained by querying DBA_USERS.

sql> SELECT username, default_tablespace,
temporary_tablespace
FROM dba_users
WHERE username IN ('BOB', 'EMI');

4. From the data dictionary, display the information on the amount of space that Bob
can use in tablespaces.
Hint: This can be obtained by querying DBA_TS_QUOTAS.

sql> COLUMN tablespace_name FORMAT a15
sql> COLUMN user FORMAT a10
sql> SELECT *
FROM dba_ts_quotas
WHERE username = 'BOB';

5. As user BOB change his temporary tablespace. What happens? Why?

sql> connect bob/crusader;
sql> ALTER USER bob
TEMPORARY TABLESPACE users;

6. As Bob, change his password to SAM.

sql> connect bob/crusader;
sql> ALTER USER bob
IDENTIFIED BY sam;

7. As SYSTEM, remove Bob’s quota on his default tablespace.

sql> CONNECT system/manager
sql> ALTER USER bob QUOTA 0 ON users;

8. Remove Emi’s account from the database.
Hint: Because Emi owns tables, you need to use the CASCADE option.

sql> DROP USER emi;

9. Bob has forgotten his password. Assign him a password of OLINK and require
that Bob change his password the next time he logs on.

sql> ALTER USER bob
IDENTIFIED BY olink
PASSWORD EXPIRE;

-----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------GRANTING PREVILIGES-----------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------


1 As SYSTEM, create user Emi and give her the capability to log on to the database and
create objects in her schema.

SQL> CONNECT system/manager
SQL> CREATE USER emi
IDENTIFIED BY "abcd12"
DEFAULT TABLESPACE data01
TEMPORARY TABLESPACE temp
QUOTA 1M ON data01;
SQL> GRANT create session, create table TO emi;

2 a Connect as Emi, and create tables using the script lab16_02a.sql to create the
tables CUSTOMERS and ORDERS.

SQL> CONNECT emi/abcd12;
SQL> @$HOME/STUDENT/LABS/lab16_02a.sql;

2 b Connect as SYSTEM and copy the data from SYSTEM.CUSTOMERS to Emi’s
CUSOMTERS table. Verify that records have been inserted.

SQL> CONNECT system/manager;
SQL> INSERT INTO emi.customers
SELECT *
FROM system.customers;
SQL> SELECT * FROM emi.customers;

c. As SYSTEM give Bob the ability to select from Emi's CUSTOMERS table. What
happens and why?

SQL> CONNECT system/manager
SQL> GRANT select ON emi.customers TO bob;

3 Reconnect as Emi and give Bob the ability to select from Emi's CUSTOMERS table.
Also, enable Bob to give the select capability to other users. Examine the data
dictionary views that record these actions.

SQL> CONNECT emi/abcd12;
SQL> GRANT select ON customers
TO bob WITH GRANT OPTION;
SQL> CONNECT system/manager;
SQL> COLUMN grantee FORMAT a8
SQL> COLUMN owner FORMAT a8
SQL> COLUMN table_name FORMAT a10
SQL> COLUMN grantor FORMAT a8
SQL> COLUMN privilege FORMAT a10
SQL> COLUMN grantable FORMAT a3
SQL> COLUMN hiearchy FORMAT a3
SQL> SELECT *
FROM dba_tab_privs
WHERE grantee='BOB';

4 Create user Trevor with the capability to log on to the database.

SQL> CONNECT system/manager
SQL> CREATE USER trevor IDENTIFIED BY "abcd1?";
SQL> GRANT create session TO trevor;


5 a As Bob, enable Trevor to access Emi’s CUSTOMERS table. Give Bob the new
password sam.

SQL> CONNECT bob/olink
SQL> GRANT select ON emi.customers TO trevor;

b As Emi, remove Bob’s privilege to read Emi’s CUSTOMERS table.

SQL> CONNECT emi/abcd12;
SQL> REVOKE select ON customers FROM bob;

c As Trevor, query Emi’s CUSTOEMRS table. What happens and why?

SQL> CONNECT trevor/abcd1?;
SQL> SELECT *
FROM emi.customers;

6 a Enable Emi to create tables in any schema. As Emi, create the table ORDERS in
Bob’s schema as a copy of EMI.ORDERS. What happened and why?

SQL> CONNECT system/manager
SQL> GRANT create any table TO emi;
SQL> CONNECT emi/abcd12
SQL> CREATE TABLE bob.orders
AS
SELECT *
FROM orders;

b As SYSTEM, examine the data dictionary view DBA_TABLES to
check the result.

SQL> CONNECT system/manager
SQL> SELECT owner, table_name
FROM dba_tables
WHERE table_name IN ('CUSMTERS', 'ORDERS');

7 Enable Emi to start up and shut down the database without the ability to create a
new database.

SQL> CONNECT sys/oracle AS SYSDBA
SQL> GRANT sysoper TO emi;

------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------MANAGING ROLES------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------


1 Examine the data dictionary view and list the system privileges of the
RESOURCE role.

SQL> CONNECT system/manager
SQL> COLUMN privilege FORMAT a20
SQL> COLUMN grantee FORMAT a10
SQL> SELECT *
FROM dba_sys_privs
WHERE grantee = 'RESOURCE';

2 Create a role called DEV, which enables a user to create a table, create a view and
select from Emi’s CUSTOMERS table.

SQL> CREATE ROLE dev;
SQL> GRANT create table, create view TO dev;
SQL> CONNECT emi/abcd12
SQL> GRANT select ON customers TO dev;
SQL> CONNECT system/manager
SQL> GRANT dev TO bob;

3 a Assign the RESOURCE and DEV roles to Bob, but make only the
RESOURCE role to be automatically enabled when he logs on.

SQL> CONNECT system/manager
SQL> GRANT dev, resource TO bob;
SQL> ALTER USER bob
DEFAULT ROLE resource;

b Give Bob the ability to read all the data dictionary information.

SQL> connect system/manager;
SQL> GRANT select_catalog_role TO bob;

4 Bob needs to check the undo segments that are currently used by the instance.
Connect as Bob and list the undo segments used.

SQL> CONNECT bob/sam
SQL> SET ROLE select_catalog_role;
SQL> SELECT segment_name
FROM dba_rollback_segs
WHERE status='ONLINE';

5 As SYSTEM, try to create a view CUST_VIEW on Emi’s CUSTOMERS table. What
happens and why?

SQL> connect system/manager
SQL> CREATE VIEW cust_view AS
SELECT *
FROM emi.customers;

6 As user Emi grant select on customers to SYSTEM. As SYSTEM try to create view
CUST_VIEW on Emi’s CUSTOMERS table. What happens and why?

SQL> CONNECT emi/abcd12
SQL> GRANT select ON customers TO system;
SQL> CONNECT system/manager
SQL> CREATE VIEW cust_view AS
SELECT *
FROM emi.customers;


-------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------MAINTAINING DATA INTEGRITY--------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------


1 Examine the script lab13_01.sql. Run the script to create the constraints.

SQL> @$HOME/STUDENT/LABS/lab13_01.sql

2 Query the data dictionary to:
a Check for constraints, whether they are deferrable, and their status.
Hint: Use the DBA_CONSTRAINTS view to get this information.

SQL> COLUMN constraint_name FORMAT a25
SQL> COLUMN table_name FORMAT a10
SQL> COLUMN constraint_type FORMAT a1
SQL> COLUMN deferrable FORMAT a15
SQL> COLUMN status FORMAT a10
SQL> SELECT constraint_name, table_name,
constraint_type, deferrable, status
FROM dba_constraints
WHERE table_name IN
('PRODUCTS','ORDERS','CUSTOMERS')
AND owner='SYSTEM';

2 b Check the names and types of indexes created to validate the constraints.
Hint: The indexes are only created for primary key and unique constraints and
have the same name as the constraints.

SQL> SELECT index_name,table_name,uniqueness
FROM dba_indexes
WHERE index_name in
( SELECT constraint_name
FROM dba_constraints
WHERE table_name IN ('PRODUCTS', 'ORDERS', 'CUSTOMERS')
AND owner='SYSTEM'
AND constraint_type in ('P','U')
);


3 Insert two records with the following values into the PRODUCTS table:

SQL> INSERT INTO system.products
VALUES(4000,'UNIX Monitor',3620);
SQL> INSERT INTO system.products
VALUES(4000,'NT Monitor', 2400);
SQL> COMMIT;

4 Enable the unique constraint on the PRODUCT table. Was it successful?
Why or why not?

SQL> ALTER TABLE system.products
ENABLE CONSTRAINT products_prod_code_uk;

5 a Ensure that new rows added to the table do not violate the constraint on the
PRODUCT table.
Hint: This can be done by enabling the constraint NOVALIDATE.

SQL> ALTER TABLE system.products
ENABLE NOVALIDATE CONSTRAINT products_prod_code_uk;

b Query the data dictionary to verify the effect of the change.

SQL> SELECT constraint_name, table_name,
constraint_type, validated, status
FROM dba_constraints
WHERE table_name = 'PRODUCTS'
AND owner='SYSTEM';

5 c Test that the constraint disables inserts that violate the change by adding a
row with the following values:

3000 Monitor 4000
LIST_PRICE PRODUCT_DESCRIPTION PRODUCT_ID

SQL> INSERT INTO system.products
VALUES(4000,'Monitor',3000);

6 Take the necessary steps to identify existing constraint violations in the PRODUCTS
table, modify product codes as needed, and guarantee that all existing as well as new
data do not violate the constraint. (Assume that the table has several thousands of
rows and it is too time-consuming to verify each row manually.)
Hint: Use the following steps:
a Create the EXCEPTIONS table.

SQL> CONNECT system/manager
SQL> @?/rdbms/admin/utlexcpt

b Run the command to enable the constraint and trap the exceptions.

SQL> ALTER TABLE system.products
ENABLE CONSTRAINT products_prod_code_uk
EXCEPTIONS INTO system.exceptions;

c Use the ROWIDs in the EXCEPTIONS table to list the rows in the
PRODUCTS table that violate the constraint. (Do not list LOB columns.)

SQL> SELECT rowid, prod_code, description
FROM system.products
WHERE rowid IN ( SELECT row_id
FROM exceptions
WHERE table_name='PRODUCTS'
);

6 dRectify the errors.

SQL> UPDATE system.products
SET prod_code='4001'
WHERE rowid = ( SELECT max(row_id)
FROM exceptions
WHERE table_name='PRODUCTS'
);

e Enable the constraint.

SQL> ALTER TABLE system.products
ENABLE CONSTRAINT products_prod_code_uk
EXCEPTIONS INTO system.exceptions;

7 Run the script lab13_07.sql to insert rows into the table. Were the inserts
successful? Roll back the changes.

SQL> @$HOME/STUDENT/LABS/lab13_07.sql
SQL> INSERT INTO system.orders
VALUES (800,'01-JAN-98','J01',NULL);
SQL> INSERT INTO system.customers
VALUES ('J01','Sports Store', 'East');
SQL> ROLLBACK;

8 Now examine the script lab13_08. Notice that this script also performs the
inserts in the same sequence. Run the script and check if it executes successfully.

SQL> @$HOME/STUDENT/LABS/lab13_08.sql
SQL> ALTER SESSION SET CONSTRAINTS=deferred;
SQL> INSERT INTO system.orders
VALUES (800,'01-JAN-98','J01',NULL);
SQL> INSERT INTO system.customers
VALUES ('J01','Sports Store', 'East');
SQL> COMMIT;

9 Truncate the CUSTOMERS table. Was it successful? Why or why not?

SQL> TRUNCATE TABLE system.customers;


-----------------------------------------------------------------------------------------------------------------------------------
--------------------------------------MANAGING PASSWORD SECURITY AND RESOURCES----------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------


1 Run the lab14_01.sql script to create user Jeff. Enable password management
by running script @$ORACLE_HOME/rdbms/admin/utlpwdmg.sql.

SQL> @$HOME/STUDENT/LABS/lab14_01.sql
SQL> @$ORACLE_HOME/rdbms/admin/utlpwdmg.sql

2 Try to change the password of user Jeff to JEFF. What happens?

SQL> ALTER USER jeff IDENTIFIED BY jeff;

3 Try changing the password for Jeff to follow the password management format.
Hint: Password should contain at least one digit, one character, and one punctuation.

SQL> ALTER USER jeff
IDENTIFIED BY super1$;

4 Alter the DEFAULT profile to ensure the following applies to users assigned the
DEFAULT profile:
- After two login attempts, the account should be locked.
- The password should expire after 30 days.
- The same password should not be reused for at least one minute.
- The account should have a grace period of five days to change an expired
password.
- Ensure that the requirements given have been implemented.
Hints:
Use the ALTER PROFILE command to change the default profile limits.
Query the data dictionary view DBA_PROFILES to verify the result.

SQL> ALTER PROFILE default LIMIT
FAILED_LOGIN_ATTEMPTS 2
PASSWORD_LIFE_TIME 30
PASSWORD_REUSE_TIME 1/1440
PASSWORD_GRACE_TIME 5;
SQL> SELECT resource_name, limit
FROM dba_profiles
WHERE profile='DEFAULT'
AND resource_type='PASSWORD';

5 Log in to user Jeff supplying an invalid password. Try this twice, then log in again,
this time supplying the correct password. What happens? Why?

SQL> CONNECT jeff/superman
SQL> CONNECT jeff/super
SQL> CONNECT jeff/super1$

6 Using data dictionary view DBA_USERS verify user Jeff is locked. Unlock the account
for the user Jeff. After unlocking user Jeff connect as Jeff.
Hint: Execute the ALTER USER command to unlock the account.

SQL> CONNECT / AS SYSDBA
SQL> SELECT username, account_status
SQL> ALTER USER jeff
ACCOUNT UNLOCK;
SQL> CONNECT jeff/super1$

7 Disable password checks for the DEFAULT profile.
Hint: Execute the ALTER PROFILE command to disable the password checks.

SQL> ALTER PROFILE default LIMIT
FAILED_LOGIN_ATTEMPTS UNLIMITED
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME UNLIMITED
PASSWORD_GRACE_TIME UNLIMITED;

8 Log in to user Jeff supplying an invalid password. Try this twice, then log in again,
this time supplying the correct password. What happens? Why?

SQL> CONNECT jeff/superman
SQL> CONNECT jeff/super
SQL> CONNECT jeff/super1$