dba lab manual 13-14

25
Nuva College of Engineering and Technology Department of MCA MCA Part-II Sem-I DBA Lab Manual 1. Write procedure to install and test Oracle using advance installation. Installing the Oracle9i Database 1. The Oracle Universal Installer requires 400 MB of temporary space on your C: drive to run successfully. If you do not hat least 400 MB on the C: drive, then update the TEMP user variable in your environment variables and change it to a location with the required amount of space. In addition, make sure that the computer has sufficient system memory (the combination of RAM and virtual memory). If the page file size is too small, messages appear indicating that the computer is running low on virtual memory. Check your page file size to make sure that the initial size is 200 MB and the maximum size is 400 MB. 2. Insert your Oracle9i Enterprise Edition CD-ROM into the CD-ROM drive. In the Autorun window that appears, choose Install/Deinstall Products. If you do not have your laptop set up for Autorun capability, run autorun.exe directly from the AUTORUN directory on your Oracle9i Enterprise Edition CD-ROM. You will install Oracle9i in its own home directory. Click Next to accept the default Oracle_Home name and location. 3. In the Welcome window, click Next. 4.Install Oracle9i in its own home directory. Make sure it says OraHome90 in the Name field, and that the path is d:\oracle\ora90. Then click Next.

Upload: abdulla-shaik

Post on 01-Jan-2016

100 views

Category:

Documents


0 download

DESCRIPTION

DBA LAB

TRANSCRIPT

Page 1: DBA Lab Manual 13-14

Nuva College of Engineering and TechnologyDepartment of MCAMCA Part-II Sem-I DBA Lab Manual

1. Write procedure to install and test Oracle using advance installation.

Installing the Oracle9i Database

1. The Oracle Universal Installer requires 400 MB of temporary space on your C: drive to run successfully. If you do not hat least 400 MB on the C: drive, then update the TEMP user variable in your environment variables and change it to a location with the required amount of space. In addition, make sure that the computer has sufficient system memory (the combination of RAM and virtual memory). If the page file size is too small, messages appear indicating that the computer is running low on virtual memory. Check your page file size to make sure that the initial size is 200 MB and the maximum size is 400 MB.

2. Insert your Oracle9i Enterprise Edition CD-ROM into the CD-ROM drive. In the Autorun window that appears, choose Install/Deinstall Products. If you do not have your laptop set up for Autorun capability, run autorun.exe directly from the AUTORUN directory on your Oracle9i Enterprise Edition CD-ROM. You will install Oracle9i in its own home directory. Click Next to accept the default Oracle_Home name and location.

3. In the Welcome window, click Next.

4.Install Oracle9i in its own home directory. Make sure it says OraHome90 in the Name field, and that the path is d:\oracle\ora90. Then click Next.

Page 2: DBA Lab Manual 13-14

5. Select Oracle9i Database 9.0.1.0.0. Click Next to accept the default.

6. Choose Enterprise Edition and then click Next.

7. Accept the General Purpose default database configuration and click Next.

Page 3: DBA Lab Manual 13-14

8. If a database already exists, you are asked whether you want to upgrade or migrate the database. Do not upgrade or migrate the database: click Next.

9. In the Global Database Name field, enter orcl.world. In the SID field, accept the default, orcl, and then click Next.

10.Change the directory to D:\oracle\oradata and click Next.

Page 4: DBA Lab Manual 13-14

11. Accept the default character set and click Next.

12.The Oracle Universal Installer displays a summary of the installation options. Make sure that you have the required disk space available and then click Install.

13. The Oracle Universal Installer begins installing Oracle9i Enterprise Edition and related software. Note: This process takes at least one hour. The Oracle Universal Installer also creates installation logs as it progresses. You can view these while the installation is in progress. The log for this installation session is located at C:\Program Files\Oracle\Inventory\

logs\installActions.log. If you install another product, the current log is copied to this file and renamed, so there is always a history of each successive installation.

Page 5: DBA Lab Manual 13-14

14.After the initial software is copied to the disk, the Oracle Universal Installer also automatically configures the network for the Production database. This is done in the background. The success of the operation is reported in the Oracle Universal Installer Configuration Tools window. Once the network configuration has been completed, the Oracle Universal Installer starts the Oracle Database Configuration Assistant. This assistant installs and configures the initial database in the background as well.

