Pets

 

Military

 

Hobbies

 

Links and Articles

 

 

 
 

 

 

 
Oracle Links
Oracle DBA Helper
DBA Interview Questions

Explain the difference between a hot backup and a cold backup and the benefits associated with each.

A hot backup is basically taking a backup of the database while it is still up and running and it must be in archive log mode. A cold backup is taking a backup of the database while it is shut down and does not require being in archive log mode. The benefit of taking a hot backup is that the database is still available for use while the backup is occurring and you can recover the database to any point in time. The benefit of taking a cold backup is that it is typically easier to administer the backup and recovery process. In addition, since you are taking cold backups the database does not require being in archive log mode and thus there will be a slight performance gain as the database is not writing archive logs to disk.

You have just had to restore from backup and do not have any control files. How would you go about bringing up this database?

I would create a text based backup control file, stipulating where on disk all the data files were and then issue the recover command with the using backup control file clause.

How do you switch from an init.ora file to a spfile?

Issue the create spfile from pfile command.

Explain the difference between a data block, an extent and a segment.

A data block is the smallest unit of logical storage for a database object. As objects grow they take chunks of additional storage that are composed of contiguous data blocks. These groupings of contiguous data blocks are called extents. All the extents that an object takes when grouped together are considered the segment of the database object.

Give two examples of how you might determine the structure of the table DEPT.

Use the describe command or use the dbms_metadata.get_ddl package.

Where would you look for errors from the database engine?

In the alert log.

Compare and contrast TRUNCATE and DELETE for a table.

Both the truncate and delete command have the desired outcome of getting rid of all the rows in a table. The difference between the two is that the truncate command is a DDL operation and just moves the high water mark and produces few rollback data. The delete command, on the other hand, is a DML operation, which will produce rollback data and thus take longer to complete.

Give the reasoning behind using an index.

Faster access to data blocks in a table.

Give the two types of tables involved in producing a star schema and the type of data they hold.

Fact tables and dimension tables. A fact table contains measurements while dimension tables will contain data that will help describe the fact tables.

What type of index should you use on a fact table?

A Bitmap index.  A bitmap index is a type of index that uses a string of bits to quickly locate rows in a table. Bitmap indexes are normally used to index low cardinality columns in a warehouse environment.

Give some examples of the types of database constraints you may find in Oracle and indicate their purpose.

  • A Primary or Unique Key can be used to enforce uniqueness on one or more columns.
  • A Referential Integrity constraint can be used to enforce a Foreign Key relationship between two tables.
  • A Not Null constraint can be used to ensure a value is entered in a column
  • A Value constraint can be used to check a column value against a specific set of values.

A table is classified as a parent table and you want to drop and re-create it. How would you do this without affecting the children tables?

Disable the foreign key constraint to the parent, drop the table, re-create the table, and then re-enable the foreign key constraint.

Explain the difference between ARCHIVELOG mode and NOARCHIVELOG mode and the benefits and disadvantages to each.

ARCHIVELOG mode is a mode that you can put the database in for creating a backup of all transactions that have occurred in the database so that you can recover to any point in time. NOARCHIVELOG mode is basically the absence of ARCHIVELOG mode and has the disadvantage of not being able to recover to any point in time. NOARCHIVELOG mode does have the advantage of not having to write transactions to an archive log and thus increases the performance of the database slightly.

What command would you use to create a backup control file?

ALTER DATABASE BACKUP CONTROL FILE TO TRACE;

Give the stages of instance startup to a usable state where normal users may access it.

STARTUP NOMOUNT - Instance startup
STARTUP MOUNT - The database is mounted
STARTUP OPEN - The database is opened

What column differentiates the V$ views to the GV$ views and how?

The INST_ID column which indicates the instance in a RAC environment the information came from.

How would you go about generating an EXPLAIN plan?

Create a plan table with utlxplan.sql.
Use the explain plan set statement_id = 'tst1' into plan_table for a SQL statement
Look at the explain plan with utlxplp.sql or utlxpls.sql

