SQL PLUS Testing FAQs

SQL PLUS STATEMENTS

1. What are the types of SQL Statement ?

Data Definition Language : CREATE,ALTER,DROP,TRUNCATE,REVOKE,NO AUDIT & COMMIT.
Data Manipulation Language : INSERT,UPublish PostPDATE,DELETE,LOCK TABLE,EXPLAIN PLAN & SELECT.

Transactional Control : COMMIT & ROLLBACK
Session Control : ALTERSESSION & SET ROLE
System Control : ALTER SYSTEM.

2. What is a transaction ?

Transaction is logical unit between two commits and commit and rollback.             
  

3. What is difference between TRUNCATE & DELETE ?

TRUNCATE commits after deleting entire table i.e., can not be rolled back. Database triggers do not fire on TRUNCATE

DELETE allows the filtered deletion. Deleted records can be rolled back or committed.
Database triggers fire on DELETE.

4. What is a join ? Explain the different types of joins ?

Join is a query which retrieves related columns or rows from multiple tables.

Self Join - Joining the table with itself.
Equi Join - Joining two tables by equating two common columns.
Non-Equi Join - Joining two tables by equating two common columns.
Outer Join - Joining two tables in such a way that query can also retrive rows that do not have corresponding join value in the other table.

5. What is the Subquery ?

Subquery is a query whose return values are used in filtering conditions of the main query.

6. What is correlated sub-query ?

Correlated sub_query is a sub_query which has reference to the main query.

7. Explain Connect by Prior ?

Retrives rows in hierarchical order.
e.g. select empno, ename from emp where.

8. Difference between SUBSTR and INSTR ?