15. Database creation takes about twenty minutes. The progress is shown in the Database Creation Progress window. When the database has been created, the Database NT service is created.

16.Click Exit.

Page 6: DBA Lab Manual 13-14

17. When the database has been completely created and all the configuration tools have completed their tasks, the End of Installation window appears. Click Exit and then Yes to exit the Universal Installer.

Exploring the Oracle9i Installation

1. Open Windows NT Explorer and click the drive where you installed the database (for example, D:). Select View > Refresh. Navigate to the D:\Oracle directory. Notice that there are three subdirectories: admin, Ora90, and oradata.

2. Navigate to the admin directory. The D:\Oracle\admin directory is an OFA-compliant directory that contains information about different database instances installed on this machine. So far it contains one directory, orcl, for the orcl.world instance that you just created.

3. Navigate back to D:\Oracle\Ora90. This is the Oracle9i software directory, also known as the Oracle9i ORACLE_HOME. All the software for the Oracle9i Enterprise Edition is installed under this directory tree.

4. Navigate to the D:\Oracle\Ora90\Network\admin directory. This is the directory that the networking files are stored in.

5.Open the listener.ora file generated during the Oracle Universal Installer installation of Oracle9i.

6.Notice that the listener has been set to listen for three different types of connections:External processes called from the server, using InterProcess Communication (IPC)Oracle Net connections from across the network, using TCP/IP, on port 1521

The listener has also been configured with two services:An external process server for external procedure calls A database service for the ORCL.WORLD instance

Your listener.ora file should look like the following:

# LISTENER.ORA Network Configuration File:

d:\oracle\ora90\network\admin\listener.ora

# Generated by Oracle configuration tools.

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC3)) )

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = meyoung-lap)(PORT = 1521)) ) ) )

SID_LIST_LISTENER =

(SID_LIST =

Page 7: DBA Lab Manual 13-14

(SID_DESC =

(SID_NAME = PLSExtProc)

(ORACLE_HOME = d:\oracle\ora90)

(PROGRAM = extproc) )

(SID_DESC =

(GLOBAL_DBNAME = orcl.world)

(ORACLE_HOME = d:\oracle\ora90)

(SID_NAME = orcl) ) )

7. Close the file when you are finished.

8. Open the tnsnames.ora file generated during the Oracle Universal Installer installation of Oracle9i. Change US.ORACLE.COM to WORLD. This is done for simplicity purposes. The examples used through out the series will use this domain name however you may use what ever you would like.

# TNSNAMES.ORA Network Configuration File:

d:\oracle\ora90\network\admin\tnsnames.ora

# Generated by Oracle configuration tools.

EXTPROC_CONNECTION_DATA.WORLD =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC3)) )

(CONNECT_DATA =

(SID = PLSExtProc)

(PRESENTATION = RO) ) )

ORCL.WORLD =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = meyoung-lap)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = orcl.world) ) )

INST1_HTTP.WORLD =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = meyoung-lap)(PORT = 1521)) )

