Professional Documents
Culture Documents
DBA Lab Manual 13-14
DBA Lab Manual 13-14
DBA Lab Manual 13-14
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.
7.
Accept the General Purpose default database configuration and click Next.
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.
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.
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.
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.
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 = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = d:\oracle\ora90) ) ) ) )
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) 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.
3.
Expand Network then Databases, then click the plus sign to expand ORCL.WORLD.
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.
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.
10. Click OK to accept the default choice and shut down immediately.
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.
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.
2. Write procedure to Creating the Database after Installation Using the Database Configuration Assistant 1. open Oracle DBCA
3. Select the nodes that you want to configure as members of your cluster database and click Next.
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.
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.
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? 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 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 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_changes FROM v$session s, v$sess_io i WHERE s.sid = i.sid ORDER 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. col Write a query to Show the ten largest objects in the database owner format a15
col segment_name format a30 col segment_type format a15 col mb format 999,999,999 select owner, segment_name, segment_type, mb from ( select owner , segment_name , segment_type 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_objects where 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_usages from dba_feature_usage_statistics 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
DECLARE EMPNOV NUMBER:=&EMPNO; EMPV EMP%ROWTYPE; BEGIN SELECT * 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); EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('EMP NUMBER DOES NOT EXIST'); END;
25.
Write a program to accept the grade and display emps belongs to that grade?
DECLARE GRADEV SALGRADE.GRADE%TYPE:=&GRADE; CURSOR A IS SELECT EMP .*,GRADE FROM EMP ,SALGRADE WHERE SAL BETWEEN LOSAL AND HISAL AND GRADE=GRADEV; B A%ROWTYPE; BEGIN OPEN A; LOOP 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('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?
DECLARE DEPTV EMP .DEPTNO%TYPE:=&DEPTNO; CURSOR A IS SELECT * FROM EMP WHERE DEPTNO=DEPTV; B A%ROWTYPE; BEGIN OPEN A; LOOP 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;
27.
DECLARE CURSOR A IS SELECT * FROM EMP; B A%ROWTYPE; BEGIN OPEN A; Page 4 of 7 LOOP 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?
DECLARE LOSALV SALGRADE.LOSAL%TYPE:=&LOSAL; HISALV SALGRADE.HISAL%TYPE:=&HISAL; EXP NUMBER(5,2); CURSOR A IS SELECT EMP .*,LOC,GRADE FROM EMP ,DEPT,SALGRADE WHERE EMP .DEPTNO=DEPT.DEPTNO AND SAL BETWEEN LOSALV AND HISALV
AND SAL BETWEEN LOSAL AND HISAL; B A%ROWTYPE; BEGIN OPEN A; LOOP FETCH 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 NUMBER IS HIREDATEV EMP .HIREDATE%TYPE; EXP NUMBER(6,3); BEGIN SELECT 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
CREATE OR REPLACE TRIGGER TRANS_TYPE Page 6 of 7 AFTER INSERT OR UPDATE OR DELETE ON EMP http://oracleapps4u.blogspot.in/ DECLARE V VARCHAR2(50); BEGIN IF INSERTING THEN V:='I'; ELSIF UPDATING THEN V:='U'; ELSE V:='D'; END IF; INSERT INTO EMP_LOG VALUES (USER,V ,SYSDATE,TO_CHAR(SYSDATE,'HH:MI:SS')); END;