Professional Documents
Culture Documents
Structured Query Language (SQL) is a language that provides an interface to relational database
systems. SQL was developed by IBM in the 1970s for use in System R. SQL is a de facto standard, as
well as an ISO and ANSI standard. SQL is often pronounced SEQUEL.
What is a Session?
The period between Login and Log-off on Schema.
How to change Line Size and Page Size and SQL Prompt?
By using SET LINESIZE <value>, SET PAGESIZE <value>, SET SQLPROMPT <new prompt>.
What is Database?
The Collection of Interrelated Data is called Data Base.
How many LONG columns are allowed in a table? Is it possible to use LONG columns in
WHERE clause or ORDER BY?
Only one LONG column is allowed. It is not possible to use LONG column in WHERE or ORDER
BY clause.
What is ROWID?
ROWID is a pseudo column attached to each row of a table. It is 18 character long, block no, row
number are the components of ROWID
What are the difference between DDL, DML, DQL, TCL and DCL commands?
DDL: DDL statements are used to define the data base structure or schema.
(A) CREATE
(B) ALTER
(C) DROP
DML: DML statements are used to manage the data with in the schema objects.
(A) INSERT
(B) UPDATE
(C) DELETE
DQL: DQL is used to get the data from data base objects for read only purpose
DCL: It is used to share information between users
(A) GRANT - It is used to give permission
(B) REVOKE - It is used to cancel the permission
TCL: It is used to control the DML operation.
(A) COMMIT - It is used to save the data dynamically.
(B) ROLL BACK - It is used to cancel the changes.
(C) SAVEPOINT - It is used to mark the transactions.
What is a transaction?
A transaction is a set of SQL statements between any two COMMIT and ROLLBACK statements.
What is the maximum no. of columns a table can have?
1000
Can we change the data type and size in a table when data is there and when data is not there?
When there is data we can increase the size, we can not decrease the size but we cannot change the
data type.
Yes we can change the data type and size when there is no data
When do you use WHERE clause and when do you use HAVING clause?
HAVING clause is used when you want to specify a condition for a group function and it is written
after GROUP BY clause. The WHERE clause is used when you want to specify a condition for
columns, single row functions except group functions and it is written before GROUP BY clause if it
is used.
How does one escape special characters when building SQL queries?
The LIKE keyword allows for string searches. The '_' wild card character is used to match exactly one
character, '%' is used to match zero or more occurrences of any characters. These characters can be
escaped in SQL.
Ex: SELECT ename FROM emp WHERE empno LIKE '%_%' ESCAPE '\';
How does one escape special characters when writing SQL queries?
Use tow quotes for every one displayed.
Ex: SELECT 'frank’’s Oracle Site' as text from dual;
What are various privileges that a user can grant to another user?
(i) SELECT
(ii) CONNECT
(iii) RESOURCES
What is SAVEPOINT?
A SAVEPOINT is a mark with in a transaction that allows for a partial rollback.
An insert statement followed by a create table statement followed by rollback? Will the rows be
inserted?
No.
If you insert a row in a table, then create another table and then say Rollback. In this case will
the row be inserted?
Yes, because Create table is a DDL which commits automatically as soon as it is executed.
The DDL commits the transactions even if the create statement fails internally.
What is DISTINCT?
The DISTINCT clause removes the duplicate values from the result set.
Display the records between two range I know the nvl function only allows the same data type(ie.
number or char or date Nvl(comm, 0)), if commission is null then the text “Not Applicable” want
to display, instead of blank space. How do I write the query?
You can use the decode function for the above requirement. Please find the query as below:
Ex: select ename,DECODE(NVL(comm,0),0,'Not Applicable',comm) from scott.emp;
What is the use of CASE?
CASE expression is used like IF..THEN...ELSE logic in SQL statement without invoking procedures.
Example:
SELECT ename,
sal,
CASE sal WHEN 1000 THEN 'Low'
WHEN 5000 THEN 'High'
ELSE 'Medium'
END
FROM emp;
What is the difference b/w sub query and correlated sub query?
In a normal sub query the child query does not depends upon parent query for the conditional value.
Here child query processes first and returns values to parent query.
In a correlated sub query the child query depends upon the parent query for the conditional value. Here
parent query processed first then child query processed one by one for each row of parent query.
What is a JOIN?
It is used to display data from more than one table in single query.
A join is a query that combines rows from two or more tables, views or materialized views.
What is SELF-JOIN?
SELF JOIN is nothing but EQUI JOIN on same table. For self join the table must have at least two
common columns.
Select e.ename "E_NAME",
m.ename "M_NAME"
FROM emp e,
emp m
WHERE e.mgr = m.empno;
What is EQUI-JOIN?
It is used to retrieve data from different tables based on the join condition.
For this condition we need to have at least common column between the tables.
For this join we use '=' operator
SELECT e.empno,
d.dname
FROM emp e,
dept d
WHERE e.deptno = d.deptno;
What Is INNER-JOIN?
It is also same as EQUI-JOIN but syntax is different.
SELECT e.empno, d.dname
FROM emp e
INNER JOIN dept d
ON e.deptno = d.deptno;
What is created implicitly for every UNIQUE and PRIMARY KEY column?
INDEX
What are the pre-requisites to (i) modify data type of a column (ii) add a column with NOT
NULL constraint?
To Modify the data type of a column the column must be empty.
To add a column with NOT NULL constrain, the table must be empty
What is a sequence?
Sequence is a database object. It is used to generate number in order. It is not related to table. By using
sequence the retrieve data from table is very fast.
It has two pseudo columns.
NEXTVAL (holds the next generated value)
CURRVAL (holds the current available value)
Consider a sequence whose currval is 1 and gets incremented by 1 by using the nextval reference
we get the next number 2. Suppose at this point we issue a rollback and again issue a nextval.
What will the output be?
The output will be 3
What is a view?
View is a logical table based on one or more tables or views. It contains no data, it contains only
SELECT statement. The view is logically & physically independent from table.
Syntax : CREATE or REPLACE view <view_name> AS select * from <table name>;
• Provide an additional level of table security by restricting access to a predetermined set of
rows and/or columns of a table
• Hide data complexity
• Simplify commands for the user
• Present the data in a different perspective from that of the base table
• Isolate applications from changes in definitions of base tables
• Express a query that cannot be expressed without using a view
If a View on a single base table is manipulated will the changes be reflected on the base table?
If changes are made to the tables which are base tables of a view then the changes effected on view.
What is the function of 'force' in view?
FORCE function is used to create view with out table. When we create the corresponding tables the
forced view become valid. When we drop the base table the view exists but becomes forced view.
What is a SNAPSHOT?
It is a static picture of table, snapshot is a table that contains the results of a query of one or more
tables or views, and it contains structure and data also.
Data retrieval is faster in snapshot than view.
Syntax: CREATE snapshot <snapshot_name> AS select statement
What is the difference between snap shots and materialized views?
SNAP SHOT : A Snap Shot is a replication of master table from a single point-in-time
Snapshots are updated by one or more master tables via individual
batch updates are known as refresh.
MATERIALIZED VIEW : Materialized view will be created to access the base table information
and it is not possible to do DML operations on that
What is a SYNONYM?
A synonym is an alternative name for objects such as tables, views, sequences, stored procedures and
other database objects. Generally when we have more than one schema and we wish to access an
object of a different schema then we create synonyms for that object in the schema where we wish to
access the object.
It is used to hide the information, some times we create synonym to give short name of the object.
Types of synonym:
Private – created by user--default
Public – created by DBA
Syntax: CREATE synonym <synonym_name> for <object_name>
If we delete the base table whether the synonym will exists or not? If we use that synonym what
type of error we will get?
The SYNONYM will be exists even though the Table was dropped.
If we use that synonym the following errors will come
ORA-00980: synonym translation is no longer valid
ORA-00903: invalid table name
ORA-04043: object SCOTT.T1 does not exist
Can database trigger written on synonym of a table and if it can be then what would be the
effect if original table is accessed.
Yes, database trigger would fire.