INSTR (String1,String2(n,(m)),
INSTR returns the position of the mth occurrence of the string 2 in
string1. The search begins from nth position of string1.

SUBSTR (String1 n,m)
SUBSTR returns a character string of size m in string1, starting from nth postion of string1.

9. Explain UNION,MINUS,UNION ALL, INTERSECT ?

INTERSECT returns all distinct rows selected by both queries.
MINUS - returns all distinct rows selected by the first query but not by the second.
UNION - returns all distinct rows selected by either query
UNION ALL - returns all rows selected by either query,including all duplicates.        
 
10. What is ROWID ?

ROWID is a pseudo column attached to each row of a table. It is 18 character long, blockno, rownumber are the components of ROWID.

11. What is the fastest way of accessing a row in a table ?

Using ROWID.
 CONSTRAINTS

12. What is an Integrity Constraint ?

Integrity constraint is a rule that restricts values to a column in a table.

13. What is Referential Integrity ?

Maintaining data integrity through a set of rules that restrict the values of one or more columns of the tables based on the values of primary key or unique key of the referenced table.

14. What are the usage of SAVEPOINTS ?

SAVEPOINTS are used to subdivide a transaction into smaller parts. It enables rolling back part of a transaction. Maximum of five save points are allowed.

15. What is ON DELETE CASCADE ?

When ON DELETE CASCADE is specified ORACLE maintains referential integrity by automatically removing dependent foreign key values if a referenced primary or unique key value is removed.

16. What are the data types allowed in a table ?

CHAR,VARCHAR2,NUMBER,DATE,RAW,LONG and LONG RAW.

17. What is difference between CHAR and VARCHAR2 ? What is the maximum SIZE allowed for each type ?

CHAR pads blank spaces to the maximum length. VARCHAR2 does not pad blank spaces. For CHAR it is 255 and 2000 for VARCHAR2.

18. 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 columns is allowed. It is not possible to use LONG column in WHERE or ORDER BY clause.

19. What are the pre requisites ?
I. to modify datatype of a column ?
ii. to add a column with NOT NULL constraint ?

To Modify the datatype of a column the column must be empty.
to add a column with NOT NULL constrain, the table must be empty.                 
  

20. Where the integrity constrints are stored in Data Dictionary ?

The integrity constraints are stored in USER_CONSTRAINTS.

21. How will you a activate/deactivate integrity constraints ?

The integrity constraints can be enabled or disabled by ALTER TABLE ENABLE constraint/DISABLE constraint.

22. If an unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE ?

It won't, Because SYSDATE format contains time attached with it.

23. What is a database link ?

Database Link is a named path through which a remote database can be accessed.

24. How to access the current value and next value from a sequence ? Is it possible to access the current value in a session before accessing next value ?

Sequence name CURRVAL, Sequence name NEXTVAL.

It is not possible. Only if you access next value in the session, current value can be accessed.

25. What is CYCLE/NO CYCLE in a Sequence ?

CYCLE specifies that the sequence continues to generate values after reaching either maximum or minimum value. After pan ascending sequence reaches its maximum value, it generates its minimum value. After a descending sequence reaches its minimum, it generates its maximum.

NO CYCLE specifies that the sequence cannot generate more values after reaching its maximum or minimum value.

26. What are the advantages of VIEW ?

To protect some of the columns of a table from other users.              
  
To hide complexity of a query.
To hide complexity of calculations.

27. Can a view be updated/inserted/deleted? If Yes under what conditions ?

A View can be updated/deleted/inserted if it has only one base table if the view is based on columns from one or more tables then insert, update and delete is not possible.

28.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 will the changes be reference on the view.
 

 1.
      Difference between group functions and single row functions. 

Group Function                                                         Single Row Function

1. A group function operates                             2. A single row function

on many rows  returns one and                          result for one row.

returns single result.

 Not allowed in Pl/sql procedural                                  Allowed in Pl/Sql

                                                                    Procedural statements

          statements.

eg SUM(),AVG,MIN,MAX  etc                                       eg UPPER,LOWER,CHR...

 2.      Difference between DECODE and TRANSLATE

   

DECODE is value by value                                 TRANSLATE is character by

character  replacement.                                             replacement.

Ex  SELECT  DECODE('ABC','A',1,'B',2,'ABC',3)        eg      SELECT

from dual; o/p                                              TRANSLATE('ABCGH',

'ABCDEFGHIJ', 1234567899)

 FROM DUAL;  o/p  12378

   

(DECODE command is used to bring IF,THEN,ELSE logic to SQL.It tests for the IF values(s) and then aplies THEN value(s) when true, the ELSE value(s) if not.)

 3.      Difference between TRUNCATE and DELETE

 

TRUNCATE deletes much faster than DELETE

 

Truncate                                                                                Delete

It is a DDL statement                                       It is a DML statement

It is a one way trip,cannot                                One  can Rollback

ROLLBACK

Doesn't have selective features (where clause)    Has

Doesn't fire database triggers                                      Does

It requires disabling of referential                       Does not require

constraints.

 4.      What is a CO-RELATED SUBQUERY

 A CO-RELATED  SUBQUERY  is one that has a correlation

name as table or view designator in the FROM clause of the outer

query and the same correlation name as a qualifier of a search

condition in the WHERE clause of the subquery.

 

eg

     SELECT  field1 from table1 X

     WHERE  field2>(select avg(field2) from table1 Y

                                       where

                                       field1=X.field1);

 

                  (The subquery in a correlated subquery is revaluated

for every row of the table or view named in the outer query.)

 5.      What are various joins used while writing SUBQUERIES

 

Self join-Its a join foreign key of a table references the same table.

 

Outer Join--Its a join condition used where One can query all the rows of one of the

tables in the join condition even though they don't satisfy the join condition.

 

Equi-join--Its a join condition that retrieves rows from one or more tables in which one

or more columns in one table are equal to one or more columns in the second table.

 

 

6.      What are various constraints used in SQL

  NULL ,NOT NULL ,CHECK ,DEFAULT

  7.      What are different Oracle database objects

  TABLES ,VIEWS ,INDEXES ,SYNONYMS ,SEQUENCES ,TABLESPACES etc

 8.      What is difference between Rename and Alias

 Rename is a permanent name given to a table or column whereas Alias is a temporary name given to a table or column which do not exist once the  SQL statement is executed.

  9.      What is a view 

A view is stored procedure based on one or more tables, it’s a virtual table.

What are various privileges that a user can grant to another user

SELECT ,CONNECT ,RESOURCES

 10.  What is difference between UNIQUE and PRIMARY KEY constraints

  A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.

  11.  Can a primary key contain more than one columns  ? yes

 

     12.  How you will avoid duplicating records in a query

                  By using DISTINCT

  13.  What is difference between SQL and SQL*PLUS

  SQL*PLUS is a command line tool where as SQL and PL/SQL language  interface and reporting tool. Its a command line tool that allows user to type SQL commands to be executed directly against an Oracle database. SQL is a language used to query the relational database(DML,DCL,DDL). SQL*PLUS commands are used to format query result, Set options, Edit SQL commands and PL/SQL.

  14.  Which datatype is used for storing graphics and images

  LONG RAW data type is used for storing BLOB's (binary large objects).

 15.  How will you delete duplicating rows from a base table

       DELETE    FROM table_name A   WHERE rowid>(SELECT     min(rowid) from table_name B where          B.table_no=A.table_no);

CREATE  TABLE new_table AS SELECT  DISTINCT * FROM old_table;

 DROP old_table    RENAME  new_table TO  old_table

DELETE  FROM table_name A   WHERE  rowid NOT IN (SELECT MAX(ROWID) FROM table_name       GROUP BY column_name)

 16.  What is difference between SUBSTR and INSTR

 SUBSTR returns a specified portion of a string

      eg  SUBSTR('BCDEF',4)       output  BCDE

          INSTR  provides character position in which a pattern    is found in a string.

eg  INSTR('ABC-DC-F','-',2)    output   7 (2nd occurence of '-')

  17.  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

  18.  There is a '%' sign in one field of a column. What will be

the query to find it. ?          '\' Should be used before '%'.

  19.  When you use WHERE clause and when 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.

  20.  Which is more faster - IN or EXISTS

EXISTS is more faster than IN because EXISTS returns a Boolean value whereas IN  returns a value.

  21.  What is a OUTER JOIN

  Outer Join--Its a join condition used where you can query all the rows of one of the

tables in the join condition even though they don’t satisfy the join condition.

22.  How you will avoid your query from using indexes

SELECT * FROM emp  Where emp_no+' '=12345; i.e you have to concatenate  the column name with space within codes in the where condition. SELECT   /*+ FULL(a)  */  ename, emp_no from emp  where emp_no=1234;

i.e using  HINTS 

23.  What is a pseudo column. Give some examples

 It is a column that is not an actual column in the table. eg USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL.

24.  Suppose customer table is there 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)

 25.  What is the purpose of a cluster.

 Oracle does not allow a user to specifically locate tables, since that is a part of the function of the RDBMS. However, for the purpose of increasing performance, oracle   allows a developer to create a CLUSTER.  A CLUSTER  provides a means for storing data from different tables together for faster retrieval than if the table placement were left to the RDBMS.

