SQL - Questions & Answers
SQL - Questions & Answers
3 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.
5 What should be the return type for a cursor variable.Can we use a scalar data type as return type?
The return type for a cursor must be a record type.It can be declared explicitly as a user-defined or
%ROWTYPE can be used. eg TYPE t_studentsref IS REF CURSOR RETURN students%ROWTYPE
8 What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?
1,000,00
9 What is syntax for dropping a procedure and a function .Are these operations possible?
Drop Procedure procedure_nameDrop Function function_name
16 What is an UTL_FILE.What are different procedures and functions associated with it?
UTL_FILE is a package that adds the ability to read and write to operating system files. Procedures associated
with it are FCLOSE, FCLOSE_ALL and 5 procedures to output data to a file PUT, PUT_LINE, NEW_LINE,
PUTF, FFLUSH.PUT, FFLUSH.PUT_LINE,FFLUSH.NEW_LINE. Functions associated with it are FOPEN,
ISOPEN.
17 What is a view ?
A view is stored procedure based on one or more tables, it’s a virtual table.
20 What is a cursor?
Oracle uses work area to execute SQL statements and store processing information PL/SQL construct called a
cursor lets you name a work area and access its stored information A cursor is a mechanism used to fetch more
than one row in a Pl/SQl block.
22 What are various privileges that a user can grant to another user?
· SELECT· CONNECT· RESOURCES
29 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
30 There is a % sign in one field of a column. What will be the query to find it?
'' Should be used before '%'.
31 Suppose a customer table is having different columns like customer no, payments.What will be the query to
select top three max payments?
SELECT customer_no, payments from customer C1
WHERE 3<=(SELECT COUNT(*) from customer C2
WHERE C1.payment <= C2.payment)
50 Can cursor variables be stored in PL/SQL tables.If yes how. If not why?
No, a cursor variable points a row which cannot be stored in a two-dimensional PL/SQL table.
1 What is PL/SQL ?
PL/SQL is a procedural language that has both interactive SQL and procedural programming language
constructs such as iteration, conditional branching.
I & ii.
Exception :
4 What are % TYPE and % ROWTYPE ? What are the advantages of using these over datatypes?
% TYPE provides the data type of a variable or a database column to that variable.
% ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in
the cursor.
The advantages are : I. Need not know about variable's data type
ii. If the database definition of a column in a table changes, the data type of a variable changes accordingly.
The cursor having query as SELECT .... FOR UPDATE gets closed after COMMIT/ROLLBACK.
The cursor having query as SELECT.... does not get closed even after COMMIT/ROLLBACK.
PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks can be used in
PL/SQL.
7 What is Raise_application_error ?
The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error. To get an
error message of a specific oracle error.
Objects of type TABLE are called "PL/SQL tables", which are modeled as (but not the same as) database
tables, PL/SQL tables use a primary PL/SQL tables can have one column and a primary key.
Cursors
The Same procedure name is repeated with parameters of different datatypes and parameters in different
positions, varying number of parameters is called overloading of procedures.
12 What is difference between a Cursor declared in a procedure and Cursor declared in a package specification
?
A cursor declared in a package specification is global and can be accessed by other procedures or procedures
in a package.
A cursor declared in a procedure is local to the procedure that can not be accessed by other procedures.
E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type
);
e_rec emp% ROWTYPE
cursor c1 is select empno,deptno from emp;
e_rec c1 %ROWTYPE.
Database trigger is stored PL/SQL program unit associated with a specific database table. Usages are Audit
data modifications, Log events transparently, Enforce complex business rules Derive column values
automatically, Implement complex security authorizations. Maintain replicate tables.
Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values from
active set into fields in the record and closes
when all the records have been processed.
Cursor is a named private SQL area from where information can be accessed. Cursors are required to process
rows individually for queries returning multiple rows.
19 What happens if a procedure that updates a column of table X is called in a database trigger of the same
table ?
20 What are two virtual tables available during database trigger execution ?
The two parts of package are PACKAGE SPECIFICATION & PACKAGE BODY.
Package Specification contains declarations that are global to the packages and local to the schema.
Package Body contains actual procedures and local declaration of the procedures and cursor declarations.
SQLCODE returns the latest code of the error that has occurred.
SQLERRM returns the relevant error message of the SQLCODE.
DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types, CLOSE
cursor name.
IN,OUT,IN-OUT parameters.
Some scalar data types such as NUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN.
Some composite data types such as RECORD & TABLE.
Datatypes PL/SQL
I & ii.
Exception :
4 What are % TYPE and % ROWTYPE ? What are the advantages of using these over datatypes?
% TYPE provides the data type of a variable or a database column to that variable.
% ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in
the cursor.
The advantages are : I. Need not know about variable's data type
ii. If the database definition of a column in a table changes, the data type of a variable changes accordingly.
The cursor having query as SELECT .... FOR UPDATE gets closed after COMMIT/ROLLBACK.
The cursor having query as SELECT.... does not get closed even after COMMIT/ROLLBACK.
PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks can be used in
PL/SQL.
7 What is Raise_application_error ?
Raise_application_error is a procedure of package DBMS_STANDARD which allows to issue an user_defined
error messages from stored sub-program or database trigger.
The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error. To get an
error message of a specific oracle error.
Objects of type TABLE are called "PL/SQL tables", which are modeled as (but not the same as) database
tables, PL/SQL tables use a primary PL/SQL tables can have one column and a primary key.
Cursors
The Same procedure name is repeated with parameters of different datatypes and parameters in different
positions, varying number of parameters is called overloading of procedures.
12 What is difference between a Cursor declared in a procedure and Cursor declared in a package specification
?
A cursor declared in a package specification is global and can be accessed by other procedures or procedures
in a package.
A cursor declared in a procedure is local to the procedure that can not be accessed by other procedures.
E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type
);
e_rec emp% ROWTYPE
cursor c1 is select empno,deptno from emp;
e_rec c1 %ROWTYPE.
14 What is an Exception ? What are types of Exception ?
Exception is the error handling part of PL/SQL block. The types are Predefined and user defined. Some of
Predefined exceptions are.
CURSOR_ALREADY_OPEN
DUP_VAL_ON_INDEX
NO_DATA_FOUND
TOO_MANY_ROWS
INVALID_CURSOR
INVALID_NUMBER
LOGON_DENIED
NOT_LOGGED_ON
PROGRAM-ERROR
STORAGE_ERROR
TIMEOUT_ON_RESOURCE
VALUE_ERROR
ZERO_DIVIDE
OTHERS.
Database trigger is stored PL/SQL program unit associated with a specific database table. Usages are Audit
data modifications, Log events transparently, Enforce complex business rules Derive column values
automatically, Implement complex security authorizations. Maintain replicate tables.
Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values from
active set into fields in the record and closes
when all the records have been processed.
Cursor is a named private SQL area from where information can be accessed. Cursors are required to process
rows individually for queries returning multiple rows.
19 What happens if a procedure that updates a column of table X is called in a database trigger of the same
table ?
20 What are two virtual tables available during database trigger execution ?
The two parts of package are PACKAGE SPECIFICATION & PACKAGE BODY.
Package Specification contains declarations that are global to the packages and local to the schema.
Package Body contains actual procedures and local declaration of the procedures and cursor declarations.
SQLCODE returns the latest code of the error that has occurred.
SQLERRM returns the relevant error message of the SQLCODE.
DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types, CLOSE
cursor name.
IN,OUT,IN-OUT parameters.
Some scalar data types such as NUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN.
Some composite data types such as RECORD & TABLE.
Datatypes PL/SQL
31 Name the tables where characteristics of Package, procedure and functions are stored ?
32 Is it possible to use Transaction control Statements such a ROLLBACK or COMMIT in Database Trigger ?
Why ?
It is not possible. As triggers are defined for each table, if you use COMMIT of ROLLBACK in a trigger, it
affects logical transaction processing.
33 How packaged procedures and functions are called from the following?
a. Stored procedure or anonymous block
b. an application program such a PRC C, PRO COBOL
c. SQL *PLUS
34 How many types of database triggers can be specified on a table ? What are they ?
If FOR EACH ROW clause is specified, then the trigger for each Row affected by the statement.
If WHEN clause is specified, the trigger fires according to the returned Boolean value.
end;
WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetched from a
cursor.
Database Triggers
There are two types of cursors, Implicit Cursor and Explicit Cursor.
PL/SQL uses Implicit Cursors for queries.
User defined cursors are called Explicit Cursors. They can be declared and used.
Programmatic Constructs
Last Update: September 06, 2004
1 What are the different types of PL/SQL program units that can be defined and stored in ORACLE database ?
Procedures and Functions,Packages and Database Triggers.
2 What are the differences between Database Trigger and Integrity constraints ?
A declarative integrity constraint is a statement about the database that is always true. A constraint applies to
existing data in the table and any statement that manipulates the table.
A trigger does not apply to data loaded before the definition of the trigger, therefore, it does not guarantee all
data in a table conforms to the rules established by an associated trigger.
A trigger can be used to enforce transitional constraints where as a declarative integrity constraint cannot be
used.
5 What is a Procedure ?
A Procedure consist of a set of SQL and PL/SQL statements that are grouped together as a unit to solve a
specific problem or perform a set of related tasks.
6 What is a Package ?
A Package is a collection of related procedures, functions, variables and other package constructs together as a
unit in the database.
4 Which parameter can be used to set read level consistency across multiple queries?
Read only.
8 Where is a procedure return in an external pl/sql library executed at the client or at the server?
At the client.
10 When a form is invoked with call_form, Does oracle forms issues a save point?
Yes
11 What are the important difference between property clause and visual attributes?
Named visual attributes differ only font, color & pattern attributes, property clauses can contain this and any
other properties. You can change the appearance of objects at run time by changing the named visual attributes
programmatically , property clause assignments cannot be changed programmatically. When an object is
inheriting from both a property clause and named visual attribute, the named visual attribute settings take
precedence, and any visual attribute properties in the class are ignored.
22 What is the purpose of the product order option in the column property sheet?
To specify the order of individual group evaluation in a cross products.
23 What is the maximum no of chars the parameter can store?
The maximum no of chars the parameter can store is only valid for char parameters, which can be upto 64K.
No parameters default to 23Bytes and Date parameter default to 7Bytes.
24 What is the main diff. bet. Reports 2.0 & Reports 2.5?
Report 2.5 is object oriented.
27 What is the difference between object embedding & linking in Oracle forms?
In Oracle forms, Embedded objects become part of the form module, and linked objects are references from a
form module to a linked source file.
28 What is the difference between boiler plat images and image items?
Boiler plate Images are static images (Either vector or bit map) that you import from the file system or
database to use a graphical elements in your form, such as company logos and maps. Image items are special
types of interface controls that store and display either vector or bitmap images. Like other items that store
values, image items can be either base table items(items that relate directly to database columns) or control
items. The definition of an image item is stored as part of the form module FMB and FMX files, but no image
file is actually associated with an image item until the item is populate at run time.
29 What is the difference between $$DATE$$ & $$DBDATE$$ $$DBDATE$$ retrieves the current database
date $$date$$ retrieves the current operating system date.
30 What is the diff. when Flex mode is mode on and when it is off?
When flex mode is on, reports automatically resizes the parent when the child is resized.
32 What is the diff. bet. setting up of parameters in reports 2.0 reports 2.5?
LOVs can be attached to parameters in the reports 2.5 parameter form.
34 What is term?
The term is terminal definition file that describes the terminal form which you are using r20run.
35 What is system.coordination_operation?
It represents the coordination causing event that occur on the master block in master-detail relation.
36 What is synchronize?
It is a terminal screen with the internal state of the form. It updates the screen display to reflect the information
that oracle forms has in its internal representation of the screen.
42 What is forms_DDL?
Issues dynamic Sql statements at run time, including server side pl/SQl and DDL
46 What is an OLE?
Object Linking & Embedding provides you with the capability to integrate objects from many Ms-Windows
applications into a single compound document creating integrated applications enables you to use the features
form .
49 What is a User_exit?
Calls the user exit named in the user_exit_string. Invokes a 3Gl program by name which has been properly
linked into your current oracle forms executable.
50 What is a timer?
Timer is an "internal time clock" that you can programmatically create to perform an action each time the
timer expires.
55 What is a library?
A library is a collection of subprograms including user named procedures, functions and packages.