PL/SQL Interview Questions with Answers Page III
From freshersonline.com
1. What's Deadlock
Deadlock is a unique situation in a multi user system that causes two or more users to wait indefinitely for a locked
resource. First user needs a resource locked by the second user and the second user needs a resource locked by the first
user. To avoid dead locks, avoid using exclusive table lock and if using, use it in the same sequence and use Commit
frequently to release locks.
2. What's Mutating Table
Mutating Table is a table that is currently being modified by an Insert, Update or Delete statement. Constraining Table
is a table that a triggering statement might need to read either directly for a SQL statement or indirectly for a declarative
Referential Integrity constraints. Pseudo Columns behaves like a column in a table but are not actually stored in the table.
E.g. Currval, Nextval, Rowid, Rownum, Level etc.
3. hat's SQL*Loader
SQL*Loader is a product for moving data in external files into tables in an Oracle database. To load data from external files
into an Oracle database, two types of input must be provided to SQL*Loader : the data itself and the control file. The control
file describes the data to be loaded. It describes the Names and format of the data files, Specifications for loading data and
the Data to be loaded (optional). Invoking the loader sqlload username/password controlfilename <options>.
4. The most important DDL statements in SQL are:
CREATE TABLE - creates a new database table
ALTER TABLE - alters (changes) a database table
DROP TABLE - deletes a database table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
5. Operators used in SELECT statements.
= Equal
<> or != Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
6. SELECT statements:
SELECT column_name(s) FROM table_name
SELECT DISTINCT column_name(s) FROM table_name
SELECT column FROM table WHERE column operator value
SELECT column FROM table WHERE column LIKE pattern
SELECT column,SUM(column) FROM table GROUP BY column
SELECT column,SUM(column) FROM table GROUP BY column HAVING SUM(column) condition value
Note that single quotes around text values and numeric values should not be enclosed in quotes. Double quotes may be
acceptable in some databases.
7. The SELECT INTO Statement is most often used to create backup copies of tables or for archiving records.
SELECT column_name(s) INTO newtable [IN externaldatabase] FROM source
SELECT column_name(s) INTO newtable [IN externaldatabase] FROM source WHERE column_name operator value
8. The INSERT INTO Statements:
INSERT INTO table_name VALUES (value1, value2,....)
INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)
9. The Update Statement:
UPDATE table_name SET column_name = new_value WHERE column_name = some_value
10. The Delete Statements:
DELETE FROM table_name WHERE column_name = some_value
Delete All Rows:
DELETE FROM table_name or DELETE * FROM table_name
11. Sort the Rows:
Sort the Rows:
SELECT column1, column2, ... FROM table_name ORDER BY columnX, columnY, ..
SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC
SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC, columnY ASC
12. The IN operator may be used if you know the exact value you want to return for at least one of the columns.
SELECT column_name FROM table_name WHERE column_name IN (value1,value2,..)
13. BETWEEN ... AND
SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2 The values can be numbers, text, or dates.
14. What is the use of CASCADE CONSTRAINTS?
When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.
15. Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME; Variable names should start with an alphabet. Here the table name starts with an '&' symbol.
16. What command is used to create a table by copying the structure of another table?
CREATE TABLE .. AS SELECT command
Explanation:
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.
17. TRUNCATE TABLE EMP;
DELETE FROM EMP;
Will the outputs of the above two commands differ?
Both will result in deleting all the rows in the table EMP..
18. What is the output of the following query SELECT TRUNC(1234.5678,-2) FROM DUAL;?
1200.
19. What are the wildcards used for pattern matching.?
_ for single character substitution and % for multi-character substitution.
20. What is the parameter substitution symbol used with INSERT INTO command?
&