26.  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 info A cursor is a mechanism used to fetch more than one row in a Pl/SQl block.

27.  Difference between an implicit & an explicit cursor.  

PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including quries that return only one row.  However,queries that return more than one row you must declare an explicit  cursor or use a cursor FOR loop. Explicit cursor is a cursor in which the cursor name is explicitly assigned to a SELECT statement via the  CURSOR...IS statement. An implicit cursor is used for all SQL statements Declare, Open, Fetch, Close. An explicit cursors are used to process multirow SELECT statements  An implicit cursor is used to process INSERT, UPDATE, DELETE and single  row SELECT. .INTO  statements, 

28.  What are cursor attributes  

             %ROWCOUNT ,   %NOTFOUND ,  %FOUND ,%ISOPEN  

29.  What is a cursor for loop.  

       Cursor For Loop is a loop where oracle implicitly declares a loop variable, the loop index that of the same record type as the cursor's record.

  30.  Difference between NO DATA FOUND and %NOTFOUND

NO DATA FOUND is an exception raised only for the SELECT....INTO statements

hen the where clause of the querydoes not  match any rows. When the where clause

of the explicit cursor does not match any rows the %NOTFOUND attribute is set to

TRUE instead.

  31.       What a SELECT FOR UPDATE cursor represent.  

SELECT......FROM......FOR......UPDATE[OF column-reference][NOWAIT] The processing done in a fetch loop modifies the rows that have been retrieved by the cursor. A convenient way of modifying the rows is done by a method with two parts: the FOR UPDATE clause in the cursor declaration, WHERE CURRENT OF CLAUSE in an UPDATE or declaration statement.

32.        What 'WHERE CURRENT OF ' clause does in a cursor.

LOOP

    SELECT  num_credits  INTO  v_numcredits  FROM classes                           WHERE  dept=123 and course=101;

 UPDATE  students  SET current_credits=current_credits+v_numcredits

                          WHERE  CURRENT OF  X;

  END  LOOP;                           COMMIT;                           END;

 

33.        What is use of a cursor variable? How it is defined.

  A cursor variable is associated with different statements at run time, which can hold

different values at run time. Static cursors can only be associated with  one run time

query. A cursor variable is reference type(like a pointer in C). Declaring a cursor variable: TYPE  type_name  IS REF CURSOR RETURN  return_type  type_name is the name of the reference type,return_type is a record type  indicating the types of the select list that will eventually be returned by the cursor variable.

  34.        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

