﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>FranklinFaces.com - Oracle &amp; SQL Server Database Forums for all IT Professionals / Oracle Forum / Oracle Interview Questions / Oracle PL/SQL and overall SQL Interview Questions </title><generator>InstantForum.NET v4.1.4</generator><description>FranklinFaces.com - Oracle &amp; SQL Server Database Forums for all IT Professionals</description><link>http://www.franklinfaces.com/</link><webMaster>no-reply@FranklinFaces.com</webMaster><lastBuildDate>Sat, 31 Jul 2010 07:13:55 GMT</lastBuildDate><ttl>20</ttl><item><title>Oracle SQL &amp; PL/SQL Interview Questions</title><link>http://www.franklinfaces.com/Topic25-81-1.aspx</link><description>&lt;H5&gt;&lt;FONT color=#113311&gt;How to display row number with records?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;Select rownum, ename from emp;&lt;/P&gt;&lt;H3&gt;&lt;FONT color=#113311 size=2&gt;How to view version information in Oracle?&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;Select banner from v$version;&lt;/P&gt;&lt;H3&gt;&lt;FONT color=#113311 size=2&gt;How to find the second highest salary in emp table?&lt;/FONT&gt; &lt;/H3&gt;&lt;P&gt;select min(sal) from emp a&lt;BR&gt;where 1 = (select count(*) from emp b where a.sal &amp;lt; b.sal) ;&lt;/P&gt;&lt;H3&gt;&lt;FONT color=#113311 size=2&gt;How to delete the duplicate rows from a table?&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;create table t1 ( col1 int, col2 int, col3 char(1) );&lt;BR&gt;insert into t1 values(1,50, ‘a’);&lt;BR&gt;insert into t1 values(1,50, ‘b’);&lt;BR&gt;insert into t1 values(1,89, ‘x’);&lt;BR&gt;insert into t1 values(1,89, ‘y’);&lt;BR&gt;insert into t1 values(1,89, ‘z’);&lt;BR&gt;&lt;/P&gt;&lt;P&gt;select * from t1;&lt;BR&gt;&lt;/P&gt;&lt;BR&gt;&lt;TABLE width="10%"&gt;&lt;TBODY&gt;&lt;T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lt;/TBODY&gt;&lt;/TABLE&gt;will do it.&lt;H5&gt;&lt;FONT color=#113311&gt;How to select a row using indexes?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;You have to specify the indexed columns in the WHERE clause of query.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How to select the first 5 characters of FIRSTNAME column of EMP table?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;select substr(firstname,1,5) from emp&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How to concatenate the firstname and lastname from emp table?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;select firstname ‘ ‘ lastname from emp&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What's the difference between a primary key and a unique key?&lt;/FONT&gt; &lt;/H5&gt;&lt;B&gt;Primary key&lt;/B&gt; does not allow nulls, &lt;P&gt;&lt;B&gt;Unique key&lt;/B&gt; allow nulls.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What is a self join?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;A self join joins a table to itself.&lt;/P&gt;&lt;H4&gt;Example&lt;/H4&gt;&lt;P&gt;SELECT a.last_name Employee, b.last_name Manager&lt;BR&gt;FROM employees a, employees b&lt;BR&gt;WHERE b.employee_id = a.manager_id;&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What is a transaction and ACID?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;&lt;B&gt;Transaction&lt;/B&gt; - A transaction is a logical unit of work. It must be commited or rolled back.&lt;/P&gt;&lt;P&gt;&lt;B&gt;ACID&lt;/B&gt; - Atomicity, Consistency, Isolation and Duralbility, these are properties of a transaction.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How to add a column to a table?&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;alter table t1 add sal number;&lt;/P&gt;&lt;P&gt;alter table t1 add middle_name varchar(20); &lt;/P&gt;&lt;P&gt;&lt;FONT color=#113311&gt;&lt;STRONG&gt;Is it possible for a table to have more than one foreign key ?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;/P&gt;&lt;P&gt;A table can have any number of foreign keys. It can have only one primary key .&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How to display number value in words?&lt;/FONT&gt;&lt;/H5&gt;SQL&amp;gt; select sal, (to_char(to_date(sal,'j'), 'jsp')) from emp; &lt;H5&gt;&lt;FONT color=#113311&gt;What is candidate key, alternate key, composite key.&lt;/FONT&gt;&lt;/H5&gt;&lt;B&gt;Candidate Key&lt;/B&gt; A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table.&lt;BR&gt;&lt;P&gt;&lt;B&gt;Alternate Key&lt;/B&gt;If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys. &lt;/P&gt;&lt;P&gt;&lt;B&gt;Composite Key:&lt;/B&gt; - A key formed by combining at least two or more columns is called composite key. &lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What's the difference between DELETE TABLE and TRUNCATE TABLE commands? Explain drop command.&lt;/FONT&gt;&lt;/H5&gt;Both Delete and Truncate will leave the structure of the table. Drop will remove the structure also.&lt;BR&gt;&lt;OL type=1&gt;&lt;LI&gt;&lt;BR&gt;&lt;H4&gt;Example&lt;/H4&gt;&lt;P&gt;If tablename is T1.&lt;/P&gt;&lt;P&gt;To remove all the rows from a table t1.&lt;/P&gt;&lt;P&gt;Delete t1&lt;/P&gt;&lt;P&gt;Truncate table t1&lt;/P&gt;Drop table t1.&lt;BR&gt;&lt;BR&gt;&lt;LI&gt;Truncate is fast as compared to Delete. DELETE will generate undo information, in case of rollback, but TRUNCATE will not.&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;LI&gt;Full Table scan and index fast scan read data blocks up to high water mark and truncate resets high water mark but delete does not.So full table scan after Delete will not improve but after truncate it will be fast.&lt;BR&gt;&lt;BR&gt;&lt;LI&gt;Delete is DML. Because truncate is a DDL, it performs implicit commit. You cannot rollback a truncate. Any uncommitted DML changes will also be committed with the TRUNCATE.&lt;BR&gt;&lt;BR&gt;&lt;LI&gt;You cannot specify a WHERE clause in the TRUNCATE statement, but you can specify that in Delete.&lt;BR&gt;&lt;BR&gt;&lt;LI&gt;When you truncate a table the storage for the table and all the indexes can be reset back to its initial size,but a Delete will never shrink the size of the a table or its indexes.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;B&gt;About Dropping&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Dropping a table removes the data and definition of the table. The indexes, constraints, triggers, and privileges on the table are also dropped. The action of dropping a table cannot be undone. The views, materialized views or other stored programs that reference the table are not dropped but they are marked as invalid.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;Explain the difference between a FUNCTION, PROCEDURE and PACKAGE.&lt;/FONT&gt; &lt;/H5&gt;&lt;P&gt;Procedures and functions are stored in compiled form in database.&lt;/P&gt;&lt;P&gt;Functions take zero or more parameters and return a value. Procedures take zero or more parameters and return no values.&lt;/P&gt;&lt;P&gt;Both functions and procedures can take or return zero or more values through their parameter lists.&lt;/P&gt;&lt;P&gt;Another difference between procedures and functions, other than the return value, is how they are called. Procedures are called as stand-alone executable statements:&lt;/P&gt;&lt;P&gt;my_procedure(parameter1,parameter2...);&lt;/P&gt;&lt;P&gt;Functions can be called anywhere in an valid expression :&lt;/P&gt;e.g&lt;BR&gt;1) IF (tell_salary(empno) &amp;lt; 500 ) THEN … 2) var1 := tell_salary(empno); 3) DECLARE var1 NUMBER DEFAULT tell_salary(empno); BEGIN …&lt;BR&gt;&lt;P&gt;Packages contain function , procedures and other data structures.&lt;/P&gt;There are a number of differences between packaged and non-packaged PL/SQL programs. &lt;P&gt;Package The data in package is persistent for the duration of the user’s session.The data in package thus exists across commits in the session.&lt;/P&gt;If you grant execute privilege on a package, it is for all functions and procedures and data structures in the package specification. You cannot grant privileges on only one procedure or function within a package. &lt;P&gt;You can overload procedures and functions within a package, declaring multiple programs with the same name. The correct program to be called is decided at runtime, based on the number or datatypes of the parameters.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;Describe the use of %ROWTYPE and %TYPE in PL/SQL&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;%ROWTYPE associates a variable to an entire table row. &lt;/P&gt;&lt;P&gt;The %TYPE associates a variable with a single column type.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;SQLCODE returns the current database error number. These error numbers are all negative, except NO_DATA_FOUND, which returns +100.&lt;/P&gt;&lt;P&gt;SQLERRM returns the textual error message.. These are used in exception handling.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How can you find within a PL/SQL block, if a cursor is open?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;By the Use of %ISOPEN cursor variable.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;How do you debug output from PL/SQL?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;By the use the DBMS_OUTPUT package. &lt;/P&gt;&lt;P&gt;By the use of SHOW ERROR command, but this only shows errors. &lt;/P&gt;&lt;P&gt;The package UTL_FILE can also be used.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are the types of triggers?&lt;/FONT&gt;&lt;BR&gt;&lt;/H5&gt;&lt;LI&gt;Use Row and Statement Triggers &lt;LI&gt;Use INSTEAD OF Triggers &lt;H5&gt;&lt;FONT color=#113311&gt;Explain the usage of WHERE CURRENT OF clause in cursors ?&lt;/FONT&gt;&lt;BR&gt;&lt;/H5&gt;&lt;P&gt;It refers to the latest row fetched from a cursor in an update and delete statement.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;Name the tables where characteristics of Package, procedure and functions are stored ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;User_objects, User_Source and User_error.&lt;BR&gt;&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are two parts of package ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;They consist of package specification, which contains the function headers, procedure headers, and externally visible data structures. The package also contains a package body, which contains the declaration, executable, and exception handling sections of all the bundled procedures and functions.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are two virtual tables available during database trigger execution ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;The table columns are referred as OLD.column_name and NEW.column_name.&lt;/P&gt;&lt;P&gt;For INSERT only TRIGGERS NEW.column_name values ARE only available.&lt;/P&gt;&lt;P&gt;For UPDATE only TRIGERS OLD.column_name NEW.column_name values ARE only available.&lt;/P&gt;&lt;P&gt;For DELETE only TRIGGERS OLD.column_name values ARE only available.v &lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What is Overloading of procedures ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;REPEATING OF SAME PROCEDURE NAME WITH DIFERENT PARAMETER LIST.&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are the return values of functions SQLCODE and SQLERRM ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;&lt;B&gt;SQLCODE&lt;/B&gt; returns the latest code of the error that has occurred.&lt;/P&gt;&lt;P&gt;&lt;B&gt;SQLERRM&lt;/B&gt; returns the relevant error message of the SQLCODE.&lt;BR&gt;&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;Is it possible to use Transaction control Statements such a ROLLBACK or COMMIT in Database Trigger ? Why ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;It is not possible.,because of the side effect to transactions. You can use them indirectly by calling procedures or functions .&lt;/P&gt;&lt;H5&gt;&lt;FONT color=#113311&gt;What are the modes of parameters that can be passed to a procedure ?&lt;/FONT&gt;&lt;/H5&gt;&lt;P&gt;IN, OUT, IN-OUT parameters.&lt;/P&gt;&lt;/LI&gt;&lt;!-- spacer for skins that want sidebar and main to be the same height--&gt;</description><pubDate>Wed, 03 Dec 2008 15:18:54 GMT</pubDate><dc:creator>Admin</dc:creator></item><item><title>Basic SQL Interview Questions</title><link>http://www.franklinfaces.com/Topic28-81-1.aspx</link><description>&lt;B&gt;&lt;FONT color=#113311&gt;What's SQL&lt;/FONT&gt; &lt;/B&gt;&lt;P&gt;SQL is an English like language consisting of commands to store, retrieve, maintain &amp;amp; regulate access to your database. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's SQL*Plus&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;SQL*Plus is an application that recognizes &amp;amp; executes SQL commands &amp;amp; specialized SQL*Plus commands that can customize reports, provide help &amp;amp; edit facility &amp;amp; maintain system variables. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's NVL&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;NVL : Null value function converts a null value to a non-null value for the purpose of evaluating an expression. Numeric Functions accept numeric I/P &amp;amp; return numeric values. They are MOD, SQRT, ROUND, TRUNC &amp;amp; POWER. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's Date Functions&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;Date Functions are ADD_MONTHS, LAST_DAY, NEXT_DAY, MONTHS_BETWEEN &amp;amp; SYSDATE. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's Character Functions&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;Character Functions are INITCAP, UPPER, LOWER, SUBSTR &amp;amp; LENGTH. Additional functions are GREATEST &amp;amp; LEAST. Group Functions returns results based upon groups of rows rather than one result per row, use group functions. They are AVG, COUNT, MAX, MIN &amp;amp; SUM. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's TTITLE &amp;amp; BTITLE&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;TTITLE &amp;amp; BTITLE are commands to control report headings &amp;amp; footers. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's COLUMN&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;COLUMN command define column headings &amp;amp; format data values. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's BREAK&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;BREAK command clarify reports by suppressing repeated values, skipping lines &amp;amp; allowing for controlled break points. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's COMPUTE&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;command control computations on subsets created by the BREAK command.&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's SET&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;SET command changes the system variables affecting the report environment. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's SPOOL&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;SPOOL command creates a print file of the report. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's JOIN&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;JOIN is the form of SELECT command that combines info from two or more tables.&lt;BR&gt;Types of Joins are Simple (Equijoin &amp;amp; Non-Equijoin), Outer &amp;amp; Self join.&lt;BR&gt;Equijoin returns rows from two or more tables joined together based upon a equality condition in the WHERE clause.&lt;BR&gt;Non-Equijoin returns rows from two or more tables based upon a relationship other than the equality condition in the WHERE clause. Outer Join combines two or more tables returning those rows from one table that have no direct match in the other table. Self Join joins a table to itself as though it were two separate tables. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's Union&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;Union is the product of two or more tables. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's Intersect&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;Intersect is the product of two tables listing only the matching rows. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What's Minus&lt;/FONT&gt; &lt;/B&gt;&lt;/P&gt;&lt;P&gt;Minus is the product of two tables listing only the non-matching rows. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What is a Correlated Subquery ?&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Correlated Subquery is a subquery that is evaluated once for each row processed by the parent statement. Parent statement can be Select, Update or Delete. Use CRSQ to answer multipart questions whose answer depends on the value in each row processed by parent statement. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What are Multiple columns ?&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Multiple columns can be returned from a Nested Subquery. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What are Sequences ?&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Sequences are used for generating sequence numbers without any overhead of locking. Drawback is that after generating a sequence number if the transaction is rolled back, then that sequence number is lost. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color=#113311&gt;What are Synonyms ?&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Synonyms is the alias name for table, views, sequences &amp;amp; procedures and are created for reasons of Security and Convenience.  Two levels are Public - created by DBA &amp;amp; accessible to all the users. Private - Accessible to creator only. Advantages are referencing without specifying the owner and Flexibility to customize a more meaningful naming convention. &lt;/P&gt;</description><pubDate>Wed, 03 Dec 2008 15:29:39 GMT</pubDate><dc:creator>Admin</dc:creator></item></channel></rss>