(CONNECT_DATA =

(SERVER = SHARED)

(SERVICE_NAME = MODOSE)

(PRESENTATION = http://HRService) ) )

9. Save your work and close the file.

10. Open the SQLNET.ORA file generated during the Oracle Universal Installer installation of Oracle9i. Change the US.ORACLE.COM entry to WORLD. The DEFAULT_DOMAIN name must match the domain name in your TNSNAMES.ORA file.

# SQLNET.ORA Network Configuration File:

d:\oracle\ora90\network\admin\sqlnet.ora

# Generated by Oracle configuration tools.

NAMES.DEFAULT_DOMAIN = WORLD

SQLNET.AUTHENTICATION_SERVICES= (NTS)

Page 8: DBA Lab Manual 13-14

NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

11. Save your work and close the file.

12. Navigate to the D:\Oracle\Ora90\Database directory. This directory contains the password files and the default initialization files for each instance created on this machine.

13. Open the initorcl.ora file. Notice that it contains a reference to the "real" initialization file at D:Oracle\Admin\orcl\pfile\initorcl.ora.

14. Navigate back to D:\Oracle\Oradata\orcl. This is the directory that contains the data files for each instance that you create on this machine. Explore the contents of this directory.

15. Select Start > Settings > Control Panel. Scroll down to the list of the services that were added as a result of your installation.

16. Now that you have installed Oracle9i, you should reboot the machine.

Testing the Oracle9i Installation

1. Select Start > Programs > Oracle-OraHome90 > Enterprise Manager Console.

2. In the Oracle Enterprise Manager Console login window, make sure that Launch standalone is selected and then click OK. Note: You can launch Enterprise Manager to immediately connect to the database for direct database administration. No configuring is necessary. From this Login window, you can also connect to the Oracle Management Server (OMS) however you need to create an OMS repository first which you will do in another module.

3. Expand Network then Databases, then click the plus sign to expand ORCL.WORLD.

Page 9: DBA Lab Manual 13-14

4. To log in to the instance, enter system in the Username field and manager in the Password field, then click OK.

5. Expand Instance and then select Configuration to see the state of the database. To view the initialization parameters, click the All Initialization Parameters button.

6. Click the db_name parameter and then click the Description button. A description of the parameter is displayed at the bottom of the window. Click OK to close the window.

Page 10: DBA Lab Manual 13-14

7. Notice that you cannot start or stop the database unless you are connected as SYSDBA. Right-click the ORCL.WORLD database and select Connect.

8. Enter sys in the Username field and change_on_install in the Password field. Select SYSDBA from the Connect as drop-down list and then click OK.

9. Expand Instance and then select Configuration. Notice that you now can shut down the database. Select the Shutdown option button and click Apply.

Page 11: DBA Lab Manual 13-14

10. Click OK to accept the default choice and shut down immediately.

11. When the shutdown is complete, click Close.

12. Notice that the database is no longer available. Now start it again. Click the Open option button and then Apply.

13. Clear the Use Configured Parameters check box. Click Browse to find the D:\Oracle\admin\orcl\pfile\initorcl.ora file and then click OK.

Page 12: DBA Lab Manual 13-14

14. When the database has been successfully started up, click Close.

15. Notice that the database has been started. Click the Memory tab.

16. In the Memory tabbed page, you can see how memory is currently allocated.

17. When you created your database, the sample schemas (or seeded) are loaded into your database, the HR user cannot log into the database until the password has been changed or that user is unlocked. This lock has been put into place for security purposes. You can unlock the user from Enterprise Manager by expanding Security, then Users, then selecting HR.

18. Select Unlock then Apply. Unlock the other Sample Schema Users: OE, PM, SH, and QS.

19. Select File > Exit to close the Enterprise Manager Console.

Page 13: DBA Lab Manual 13-14

2. Write procedure to Creating the Database after Installation Using the Database Configuration Assistant1. open Oracle DBCA

2. Select the Create a Database option and click Next.

3. Select the nodes that you want to configure as members of your cluster database and click Next.

Page 14: DBA Lab Manual 13-14

4. Select a template from which to create your cluster database and click Next.

5. Enter the global database name and the Oracle system identifier (sid) prefix for your cluster database and click Next.

6. Select the options you want to configure in your cluster database and click Next.

Page 15: DBA Lab Manual 13-14

7. Select the connection mode for your cluster database and click Next.

8. Select the File Locations tab on the Initialization Parameters page. Make sure your entries for the File Locations tab, as well as for the other tabs, are correct for your Real Application Clusters database and click Next.

9.Click Next when you have completed entering data on the Database Storage page.

Page 16: DBA Lab Manual 13-14

10. Review the information on the Summary page and click OK.

3.There is a string

'120000 12 0 .125' ,how you will find the position of the decimal place

INSTR('120000 12 0 .125','.',1) output 13

4. Write a queries to determine the time zone under which a database was operating?

SELECT dbtimezone FROM DUAL;

5. Write a queries to force a log switch?

alter system switch logfile;

6. Write a queries to add a data file to a tablespace?

alter tablespace USERS add datafile '/ora01/oradata/users02.dbf' size 50M;

7. Write a queries to resize a data file?

alter database datafile '/ora01/oradata/users02.dbf' resize 100M;

8. Write a queries to rebuild an index?

Page 17: DBA Lab Manual 13-14

ALTER INDEX index_name REBUILD;

9. Write a queries to gather statistics on a table?

exec dbms_stats.gather_table_stats

10. Write a queries to delete duplicating rows from a base table

DELETE FROM table_name A WHERE rowid>(SELECT min(rowid) from table_name B where B.table_no=A.table_no); or

CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table;

DROP old_table RENAME new_table TO old_table DELETE FROM table_name A WHERE rowid NOT IN (SELECT MAX(ROWID) FROM table_name GROUP BY column_name)

11. Write a queries to avoid your query from using indexes

SELECT * FROM emp Where emp_no+' '=12345;

12. Write a query to display system global name.

SELECT * FROM GLOBAL_NAME;

13. Write a query to display ORA_DATABASE_NAME.

Select ora_database_name from dual;

14. Write a queries to find the user objects created by him/her in his/her schema.

select * from tab;

select * from cat;

select * from user_catalog;

select table_name from user_tables;

select table_name from tabs;

select object_name,object_type from user_objects;

select segment_name from user_segments;

select segment_name from user_extents;

15. Write a query to show the table structure

select dbms_metadata.get_ddl('TABLE','DEMO','Saju') FROM DUAL;

16. Write a query to show you the allocated, Free and Used space in each of the datafiles.

SELECT SUBSTR (df.NAME, 1, 40) file_name, df.bytes / 1024 / 1024 allocated_mb,

((df.bytes / 1024 / 1024) - NVL (SUM (dfs.bytes) / 1024 / 1024, 0))

used_mb,

NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb

FROM v$datafile df, dba_free_space dfs

WHERE df.file# = dfs.file_id(+)

GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes

Page 18: DBA Lab Manual 13-14

ORDER BY file_name;

17. Write a query to Monitor long running operations using v$session_longops

SELECT SID, SERIAL#, opname, SOFAR, TOTALWORK,

ROUND(SOFAR/TOTALWORK*100,2) COMPLETE

FROM V$SESSION_LONGOPS

WHERE

TOTALWORK != 0

AND SOFAR != TOTALWORK

order by 1;

18. Write a query to find a session with high archive logs

SELECT s.sid, s.serial#, s.username, s.program, i.block_changesFROM v$session s, v$sess_io iWHERE s.sid = i.sidORDER BY 5 desc

19. Write a query to display oracle processes.

select nm, max(description) descript from (select regexp_replace( name,'[0-9a-z]','#') nm, description from v$bgprocess) group by nm order by nm;

20. Write a query to Show the ten largest objects in the database

col owner format a15col segment_name format a30col segment_type format a15col mb format 999,999,999select owner, segment_name, segment_type, mbfrom ( select owner , segment_name , segment_type , bytes / 1024 / 1024 "MB" from dba_segments order by bytes desc )where rownum < 11

21. Write a query to Is java installed in the database?

select count(*)from all_objectswhere object_type like '%JAVA%'and owner = 'SYS'

22. Write a query to Display character set information

select * from nls_database_parameters

23. Write a query to Show all used features

select name, detected_usagesfrom dba_feature_usage_statistics

Page 19: DBA Lab Manual 13-14

where detected_usages > 0

24. WAP to accept the empno and display all the details of emp. If emp does not exist display the message

DECLAREEMPNOV NUMBER:=&EMPNO;EMPV EMP%ROWTYPE;BEGINSELECT * INTO EMPV FROM EMP WHERE EMPNO=EMPNOV;DBMS_OUTPUT.PUT_LINE('EMPNO '||EMPV.EMPNO);DBMS_OUTPUT.PUT_LINE('ENAME '||EMPV.ENAME);DBMS_OUTPUT.PUT_LINE('JOB '||EMPV.JOB);DBMS_OUTPUT.PUT_LINE('SALARY '||EMPV.SAL);DBMS_OUTPUT.PUT_LINE('HIREDATE '||EMPV.HIREDATE);DBMS_OUTPUT.PUT_LINE('DEPTNO '||EMPV.DEPTNO);DBMS_OUTPUT.PUT_LINE('MGRNO '||EMPV.MGR);DBMS_OUTPUT.PUT_LINE('COMMISSION '||EMPV.COMM);EXCEPTIONWHEN NO_DATA_FOUND THENDBMS_OUTPUT.PUT_LINE('EMP NUMBER DOES NOT EXIST');END;

25. Write a program to accept the grade and display emps belongs to that grade?

DECLAREGRADEV SALGRADE.GRADE%TYPE:=&GRADE;CURSOR A ISSELECT EMP.*,GRADE FROM EMP,SALGRADE WHERE SAL BETWEEN LOSAL AND HISAL ANDGRADE=GRADEV;B A%ROWTYPE;BEGINOPEN A;LOOPFETCH A INTO B;EXIT WHEN A%NOTFOUND;DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);DBMS_OUTPUT.PUT_LINE('GRADE IS ' || B.GRADE);DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);DBMS_OUTPUT.PUT_LINE('*************************');END LOOP;CLOSE A;END;