35.        How you open and close a cursor variable.Why it is required.

OPEN  cursor variable FOR  SELECT...Statement

CLOSE cursor variable In order to associate a cursor variable with a particular

SELECT statement  OPEN syntax is used.In order to free the resources used

for the query CLOSE statement is used.

  36.        How you were passing cursor variables in PL/SQL 2.2.

In PL/SQL 2.2 cursor variables cannot be declared in a package.This is because the storage for a cursor variable has to be allocated using Pro*C or OCI with version 2.2,the only means of passing a cursor variable to a PL/SQL block is  via bind variable or a procedure parameter.

37.        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.

  38.        Difference between procedure and function.

  Functions are named PL/SQL blocks that return a value and can be called with arguments procedure a named block that can be called with parameter. A procedure all is a PL/SQL statement by itself, while a Function call is called as part of an expression.

  39.        What are different modes of parameters used in functions and procedures.

    IN  ,     OUT ,                   INOUT

40.         What is difference between a formal and an actual parameter

The variables declared in the procedure and which are passed, as arguments are called  actual, the parameters in the procedure declaration. Actual parameters contain the values that are passed to a procedure and receive results. Formal parameters are the  placeholders for the values of actual parameters

  41.        Can the default values be assigned  to  actual parameters.       Yes

  42.        Can a function take OUT parameters.If not why.

  No.A function has to return a value,an OUT parameter cannot return a value.

  43.        What is syntax for dropping a procedure and a function .Are these operations      possible.

   Drop Procedure procedure_name   ,     Drop Function function_name

  44.        What are ORACLE PRECOMPILERS.

  Using ORACLE PRECOMPILERS ,SQL statements and PL/SQL blocks can be contained inside 3GL programs written in C,C++,COBOL,PASCAL,  FORTRAN,PL/1 AND ADA. The Precompilers are known as Pro*C,Pro*Cobol,... This form of PL/SQL is known as embedded pl/sql,the language in which pl/sql is embedded is known as the host language.   The prcompiler translates the embedded SQL and pl/sql  ststements into calls to the precompiler runtime library.The output must be compiled and linked with  this library to  creater an executable.

  45.        What is OCI. What are its uses.

  Oracle Call Interface is a method of accesing database from a 3GL program. Uses--No precompiler is required,PL/SQL blocks are executed like  other DMLstatements.                       The OCI library provides  -functions to parse SQL statemets ,                                    -bind input variables ,   -bind output variables ,  -execute statements ,                              -fetch the results

  46.        Difference between database triggers and form triggers.

 a)      Data base trigger(DBT) fires when a DML operation is performed on a data base table.Form trigger(FT) Fires when user presses a key or navigates between fields  on the screen b)      Can be row level or statement level  No distinction between row level and statement level.c)      Can manipulate data stored in Oracle tables via SQL Can manipulate data in Oracle tables as well as variables in forms. d)      Can be fired from any session executing the triggering DML statements. Can be fired only from the form that define the trigger. e)      Can cause other database triggers to fire.Can cause other database triggers to fire,but not other form triggers.

  47.        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.

48.   Can you use a commit statement within a database trigger.          No

 49.  What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?

1,000,000

 

Basiscs of PL/SQL

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.

2. What is the basic structure of PL/SQL ?

PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks can be used in PL/SQL.

3. What are the components of a PL/SQL block ?

A set of related declarations and procedural statements is called block.

4. What are the components of a PL/SQL Block ?

Declarative part, Executable part and Execption part.

Datatypes PL/SQL

5. What are the datatypes a available in PL/SQL ?

Some scalar data types such as NUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN.
Some composite data types such as RECORD & TABLE.

6. 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.

7. What is difference between % ROWTYPE and TYPE RECORD ?

% ROWTYPE is to be used whenever query returns a entire row of a table or view.

TYPE rec RECORD is to be used whenever query returns columns of different
table or views and variables.

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.

8. What is PL/SQL table ?

Objects of type TABLE are called "PL/SQL tables", which are modelled 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

9. What is a cursor ? Why Cursor is required ?

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.

10. Explain the two type of Cursors ?

There are two types of cursors, Implict Cursor and Explicit Cursor.
PL/SQL uses Implict Cursors for queries.
User defined cursors are called Explicit Cursors. They can be declared and used.

11. What are the PL/SQL Statements used in cursor processing ?

DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types, CLOSE cursor name.

12. What are the cursor attributes used in PL/SQL ?