How would you go about increasing the buffer cache hit ratio?

Use the buffer cache advisory over a given workload and then query the V$DB_CACHE_ADVICE table.  If a change was necessary, then use the ALTER SYSTEM SET DB_CACHE_SIZE command.

Explain an ORA-01555.

You get this error when you get a snapshot too old within rollback. It can usually be solved by increasing the undo retention or increasing the size of rollbacks. You should also look at the logic involved in the application getting the error message.

Explain the difference between $ORACLE_HOME and $ORACLE_BASE.

ORACLE_BASE is the root directory for oracle. ORACLE_HOME located beneath ORACLE_BASE is where the Oracle products reside.

PL/SQL Interview Questions

How would you determine the time zone under which a database was operating?

SELECT dbtimezone FROM DUAL;

Explain the use of setting GLOBAL_NAMES equal to TRUE.

It ensures the use of consistent naming conventions for databases and links in a networked environment.

What command would you use to encrypt a PL/SQL application?

WRAP

Explain the difference between a FUNCTION, PROCEDURE and PACKAGE.

They are all named PL/SQL blocks.
A Function must return a value. A function can be called inside a query.
A Procedure may or may not return a value.
A Package is the collection of like functions, procedures, and variables which can be logically grouped together.

Explain the use of table functions.

Name three advisory statistics you can collect.

Where in the Oracle directory tree structure are audit traces placed?

Explain materialized views and how they are used?

When a user process fails, what background process cleans up after it?

PMON

What background process refreshes materialized views?

Job Queue Process (CJQ)

How would you determine what sessions are connected and what resources they are waiting for?

V$SESSION, and V$SESSION_WAIT

Describe what redo logs are.

How would you force a log switch?

ALTER SYSTEM SWITCH LOGFILE;

Give two methods you could use to determine what DDL changes have been made.

What does coalescing a tablespace do?

Coalesce simply takes contiguous free extents and makes them into a single larger free extent.

What is the difference between a TEMPORARY tablespace and a PERMANENT tablespace?

TEMP tablespace gets cleared once the transaction is done, whereas PERMANENT tablespace retains the data.

Name a tablespace automatically created when you create a database.

SYSTEM, SYSAUX, TEMPORARY, USER, UNDOTBS1

When creating a user, what permissions must you grant to allow them to connect to the database?

GRANT CREATE SESSION TO USERNAME;

How do you add a data file to a tablespace?

ALTER TABLESPACE USERS ADD DATAFILE'/ora01/oradata/users02.dbf' SIZE 50M;

How do you resize a data file?

ALTER DATABASE DATAFILE '/ora01/oradata/users02.dbf' RESIZE 100M;

What view would you use to look at the size of a data file?

DBA_DATA_FILES

What view would you use to determine free space in a tablespace?

DBA_FREE_SPACE

How would you determine who has added a row to a table?

By implementing an INSERT trigger for logging details during each INSERT operation on the table.

How can you rebuild an index?

ALTER INDEX index_name REBUILD;

Explain what partitioning is and what its benefit is.

A table partition is also a table segment, and by using partitioning techniques we can enhance performance of table access.

You have just compiled a PL/SQL package but got errors, how would you view the errors?

show errors

How can you gather statistics on a table?

exec DBMS_STATS.GATHER_TABLE_STATS
Also, remember to analyze all associated indexes on that table using DBMS_STATS.GATHER_INDEX_STATS

How can you enable a trace for a session?

ALTER SESSION SET SQL_TRACE = 'TRUE';

What is the difference between the SQL*Loader and IMPORT utilities?

SQL*LOADER loads external data which is in OS files to Oracle database tables.  While the IMPORT utility imports only data which is exported by the EXPORT utility of Oracle.

Name two files used for network connection to a database.

TNSNAMES.ORA and SQLNET.ORA

Describe the difference between a procedure, function and anonymous PL/SQL block.

An anonymous PL/SQL block uses the DECLARE statement in the declaration section.  A function must return a value, while a procedure doesn't have to return a value.