26. Write a program to accept a deptno and display who are working in that dept?

DECLAREDEPTV EMP.DEPTNO%TYPE:=&DEPTNO;CURSOR A ISSELECT * FROM EMP WHERE DEPTNO=DEPTV;B A%ROWTYPE;BEGINOPEN A;LOOPFETCH A INTO B;EXIT WHEN A%NOTFOUND;DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);DBMS_OUTPUT.PUT_LINE('DEPTNO IS ' || B.DEPTNO);DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);DBMS_OUTPUT.PUT_LINE('*************************');END LOOP;

Page 20: DBA Lab Manual 13-14

CLOSE A;END;

27. Write a program to display all the information of emp table? DECLARECURSOR A ISSELECT * FROM EMP;B A%ROWTYPE;BEGINOPEN A;Page 4 of 7LOOP http://oracleapps4u.blogspot.in/FETCH A INTO B;EXIT WHEN A%NOTFOUND;DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);DBMS_OUTPUT.PUT_LINE('DEPTNO IS ' || B.DEPTNO);DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);DBMS_OUTPUT.PUT_LINE('*************************');END LOOP;CLOSE A;END;

28. Write a program to accept a range of salary (that is lower boundary and higher boundary) and print the details of emps along with loc,grade and exp?

DECLARELOSALV SALGRADE.LOSAL%TYPE:=&LOSAL;HISALV SALGRADE.HISAL%TYPE:=&HISAL;EXP NUMBER(5,2);CURSOR A ISSELECT EMP.*,LOC,GRADE FROM EMP,DEPT,SALGRADE WHEREEMP.DEPTNO=DEPT.DEPTNOAND SAL BETWEEN LOSALV AND HISALVAND SAL BETWEEN LOSAL AND HISAL;B A%ROWTYPE;BEGINOPEN A;LOOPFETCH A INTO B;EXIT WHEN A%NOTFOUND;EXP:=MONTHS_BETWEEN(SYSDATE,B.HIREDATE)/12;DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);DBMS_OUTPUT.PUT_LINE('LOC IS ' || B.LOC);DBMS_OUTPUT.PUT_LINE('EXP IS ' || EXP);DBMS_OUTPUT.PUT_LINE('GRADE IS ' || B.GRADE);DBMS_OUTPUT.PUT_LINE('*************************');END LOOP;CLOSE A;END;

29. Write a function to accept the empno and return exp with minimum 3 decimal?

CREATE OR REPLACE FUNCTION E_DETAILS(EMPNOV NUMBER) RETURN NUMBERISHIREDATEV EMP.HIREDATE%TYPE;EXP NUMBER(6,3);BEGINSELECT HIREDATE INTO HIREDATEV FROM EMP WHERE EMPNO=EMPNOV;EXP:=MONTHS_BETWEEN(SYSDATE,HIREDATEV)/12;RETURN EXP;END;

30. Write a database trigger stroe the username ,type of transaction ,date of transaction and time of transaction of table em into the table _LOG

Page 21: DBA Lab Manual 13-14

CREATE OR REPLACE TRIGGER TRANS_TYPEPage 6 of 7AFTER INSERT OR UPDATE OR DELETE ON EMP http://oracleapps4u.blogspot.in/DECLAREV VARCHAR2(50);BEGINIF INSERTING THENV:='I';ELSIF UPDATING THENV:='U';ELSEV:='D';END IF;INSERT INTO EMP_LOG VALUES (USER,V,SYSDATE,TO_CHAR(SYSDATE,'HH:MI:SS'));END;