%ISOPEN - to check whether cursor is open or not
% ROWCOUNT - number of rows featched/updated/deleted.
% FOUND - to check whether cursor has fetched any row. True if rows are featched.
% NOT FOUND - to check whether cursor has featched any row. True if no rows are featched.
These attributes are proceded with SQL for Implict Cursors and with Cursor name for Explict Cursors.

13. What is a cursor for loop ?

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.

eg. FOR emp_rec IN C1 LOOP
salary_total := salary_total +emp_rec sal;
END LOOP;

14. What will happen after commit statement ?
Cursor C1 is
Select empno,
ename from emp;
Begin
open C1; loop
Fetch C1 into
eno.ename;
Exit When
C1 %notfound;-----
commit;
end loop;
end;

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.

15. Explain the usage of WHERE CURRENT OF clause in cursors ?

WHERE CURRENT OF clause in an UPDATE,DELETE statement refers to the latest row fetched from a cursor.

Database Triggers

16. What is a database trigger ? Name some usages of database trigger ?

Database trigger is stored PL/SQL program unit associated with a specific database table. Usages are Audit data modificateions, Log events transparently, Enforce complex business rules Derive column values automatically, Implement complex security authorizations. Maintain replicate tables.

17. How many types of database triggers can be specified on a table ? What are they ?

Insert Update Delete

Before Row o.k. o.k. o.k.

After Row o.k. o.k. o.k.

Before Statement o.k. o.k. o.k.

After Statement o.k. o.k. o.k.

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 retruned boolean value.

18. 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.

19. What are two virtual tables available during database trigger execution ?

The table columns are referred as OLD.column_name and NEW.column_name.
For triggers related to INSERT only NEW.column_name values only available.
For triggers related to UPDATE only OLD.column_name NEW.column_name values only available.
For triggers related to DELETE only OLD.column_name values only available.

20. What happens if a procedure that updates a column of table X is called in a database trigger of the same table ?

Mutation of table occurs.

21. Write the order of precedence for validation of a column in a table ?
I. done using Database triggers.
ii. done using Integarity Constraints.

I & ii.

Exception :

22. 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 execptions 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.

23. What is Pragma EXECPTION_INIT ? Explain the usage ?

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.

e.g. PRAGMA EXCEPTION_INIT (exception name, oracle error number)

24. 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.

25. What are the return values of functions SQLCODE and SQLERRM ?

SQLCODE returns the latest code of the error that has occured.
SQLERRM returns the relevant error message of the SQLCODE.

26. Where the Pre_defined_exceptions are stored ?

In the standard package.

Procedures, Functions & Packages ;

27. What is a stored procedure ?

A stored procedure is a sequence of statements that perform specific function.

28. What is difference between a PROCEDURE & FUNCTION ?

A FUNCTION is alway returns a value using the return statement.
A PROCEDURE may return one or more values through parameters or may not return at all.

29. What are advantages fo Stored Procedures /

Extensibility,Modularity, Reusability, Maintainability and one time compilation.

30. What are the modes of parameters that can be passed to a procedure ?

IN,OUT,IN-OUT parameters.

31. What are the two parts of a procedure ?

Procedure Specification and Procedure Body.

32. Give the structure of the procedure ?


PROCEDURE name (parameter list.....)
is
local variable declarations

BEGIN
Executable statements.
Exception.
exception handlers

end;

33. Give the structure of the function ?


FUNCTION name (argument list .....) Return datatype is
local variable declarations
Begin
executable statements
Exception
execution handlers
End;

34. Explain how procedures and functions are called in a PL/SQL block ?

Function is called as part of an expression.
sal := calculate_sal ('a822');
procedure is called as a PL/SQL statement
calculate_bonus ('A822');

35. What is Overloading of procedures ?

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.

e.g. DBMS_OUTPUT put_line

36. What is a package ? What are the advantages of packages ?

Package is a database object that groups logically related procedures.
The advantages of packages are Modularity, Easier Applicaton Design, Information. Hiding,. reusability and Better Performance.

37.What are two parts of package ?

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.

38. 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.

39. 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

a. PACKAGE NAME.PROCEDURE NAME (parameters);
variable := PACKAGE NAME.FUNCTION NAME (arguments);
EXEC SQL EXECUTE
b.
BEGIN
PACKAGE NAME.PROCEDURE NAME (parameters)
variable := PACKAGE NAME.FUNCTION NAME (arguments);
END;
END EXEC;
c. EXECUTE PACKAGE NAME.PROCEDURE if the procedures does not have any
out/in-out parameters. A function can not be called.