What is a mutating table error and how can you get around it?

This happens with triggers.  It occurs because the trigger is trying to update a row it is currently using. The usual fix involves either the use of views or temporary tables so the database is selecting from one while updating the other.

Describe the use of %ROWTYPE and %TYPE in PL/SQL.

%ROWTYPE allows you to associate a variable with an entire table row. The %TYPE associates a variable with a single column type.

What packages (if any) has Oracle provided for use by developers?

Oracle provides the DBMS_ series of packages. There are many which developers should be aware of such as DBMS_SQL, DBMS_PIPE, DBMS_TRANSACTION, DBMS_LOCK, DBMS_ALERT, DBMS_OUTPUT, DBMS_JOB, DBMS_UTILITY, DBMS_DDL, and UTL_FILE. If they can mention a few of these and describe how they used them, even better. If they include the SQL routines provided by Oracle, great, but not really what was asked.

Describe the use of PL/SQL tables.

PL/SQL tables are scalar arrays that can be referenced by a binary integer. They can be used to hold values for use in later queries or calculations. In Oracle 8, they will be able to be of the %ROWTYPE designation, or RECORD.

When is a declare statement needed?

The DECLARE statement is used in PL/SQL anonymous blocks such as with standalone, non-stored PL/SQL procedures.  It must come first in the declaration section of a PL/SQL standalone file if it is used.

In what order should an OPEN/FETCH/LOOP set of commands in a PL/SQL block be implemented if you use the %NOTFOUND cursor variable in the EXIT WHEN statement? Why?

OPEN then FETCH then LOOP followed by the EXIT WHEN statement.  If not specified in this order, it will result in the final RETURN being done twice because of the way the %NOTFOUND is handled by PL/SQL.

What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?

SQLCODE returns the value of the error number for the last error encountered.  SQLERRM returns the actual error message for the last error encountered.  They can be used in exception handling to report, or store in an error log table, the error that occurred in the code.  These are especially useful for the WHEN OTHERS exception.

How can you find, within a PL/SQL block, if a cursor is open?

Use the %ISOPEN cursor status variable.

How can you generate debugging output from PL/SQL?

Use the DBMS_OUTPUT package to display output to the screen.  Another possible method is to just use the SHOW ERROR command, but this only shows errors.  The DBMS_OUTPUT package can be used to show intermediate results from loops and the status of variables as the procedure is executed.  The package UTL_FILE can also be used to write output to a file on the OS.

What are the types of triggers?

There are 12 types of triggers in PL/SQL.  These consist of combinations of the BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and ALL key words: BEFORE ALL ROW INSERT, AFTER ALL ROW INSERT, BEFORE INSERT, AFTER INSERT, etc.

SQL Interview Questions

How can variables be passed to a SQL routine?

By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1, &2,...,&8) to pass the values after the command into the SQLPLUS session. To be prompted for a specific variable, place the ampersanded variable in the code itself: "select * from dba_tables where owner=&owner_name;" . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable, a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user.

You want to include a carriage return/linefeed in your output from a SQL script, how can you do this?

The best method is to use the CHR() function (CHR(10) is a return/linefeed) and the concatenation function "||". Another method, although it is hard to document and isn't always portable is to use the return/linefeed as a part of a quoted string.

How can you call a PL/SQL procedure from SQL?

By use of the EXECUTE (short form EXEC) command.

How do you execute a host operating system command from within SQL?

By use of the exclamation ball "!" (in UNIX and some other OS) or the HOST (HO) command.

You want to use SQL to build SQL, what is this called? Give an example.

This is called dynamic SQL.
An example would be:
set lines 90
pages 0
termout off
feedback off
verify off
spool drop_all.sql
SELECT 'drop user'||username||' cascade;'
FROM dba_users
WHERE username NOT IN ('SYS','SYSTEM');
spool off
Essentially you are looking to see that they know to include a command (in this case DROP USER...CASCADE;) and that you need to concatenate using the "||" the values selected from the database.