40. Name the tables where characteristics of Package, procedure and functions are stored ?

User_objects, User_Source and User_error.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Oracle

 

1. Three beauty pageant finalists-Cindy, Amy and Linda-The winner was musician. The one who was not last or first was a math major. The one who came in third had black hair. Linda had red hair. Amy had no musical abilities. Who was first?
           (A) Cindy                       (B) Amy                       (C) Linda                       (D) None of these

2. Two twins have certain peculiar characteristics. One of them always lies on Monday, Wednesday, Friday. The other always lies on Tuesdays, Thursday and Saturdays. On the other days they tell the truth. You are given a conversation.
                      Person A- today is Sunday, my name is Anil
                      Person B-today is Tuesday, my name is Bill                        What day is today?
           (A) Sunday                       (B) Tuesday                       (C) Monday                   (D) Thursday

3. The difference of a number and its reciprocal is 1/2.The sum of their squares is 
           (A) 9/4                           (B) 4/5                           (C) 5/3                           (D) 7/4

4. The difference of a number and its square is 870.What is the number?
           (A) 42                           (B) 29                               (C) 30                           (D) 32

5. A trader has 100 Kg of wheat, part of which he sells at 5% profit and the rest at 20% profit. He gains 15% on the whole. Find how much is sold at 5% profit?
           (A) 60                           (B) 50                               (C) 66.66                           (D) 33.3

6. Which of the following points are collinear?
           (A) (3,5)   (4,6)   (2,7)                               (B) (3,5)   (4,7)   (2,3)
           (C) (4,5)   (4,6)   (2,7)                               (D) (6,7)   (7,8)   (2,7)

7. A man leaves office daily at 7pm.a driver with car comes from his home to pick him from office and bring back home. One day he gets free at 5.30 and instead of waiting for driver he starts walking towards home. In the way he meets the car and returns home on car. He reaches home 20 minutes earlier than usual. In how much time does the man reach home usually?
           (A) 1 hr 20 min                           (B) 1 hr                       (C) 1 hr 10 min                    (D) 55 min

8. If m:n = 2:3,the value of 3m+5n/6m-n is
           (A) 7/3                           (B) 3/7                           (C) 5/3                           (D) 3/5

9. A dog taken four leaps for every five leaps of hare but three leaps of the dog is equal to four leaps of the hare. Compare speed?
           (A) 12:16                       (B) 19:20                       (C) 16:15                       (D) 10:12

10. A watch ticks 90 times in 95 seconds. And another watch ticks 315 times in 323 secs. If they start together, how many times will they tick together in first hour?
           (A) 100 times                   (B) 101 times                   (C) 99 times                   (D) 102 times

11. The purpose of defining an index is 
           (A) Enhance Sorting Performance                       (B) Enhance Searching Performance
           (C) Achieve Normalization                                 (D) All of the above

12. A transaction does not necessarily need to be
           (A) Consistent               (B) Repeatable               (C) Atomic               (D) Isolated

13. To group users based on common access permission one should use 
           (A) User Groups               (B) Roles               (C) Grants               (D) None of the above

14. PL/SQL uses which of the following
           (A) No Binding           (B) Early Binding           (C) Late Binding           (D) Deferred Binding

15. Which of the constraint can be defined at the table level as well as at the column level
           (A) Unique                   (B) Not Null                   (C) Check                   (D) All the above

16. To change the default date format in a SQLPLUS Session you have to 
           (A) Set the new format in the DATE_FORMAT key in the windows Registry.
           (B) Alter session to set NLS_DATE-FORMAT.
           (C) Change the Config.ora File for the date base.
           (D) Change the User Profile USER-DATE-FORMAT.

17. Which of the following is not necessarily an advantages of using a package rather than independent stored procedure in data base. 
           (A) Better performance.                                                   (B) Optimized memory usage.
           (C) Simplified Security implementation.                             (D) Encapsulation.

18. Integrity constrains are not checked at the time of 
           (A) DCL Statements.                           (B) DML Statements.
           (C) DDL Statements.                           (D) It is checked all the above cases.

19. Roll Back segment is not used in case of a
           (A) DCL Statements.       (B) DML Statements.       (C) DDL Statements.       (D) all of the above.

20. An Arc relationship is applicable when
           (A) One child table has multiple parent relation, but for anyone instance of a child record only one of the relations is applicable.
           (B) One column of a table is related to another column of the same table.
           (C) A child table is dependent on columns other than the primary key columns of the parent table.
           (D) None of the above.

21. What is true about the following C functions?
           (A) Need not return any value.                           (B) Should always return an integer.
           (C) Should always return a float.                        (D) Should always return more than one value.

22. enum number { a=-1, b=4, c,d,e,} what is the value of e?
           (A) 7                                (B) 4                               (C) 5                               (D) 3

23. Which of the following about automatic variables within a function is correct?
           (A) Its type must be declared before using the variable.                   (B) They are local.
           (C) They are not initialized to zero.                                                 (D) They are global.

24. Consider the following program segment
                                  int n, sum=5;
                                  switch(n)
                                  {
                                      case 2:sum=sum-2;
                                      case 3:sum*=5;
                                      break;
                                      default:sum=0;
                                  }
    if n=2, what is the value of the sum?
           (A) 0                           (B) 15                           (C) 3                           (D) None of these.


25. Which of the following is not an infinite loop?                                                           
   (A) x=0;                                                                           (B) # define TRUE 0.... 
         do{                                                                                    While(TRUE){....}
                /*x unaltered within the loop*/                              (C) for(;;)   {....}
            ....}
          While(x==0);                                                             (D) While(1) {....}                  

26. Output of the following program is 
                                main()
                                {
                                    int i=0;
                                    for(i=0;i<20;i++)
                                    {
                                        switch(i){
                                                        case 0:
                                                            i+=5;
                                                        case 1:
                                                            i+=2;
                                                        case 5:
                                                            i+=5;
                                                        default:
                                                            i+=4;
                                                        break;
                                                    }
                                    }
                              } 
           (A) 5,9,13,17                   (B) 12,17,22                   (C) 16,21                   (D) syntax error.

27. What does the following function print?
                                func(int i)
                                {
                                    if(i%2) return 0;
                                    else return 1;
                                }
                                main()
                                {
                                    int i=3;
                                    i=func(i);
                                    i=func(i);
                                    printf("%d",i);
                                } 
           (A) 3                                (B) 1                                   (C) 0                               (D) 2

28. What will be the result of the following program?
                                char*g()
                                {
                                    static char x[1024];
                                    return x;
                                }
                                main()
                                {
                                    char*g1="First String";
                                    strcpy(g(),g1);
                                    g1=g();
                                    strcpy(g1,"Second String");
                                    printf("Answer is:%s", g());
                                }
           (A) Answer is: First String                           (B) Answer is: Second String
           (C) Run time Error/Core Dump                   (D) None of these

29. Consider the following program
                                main()
                                {
                                    int a[5]={1,3,6,7,0};
                                    int *b;
                                    b=&a[2];
                                }
      The value of b[-1] is
           (A) 1                               (B) 3                               (C) -6                               (D) none

30. Given a piece of code
                                int x[10];
                                int *ab;
                                ab=x;
      To access the 6th element of the array which of the following is incorrect?
           (A) *(x+5)                       (B) x[5]                       (C) ab[5]                       (D) *(*ab+5} .

 

 

 

 

 

 

Oracle2

    This is the oracle paper held on July 13 2003  at NITK Surathkal.

The test has 2 sections : 30 technical and 30 aptitude and 60 min time.

 

Technical section:

its very easy any one can answer 25 qns without preperation. some are

1. how compiler treats variables of recursive functions

2. what is orthogonal matrix?

3. given two tables and asked 2 qns on those table ,

  one is on join and another is on NOT IN

4. given some qns on pointers( pretty easy)

5. given five qns on data structures like , lifo, fifo

6. qtn on primary key

7. how NULL in sql is treated?

8. given a doubly linked list and asked r->left->right->data

   ans: r->data

9:explain const char *ptr and char *const ptr