What SQLPlus command is used to format output from a select?

This is best done with the COLUMN command.

You want to group the following set of select returns, what can you group on?

Max(sum_of_cost), min(sum_of_cost), count(item_no), item_no The only column that can be grouped on is the "item_no" column, the rest have aggregate functions associated with them.

What special Oracle feature allows you to specify how the cost based system treats a SQL statement?

The COST based system allows the use of HINTs to control the optimizer path selection. If they can give some example hints such as FIRST ROWS, ALL ROWS, USING INDEX, STAR, even better.

You want to determine the location of identical rows in a table before attempting to place a unique index on the table, how can this be done?

Oracle tables always have one guaranteed unique column, the rowid column. If you use a min/max function against your rowid and then select against the proposed primary key you can squeeze out the rowids of the duplicate rows pretty quick. For example: select rowid from emp e where e.rowid > (select min(x.rowid) from emp x where x.emp_no = e.emp_no); In the situation where multiple columns make up the proposed key, they must all be used in the where clause.

What is a Cartesian product?

A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows in each table involved in the join.

You are joining a local and a remote table, the network manager complains about the traffic involved, how can you reduce the network traffic?

Push the processing of the remote data to the remote instance by using a view to pre-select the information for the join. This will result in only the data required for the join being sent across.

What is the default ordering of an ORDER BY clause in a SELECT statement?

Ascending

What is tkprof and how is it used?

The tkprof tool is a tuning tool used to determine cpu and execution times for SQL statements. You use it by first setting timed_statistics to true in the initialization file and then turning on tracing for either the entire database via the sql_trace parameter or for the session using the ALTER SESSION command. Once the trace file is generated you run the tkprof tool against the trace file and then look at the output from the tkprof tool. This can also be used to generate explain plan output.

What is explain plan and how is it used?

The EXPLAIN PLAN command is a tool to tune SQL statements. To use it you must have an explain_table generated in the user you are running the explain plan for. This is created using the utlxplan.sql script. Once the explain plan table exists you run the explain plan command giving as its argument the SQL statement to be explained. The explain_plan table is then queried to see the execution plan of the statement. Explain plans can also be run using tkprof.

How do you set the number of lines on a page of output?

The width The SET command in SQLPLUS is used to control the number of lines generated per page and the width of those lines, for example SET PAGESIZE 60 LINESIZE 80 will generate reports that are 60 lines long with a line width of 80 characters. The PAGESIZE and LINESIZE options can be shortened to PAGES and LINES.

How do you prevent output from coming to the screen?

The SET option TERMOUT controls output to the screen. Setting TERMOUT OFF turns off screen output. This option can be shortened to TERM.

How do you prevent Oracle from giving you informational messages during and after a SQL statement execution?

The SET options FEEDBACK and VERIFY can be set to OFF.

How do you generate file output from SQL?

By use of the SPOOL command.

Calculating table size

Tom breaks down the basics of sizing in this older article.
dbms_space.free_space

Article written for version 8.1.5, but has copious examples.
What don't you like about Oracle?

Tom discusses his views on the upcoming direction of the Oracle DB.
Table sizing

Very good examples of sizing calculations.
Recovery Manager Reference

Oracle 9i Recovery Manager Reference guide
Recovery Manager User's Guide

Oracle 9i Recovery Manager User's Guide

SQL Server DBA Helper
Documenting and Configuring SQL Server Settings

Brad McGehee discusses some best practice methods to configuring the instance-level settings.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Number storage

Discusses how NUMBER datatypes are sized.
Articles - Page: 1
 
Fosters and Others

Fostering dogs and cats has it's challenges and rewards. These photos show some of the fosters that I have been fortunate enough to have had in my life for even a short period of time.

Also, in this collection are general photos of fuzzy acquaintances that have stopped by for a visit.

View (14 Photos)

 

Updated: 4/5/12

 
Articles - Page: 1
gulfsidecsi.com -- Revised: 2/24/16
Copyright ©1998
Gulfside Consulting Services, Inc.
DSchwisow