remaining i didn`t remember

 

aptiude

15 quant apti from rs agrval

15 verbal apti,

in this 4 are odd word out

and 4 are sentese ordering when jumbled senteses given

and 4 are reasoning  

 

                         Model Questions From the Exam conducted by Oracle Bangalore in 2002.

1. What is the output of the following program?

 

#include

#include

 void main( )

{

 int a=5,b=7;

 printf(“%d\n”,b\a);

}

 

A. 1.4   B. 1.0  C. 1  D. 0

 

2. What is the output of the following program listing?

 

#include

void main ( )

{

 int x,y:

y=5;

x=func(y++);

printf(“%s\n”,

          (x==5)?”true”;”false”);

}

 

int func(int z)

{

 if (z== 6)

  return 5;

 else

  return 6;

}

 

A  True  B false  C either a or b   D neither a nor b

 

 

3. What is the output of the following progarm?

 

#include

main( )

{

 int x,y=10;

 x=4;

 y=fact(x);

 printf(“%d\n”,y);

}

 

unsigned int fact(int x)

{

return(x*fact(x-1));

}

A. 24   B. 10  C. 4   D. none

 

 

4. Consider the following C program and chose collect answer

 

#include

void main( )

{

 inta[10],k;

 for(k=0;k<10;k++)

{

     a[k]=k;

}

printf (“%d\n”,k);

}

 

A. value of k is undefined ; unpredictable answer

B. 10

C. program terminates with run time error

D. 0

 

5. Consider the prog and select answer

 

#include

void main ( )

{

 int k=4,j=0:

 switch (k)

 {

  case 3;       j=300;  

  case 4:      j=400:

  case 5:        j=500;

 }

printf (“%d\n”,j);

}

 

A. 300  B. 400 C. 500  D. 0

 

6. Consider the following statements:

Statement 1

A union is an object consisting of a sequence of named members of various types

Statement 2

A structure is a object that contains at different times, any one of the several members of various types

Statement 3

C is a compiled as well as an interpretted language

Statement 4

It is impossible to declare a structure or union containing an instance of itself

A. all the statements are correct

B. except 4 all are correct

C. statemnt 3 is only correct

D. statement 1,3 are incorrect either 2 or 4 is correct

 

7. consider the following program listing and select the output

 

#include

main ( )

{

int a=010,sum=0,tracker:

for(tracker=0;tracker<=a;tracker++)

 sum+=tracker;

printf(“ %d\n”,sum);

}

 

A. 55    B. 36     C. 28      D. n

 

8.Spot the line numbers , that are valid according to the ANSI C standards?

 

Line 1:  #include

Line 2: void main()

Line 3: {

4 : int *pia,ia;

5 :float *pafa,fa;

6 :ia=100;

7 :fa=12.05;

8 :*pfa=&ia;

9 :pfa=&ia;

10 :pia=pfa;

11 :fa=(float)*pia;

12 :fa=ia;

13 :}

 

a. 8 and 9   b. 9 and 10   c. 8 and 10  d. 10 and 11

 

8. What is the o/p of the follow pgm?

  #include

main()

{

char char_arr[5]=”ORACL”;

char c=’E’;

prinf(“%s\n”,strcat(char_arr,c));

}

 

a:oracle   b. oracl    c.e  d.none

 

9. consider the following pgm listing

 

  #include

main()

{

int a[3];

int *I;

a[0]=100;a[1]=200;a[2]=300;

I=a;

Printf(“%d\n”, ++*I);             

Printf(“%d\n”, *++I);             

 

Printf(“%d\n”, (*I)--);             

Printf(“%d\n”, *I);             

}

what is the o/p

 

a. 101,200,200,199   b. 200,201,201,100   c. 101,200,199,199   d. 200,300,200,100

 

10. which of the following correctly declares “My_var” as a pointer to a function that returns an integer

 

a. int*My_Var();      b. int*(My_Var()); c. int(*)My_Var();        d. int(*My_Var)();

 

11. what is the memory structure employed by recursive functions in a C pgm?

 

a. B tree    b. Hash table        c. Circular list          d. Stack

 

12. Consider the follow pgm listing?

 

Line 1: #include

        2: void main()

        3: {

        4: int a=1;

        5: const int c=2;

       6: const int *p1=&c;

       7: const int*p2=&a;

      8: int *p3=&c;

      9: int*p4=&a;

     10:}

 

what are the lines that cause compilation errors?

 

a.7    b.8      c.6 and 7         d.no errors

 

13. what will be the o/p

  #include

  main()

{   inta[3];        int *x; int*y;       a[0]=0;a[1]=1;a[2]=2;   x=a++;  y=a;

printf(“%d  %d\n”, x,(++y));   }

 

a. 0,1  b. 1,1  c. error  d. 1,2

 

what is the procedure for swapping a,b(assume that a,b and tmp are of the same type?

a. tmp=a; a=b;b=temp;        b. a=a+b;b=a-b;a=a-b;

c. a=a-b;b=a+b;a=b-a;          d. all of the above

 

 

 

1 comment:

  1. Good work! great job...

    But non equijoin definition is wrong..plz correct it and post again :)

    ReplyDelete