Commonly asked SQL and Plsql Questions

download Commonly asked SQL and Plsql Questions

of 32

Transcript of Commonly asked SQL and Plsql Questions

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    1/32

    LONG Data Types:

    Determine the length of a LONG field

    Retrieve the value of a LONG field

    String Data Types:

    Dealing with apostrophes/single quotes in strings

    Test a string for a numeric value

    Test a string for an alphabetic value

    Test a string for an alphanumeric value

    Sort a varchar2 field as a numeric field

    Extract arithmetic operators from a string

    Parse a string value and then return a substring

    Difference between an empty string and a null value

    Extract the directory path from a full file path

    Extract the filename (including suffix) from a full file path

    Extract the filename suffix from a full file path

    DATE Data Types:

    Insert a date/time value into an Oracle table

    Retrieve the total elapsed time in minutes between two dates

    Cursors:

    Cursor within a cursor

    http://www.techonthenet.com/oracle/questions/long_length.phphttp://www.techonthenet.com/oracle/questions/long_value.phphttp://www.techonthenet.com/oracle/questions/quotes.phphttp://www.techonthenet.com/oracle/questions/isnumeric.phphttp://www.techonthenet.com/oracle/questions/isalpha.phphttp://www.techonthenet.com/oracle/questions/isalphanumeric.phphttp://www.techonthenet.com/oracle/questions/sort1.phphttp://www.techonthenet.com/oracle/questions/operators.phphttp://www.techonthenet.com/oracle/questions/parse.phphttp://www.techonthenet.com/oracle/questions/empty_null.phphttp://www.techonthenet.com/oracle/questions/dir_path.phphttp://www.techonthenet.com/oracle/questions/filename.phphttp://www.techonthenet.com/oracle/questions/file_suffix.phphttp://www.techonthenet.com/oracle/questions/insert_date.phphttp://www.techonthenet.com/oracle/questions/elapsed_mins.phphttp://www.techonthenet.com/oracle/questions/cursor2.phphttp://www.techonthenet.com/oracle/questions/cursor2.phphttp://www.techonthenet.com/oracle/questions/elapsed_mins.phphttp://www.techonthenet.com/oracle/questions/insert_date.phphttp://www.techonthenet.com/oracle/questions/file_suffix.phphttp://www.techonthenet.com/oracle/questions/filename.phphttp://www.techonthenet.com/oracle/questions/dir_path.phphttp://www.techonthenet.com/oracle/questions/empty_null.phphttp://www.techonthenet.com/oracle/questions/parse.phphttp://www.techonthenet.com/oracle/questions/operators.phphttp://www.techonthenet.com/oracle/questions/sort1.phphttp://www.techonthenet.com/oracle/questions/isalphanumeric.phphttp://www.techonthenet.com/oracle/questions/isalpha.phphttp://www.techonthenet.com/oracle/questions/isnumeric.phphttp://www.techonthenet.com/oracle/questions/quotes.phphttp://www.techonthenet.com/oracle/questions/long_value.phphttp://www.techonthenet.com/oracle/questions/long_length.php
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    2/32

    Procedure that outputs a dynamic PLSQL cursor

    Cursor with variable in an "IN CLAUSE"

    Errors:

    ORA-04098 Error

    Avoid "data not found" error in PLSQL code

    Retrieve Top, Middle, or Bottom N records of a query:

    Retrieve Top N records from a query

    Retrieve Bottom N records from a query

    Retrieve Middle N records from a query

    Retrieve second highest value from a table

    Retrieve third highest value from a table

    Retrieve second lowest value from a table

    Retrieve third lowest value from a table

    SQLPlus:

    Execute an SQL script file in SQLPlus

    Prompt user for a parameter value in SQLPlus

    Miscellaneous:

    Format a number in Oracle

    Calculate the average between two dates

    Return error message when return datatype is set to NUMBER

    Rollback behavior and DDL's

    Function to return a monthly period

    Execute a function that is defined in a package

    http://www.techonthenet.com/oracle/questions/cursor1.phphttp://www.techonthenet.com/oracle/questions/cursor3.phphttp://www.techonthenet.com/oracle/questions/ora04098.phphttp://www.techonthenet.com/oracle/questions/no_data.phphttp://www.techonthenet.com/oracle/questions/top_records.phphttp://www.techonthenet.com/oracle/questions/bottom_records.phphttp://www.techonthenet.com/oracle/questions/middle_records.phphttp://www.techonthenet.com/oracle/questions/second_highest.phphttp://www.techonthenet.com/oracle/questions/third_highest.phphttp://www.techonthenet.com/oracle/questions/second_lowest.phphttp://www.techonthenet.com/oracle/questions/third_lowest.phphttp://www.techonthenet.com/oracle/questions/script.phphttp://www.techonthenet.com/oracle/questions/parameter.phphttp://www.techonthenet.com/oracle/questions/format_nbr.phphttp://www.techonthenet.com/oracle/questions/avg_date.phphttp://www.techonthenet.com/oracle/questions/return_nbr.phphttp://www.techonthenet.com/oracle/questions/rollback.phphttp://www.techonthenet.com/oracle/questions/periods.phphttp://www.techonthenet.com/oracle/questions/exec_function.phphttp://www.techonthenet.com/oracle/questions/exec_function.phphttp://www.techonthenet.com/oracle/questions/periods.phphttp://www.techonthenet.com/oracle/questions/rollback.phphttp://www.techonthenet.com/oracle/questions/return_nbr.phphttp://www.techonthenet.com/oracle/questions/avg_date.phphttp://www.techonthenet.com/oracle/questions/format_nbr.phphttp://www.techonthenet.com/oracle/questions/parameter.phphttp://www.techonthenet.com/oracle/questions/script.phphttp://www.techonthenet.com/oracle/questions/third_lowest.phphttp://www.techonthenet.com/oracle/questions/second_lowest.phphttp://www.techonthenet.com/oracle/questions/third_highest.phphttp://www.techonthenet.com/oracle/questions/second_highest.phphttp://www.techonthenet.com/oracle/questions/middle_records.phphttp://www.techonthenet.com/oracle/questions/bottom_records.phphttp://www.techonthenet.com/oracle/questions/top_records.phphttp://www.techonthenet.com/oracle/questions/no_data.phphttp://www.techonthenet.com/oracle/questions/ora04098.phphttp://www.techonthenet.com/oracle/questions/cursor3.phphttp://www.techonthenet.com/oracle/questions/cursor1.php
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    3/32

    Add days to a date (skipping Saturdays and Sundays)

    Retrieve Oracle version information

    Retrieve the name of the Oracle instance currently connected to

    Retrieve primary key information

    Retrieve the value that occurs most in a column

    GROUP BY Clause and sorting

    Insert multiple rows with a single INSERT statement

    1. Describe the difference between a procedure, function and anonymous pl/sql block.Level: Low

    Expected answer : Candidate should mention use of DECLARE statement, a function

    must return a value while a procedure doesn't have to.

    2. What is a mutating table error and how can you get around it?

    Level: Intermediate

    Expected answer: This happens with triggers. It occurs because the trigger is trying to

    update a row it is currently using. The usual fix involves either use of views or temporary

    tables so the database is selecting from one while updating the other.

    3. Describe the use of %ROWTYPE and %TYPE in PL/SQL

    Level: Low

    Expected answer: %ROWTYPE allows you to associate a variable with an entire table

    row.

    The %TYPE associates a variable with a single column type.

    4. What packages (if any) has Oracle provided for use by developers?

    Expected answer: Oracle provides the DBMS_ series of packages. There are many

    which developers should be aware of such as DBMS_SQL, DBMS_PIPE,

    DBMS_TRANSACTION,

    DBMS_LOCK, DBMS_ALERT, DBMS_OUTPUT, DBMS_JOB, DBMS_UTILITY, DBMS_DDL,

    UTL_FILE. If they can mention a few of these and describe how they used them, even

    better. If they include the SQL routines provided by Oracle, great, but not really what

    was asked.

    http://www.techonthenet.com/oracle/questions/add_days.phphttp://www.techonthenet.com/oracle/questions/version.phphttp://www.techonthenet.com/oracle/questions/instance.phphttp://www.techonthenet.com/oracle/questions/find_pkeys.phphttp://www.techonthenet.com/oracle/questions/most_common.phphttp://www.techonthenet.com/oracle/questions/group_order.phphttp://www.techonthenet.com/oracle/questions/insert_rows.phphttp://www.techonthenet.com/oracle/questions/insert_rows.phphttp://www.techonthenet.com/oracle/questions/group_order.phphttp://www.techonthenet.com/oracle/questions/most_common.phphttp://www.techonthenet.com/oracle/questions/find_pkeys.phphttp://www.techonthenet.com/oracle/questions/instance.phphttp://www.techonthenet.com/oracle/questions/version.phphttp://www.techonthenet.com/oracle/questions/add_days.php
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    4/32

    5. Describe the use of PL/SQL tables

    Expected answer: PL/SQL tables are scalar arrays that can be referenced by a

    binary integer. They can be used to hold values for use in later queries

    or calculations. In Oracle 8 they will be able to be of the %ROWTYPE designation, or

    RECORD.

    6. When is a declare statement needed ?

    The DECLARE statement is used in PL/SQL anonymous blocks such as with stand alone,

    non-stored PL/SQL procedures. It must come first in a PL/SQL stand alone file if it is

    used.

    7. In what order should a open/fetch/loop set of commands in a PL/SQL block be

    implemented if you use the NOTFOUND cursor variable in the exit when statement?

    Why?

    Expected answer: OPEN then FETCH then LOOP followed by the exit when. If not

    specified in this order will result in the final return being done twice because of the way

    the %NOTFOUND is handled by PL/SQL.

    8. What are SQLCODE and SQLERRM and why are they important for PL/SQL

    developers?

    Expected answer: SQLCODE returns the value of the error number for the last error

    encountered. The SQLERRM returns the actual error message for the last error

    encountered. They can be used in exception handling to report, or, store in an error log

    table, the error that occurred in the code. These are especially useful for the WHEN

    OTHERS exception.

    9. How can you find within a PL/SQL block, if a cursor is open?

    Expected answer: Use the %ISOPEN cursor status variable.

    10. How can you generate debugging output from PL/SQL?

    Expected answer: Use the DBMS_OUTPUT package. Another possible method is to just

    use the SHOW ERROR command, but this only shows errors. The DBMS_OUTPUT

    package can be used to show intermediate results from loops and the status of variables

    as the procedure is executed. The new package UTL_FILE can

    also be used.

    11. What are the types of triggers?

    Expected Answer: There are 12 types of triggers in PL/SQL that consist of

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    5/32

    combinations of the BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and

    ALL key words:

    BEFORE ALL ROW INSERT

    AFTER ALL ROW INSERT

    BEFORE INSERTAFTER INSERT etc.

    2. Q: What is PL/SQL?3.4. Q: Where can you store a PL/SQL procedure?5.6. Q: What is the PL/SQL body section?7.8. Q: What is the PL/SQL declaration section?9.10.Q: What does the SET SERVEROUTPUT command?11.12.Q: What does the DBMS_OUTPUT.PUT_LINE procedure?13.14.Q: How do you define a variable or variables in the PL/SQL declaration section?15.16.Q: How do you save a PL/SQL block in the client environment?17.18.Q: How do you use the %TYPE keyword?19.20.Q: How do you open a saved PL/SQL block?21.22.Q: How do you run a saved PL/SQL block?23.24.Q: What does the %ROWTYPE keyword in the PL/SQL language?25.26.Q: What is an implicit cursor in the PL/SQL language?27.28.Q: An implicit cursor must have _________ on its SELECT SQL statement?29.30.Q: What does the SQL%NOTFOUND reserved PL/SQL word?31.

    32.Q: What does the SET SERVEROUTPUT ON?33.34.Q: Write a PL/SQL block , to output the "Hello iSelfSchooling" message.35.36.Q: Use the %TYPE keyword, to declare a variable as the same datatype and size of the

    department name column of the dept table.

    37.

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    6/32

    38.Q: Use the implicit cursor to query the department table information where deptno is30. Check, if no record was found then print Record was not found. Else print the

    department name only.

    39.40.Explicit Cursor Handling41.Lesson 0242.Q: Describe that why do we need to use a solid naming convention in our PL/SQL

    program.

    43.44.Q: What is the explicit cursor in the PL/SQL language?45.46.Q: What are the differences between the explicit and implicit cursors?47.48.Q: Where do you declare an explicit cursor in the PL/SQL language?49.50.

    Q: Where do you declare an implicit cursor in the PL/SQL language?51.

    52.Q: What is a simple loop in the PL/SQL language?53.54.Q: How do you open an explicit cursor in the PL/SQL language?55.56.Q: What does the FETCH statement in the Oracle PL/SQL language?57.58.Q: How do you terminate from a simple loop in the PL/SQL language?59.60.Q: How do you OPEN or CLOSE a cursor in the PL/SQL language?61.62.Q: Declare a cursor to list the department name (dname), total number of employees

    (ttemp), total salary (ttsal), and average salary (avsal) for each department from the

    department table and employee table order by the department name.

    63.Write all department names with their total number of employees for each departmentusing the notepad editor.

    64.65.For example: ACCOUNTING has 3 employees.66.(Note: Dont use the ttemp, ttsal, and avsal item at this time)67.68.Controlling Process Flow69.Lesson 0370.Q: What does the FOR LOOP statement in the PL/SQL language?71.72.Q: What are the differences between a SIMPLE LOOP and FOR LOOP?73.74.Q: What are the advantages of using the FOR LOOP statement?

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson02.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson02.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson03.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson03.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson03.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson02.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    7/32

    75.76.Q: What does the SHOW ERRORS statement in the PL/SQL language?77.78.Q: What is the IF-THEN-ELSE statement?79.80.Q: Modify the previous PL/SQL block and use the FOR LOOP statement vs the simple

    LOOP statement. Also, list only the department name that their total number of

    employees is more than 4.

    81.82.Populating Table using PL/SQL83.Lesson 0484.Q: Create a table named "dept_stat". The table should have four columns:

    department name (dname), total number of employees (total_empno), total salary of

    employees (total_sal), and average salary of employees (avg_sal). And the department

    name should be a primary key. The following are its columns, datatypes and index

    constraint:85. dname VARCHAR2(20) primary key86. total_empno NUMBER(3)87. total_sal NUMBER (8,2)88. avg_sal NUMBER (8,2)89.90.Q: Write a PL/SQL block to populate the department table statistics into the

    dept_stat table.

    91.Statistics Information:92.The Department Number,93.The total number of employees in each department,94.The total salary paid in each department, and95.The average salary paid in each department.96.97.Cursor Parameter98.Lesson 0599.Q: What is the cursor parameter in the PL/SQL language?100. Q: Where do you define a cursor parameter in the PL/SQL language?101.102. Q: Write a PL/SQL block to populate the department table statistics into the

    dept_stat table for a specific department.103. Statistics Information:104. The Department Number,105. The total number of employees in each department,106. The total salary paid in each department, and107. The average salary paid in each department.108.

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson04.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson04.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson05.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson05.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson05.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson04.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    8/32

    109. EXCEPTION110. Lesson 06111. Q: What is the EXCEPTION section in the PL/SQL language?112.113. Q: What do you use the EXCEPTION section for?114.115. Q: What would be happen if you dont define your exception in the PL/SQL

    procedure?

    116.117. Q: What is an Oracle Defined EXCEPTION?118.119. Q: What is a User Defined EXCEPTION?120.121. Q: What are the differences between a User Defined and an Oracle defined

    exceptions?

    122.123. Q: Modify the previous PL/SQL block --last assignment in the previous hands-on

    practice--to add a user defined exception, to check the total number of employees in a

    department. Check if the total number of employees less than 10 then the procedure

    raises an exception and print a messageWe need more good employees.

    124.125. Create PL/SQL to populate table using Notepad126. Lesson 07127. Q: How do you write a PL/SQL language using NOTEPAD?128.129. Q: Create a table to keep your customers portfolio statistics and name it

    CUST_STAT. You should populate into this table a customer last name, his/her traded

    date, and total stock market value for the traded date.

    130. See the following columns and datatypes:131. customer_lname VARCHAR2(20)132. trade_date DATE133. portfolio_value NUMBER(8,2)134.135. Q: Write a stored procedure to populate the customer statistics table. Declare a

    cursor to query all the customer last names, the traded date, and the total stock market

    value for the traded date. Use a sub-query with a MAX (trade_date) function to

    guarantee the current stock market value for the traded date. In the PL/SQL body, usethe FOR LOOP statement to read the cursor information one record at a time. Then

    insert the summary statistics data into the customer statistics table. Use commit to

    save the transaction. In the exception section, add the no data found exception and

    use the dbms_output package to display the error message. Add the invalid number

    exception to detect any invalid input data into the insert command. Add the Others

    exception to detect other problems. Always use the others exception in case you miss

    some other exceptions.

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson06.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson07.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson07.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson06.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    9/32

    136.137. Q: Then run your created procedure.138.139. Q: Verify that your table was populated.140.141. Create PL/SQL to add department row using procedure builder142. Lesson 08143. Q: What is the Procedure Builder Tool?144.145. Q: What is the listener in the Oracle database?146.147. Q: How do you start or stop your listener?148.149. Q: What is the Object Navigator in the Procedure Builder tool?150.151.

    Q: How to you open a database using the Procedure Builder tool?152.

    153. Q: What is a users schema?154.155. Q: What type of objects can you have under a schema?156.157. Q: How do you create a procedure using the Procedure Builder Tool?158.159. Q: What is a Program Unit?160.161. Q: Write a PL/SQL stored procedure to add a record into the department table

    (dept). You use three input parameters to pass the department's columns (Departmentnumber DEPTNO, department name DNAME, and department location LOC); and

    use one output parameter to check the status of the insert transaction. You should use

    the Procedure Builder.

    162.163. Note that you should use the "p_" prefix to name the parameters. You use this

    parameter as an output parameter to check the status of your transaction. Use

    comments in your programs. Use double dashes for a single line comment. In addition,

    use /* ended with */ for a multiple lines comment. In the EXCEPITON section,

    define the exception. Use the duplicate value on index exception, the invalid

    number exception, and the OTHERS exception. Use the others in case you are missingother exceptions.

    164.165. Q: Write a stored procedure to test the add_department procedure. Declare a

    status variable and make sure to call the add_department procedure. Enter an invalid

    department number to see the exception error message. To display the status of your

    transaction value, use the TEXT_IO instead of the DBMS_OUTPUT, when you run the

    procedure locally.

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson08.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson08.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    10/32

    166.167. Q: What is the client side environment?168.169. Q: What is the server side environment?170.171. Q: How do you save the above PL/SQL procedure in your local library?172.173. Create PL/SQL to remove department row174. Lesson 09175. Q: Write a procedure to remove a department record. Make sure to define one

    input parameter for the department number; and an output parameter as a status

    parameter. You will use this parameter to test the status of the deleted transaction.

    176.177. In the PL/SQL body, delete the department record where its department number

    matches with the input department number parameter. Save the deleted transaction

    and assign "OK" to the status output parameter for a successful deleted transaction.178.179. Q: Write a PL/SQL procedure to test the above-created PL/SQL procedure.180.181. Q: What does the TEXT_IO package?182.183. Q: Name one procedure that is in the TEXT_IO package.184.185. Q: What are the differences between the TEXT_IO and DBMS_OUTPUT

    packages?

    186.187. Create PL/SQL to concatenate customers name188. Lesson 10189. Q: What is the PL/SQL function?190.191. Q: What are the differences between the PL/SQL function and procedure?192.193. Q: When do you create the PL/SQL function?194.195. Q: write a PL/SQL Function to concatenate the customer's last name and first

    name to be separated by a comma. For example: Kazerooni, John. Name the function

    "Full_Name, and declare a datatype for the Function return value. Declare a first nameand last name input parameters. Their datatypes should match with the datatype of the

    firstname and lastname in the customers table.

    196.197. In the PL/SQL body, return the customers concatenated name. Write the

    exception. In the exception section, do nothing in the case of an error handling

    exception.

    198.

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson09.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson10.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson10.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson09.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    11/32

    199. Q: How do you execute the above-created PL/SQL function in the SQLPLUStool?

    200.201. Q: What is the PL/SQL interpreter?202.203. Q: How do you execute a PL/SQL procedure in the PL/SQL interpreter?204.

    All progress is precarious, and the solution of one problem brings us face to

    face with another problem.

    Martin Luther King Jr., 'Strength to Love,' 1963

    205. Create PL/SQL to return department name206. Lesson 11207. Q: Write a PL/SQL Function to return the department name (dname). You use

    one input parameter to pass the department number (DEPTNO) and return its

    department name.

    208.

    209. Q: In the PL/SQL interpreter section, use the select statement and use thedepartment number 10 to test the function.

    210.211. Q: To test the exception, call the function again using the department number

    that does not exist in the department table.

    212.213. Q: Query the department name function against the employee table sorted by

    the employee name.

    214.The good neighbor looks beyond the external accidents and discerns those

    inner qualities that make all men human and, therefore, brothers.Martin Luther King Jr., 'Strength to Love,' 1963

    215. Debugging PL/SQL Stored Procedure216. Lesson 12217. Q: How do you debug a PL/SQL procedure?218.219. Q: How do you move a PL/SQL procedure to the PL/SQL interpreters source

    area?

    220.221. Q: What is the BREAKPOINT indicator in the PL/SQL interpreter?222.223. Q: How do you create a BREAKPOINT in the PL/SQL interpreter?224.225. Q: How do you activate the Step Into, Step Out, and Reset icon in the PL/SQL

    interpreter?

    226.227. Q: What does the Step Into icon in the PL/SQL interpreter?228.

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson11.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson12.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson12.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson11.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    12/32

    229. Q: What does the Step Out icon in the PL/SQL interpreter?230.231. Q: What does the Reset icon in the PL/SQL interpreter?232.233. Q: What does the STACK section contain?234.235. Q: How can you see the columns and variables values in the PL/SQL program

    using the PL/SQL interpreter?

    236.237. Q: How do you store a PL/SQL procedure in the PL/SQL library?238.239. Q: Can you have multiple versions of a PL/SQL procedure in the PL/SQL library?240.241. Q: How do you store a PL/SQL procedure in your database server?242.243. Q: How can you copy a PL/SQL procedure to your database server?244.245. Q: What would be happen if you move or copy a locally PL/SQL procedure with

    its local packages into the database server?

    246.247. Granting Object privileges248. Lesson 13249. Q: What is an Object Privilege?250.251. Q: What are System Privileges?252.253. Q: How do you create a user in the Oracle database?254.255. Q: How do you assign a default and temporary tablespace to a user in the

    Oracle database?

    256.257. Q: What are the System Privileges in the RESOURCE and CONNECT roles?258.259. Q: How do you grant an object privilege to a user?260.261. Q: How do you grant a system privilege to a user?262.263. Q: What is the Public Synonym in the Oracle database?264.265. Q: How do you create a PUBLIC SYNONYM?266.267. Q: Why do you need a PUBLIC SYNONYM?268.269. Q: What is the EXECUTE privilege? Is it a system privilege or an object privilege?

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson13.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson13.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    13/32

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    14/32

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    15/32

    350.351. Using the DBMS_DDL package352. Lesson 17353. Q: How do you increase the size of SERVEROUTPUT buffer?354.355. Q: Can you perform a DDL statement in the PL/SQL block?356.357. Q: How can you compile an object in a PL/SQL block?358.359. Q: What does the DBMS_DDL package?360.361. Q: What does the ANALZE_OBJECT procedure in the DBMS_DDL package and

    how can you verify that the object was ANALYZED?

    362.363. Q: What does the ALTER_COMPILE procedure in the DBMS_DDL package and

    how can you verify that the object was compiled?364.365. Using Native Dynamic SQL366. Lesson 18367. Q: What is a Native Dynamic SQL statement?368.369. Q: Write a stored procedure to pass the table name and get back the number of

    records that table contains. The SELECT statement must be created dynamically, since

    you dont know what table you are getting statistics from. You should write your

    function so that your client can display the tables name, plus the number of records

    contained each table.

    370.371. Calling JAVA Stream in Oracle372. Lesson 19373. Q: How do you check that you have the JAVA tool installed in your server?374.375. Q: What should it be at least size for the JAVA pool memory usage?376.377. Q: How do you create a JAVA class?378.379. Q: How do you publish a JAVA class?380.381. Q: How do you test a JAVA function?382.383. Q: How do you drop a JAVA source and Function?384.385. Inserting employees picture into the EMP table using BLOB386. Lesson 20

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson17.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson18.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson19.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson20.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson20.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson19.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson18.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson17.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    16/32

    387. Q: How do you add a column to a table?388.389. Q: What does the EMPTY_BLOB() function?390.391. Q: How do you create a directory in the Oracle database?392.393. Q: Does everyone can create a directory in the Oracle database?394.395. Q: Write a stored procedure to read the employee number and its photo file

    name and then store the employees picture into the EMP table.

    396.397. Q: How do you test that there is a picture in a column?398.399. Q: What does the DBMS_LOB package?400.401. Q: What does the GETLENGTH() function in the DBMS_LOB package?402.403. Q: How do you drop a directory from your Oracle database?404.405. Q: How and when do you grant the CREATE ANY DIRECTORY privilege to a user?406.407. Q: How do you revoke the CREATE ANY DIRECTORY privilege from a user?408.409. In General:410. Lesson 21411. Q: Describe the command line technique.412.413. Q: How do you use the define_editor command?414.415. Q: How many categories of PL/SQL blocks are there?416.417. Q: What is an anonymous block?418.419. Q: What is a named block?420.421. Q: What does a PL/SQL block contain?422.423. Q: What is the EXCEPTION section in the PL/SQL block?424.425. Q: What are the differences between an implicit cursor and explicit cursor?426.427. Q: How do you obtain data from a cursor?428.429. Q: What is a LOOP in the PL/SQL block and how many types are there?

    http://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson21.htmlhttp://www.iselfschooling.com/Free_Oracle_Training/01_Basics/02_PLSQL/lesson21.html
  • 8/13/2019 Commonly asked SQL and Plsql Questions

    17/32

    430.431. Q: What is advantage of the FOR LOOP statement verses of the simple LOOP

    statement?

    432.433. Q: How do you pass a parameter to a PL/SQL procedure or function?434.435. Q: What does the procedure builder tool?436.437. Q: Describe the server-side and client-side machine.438.439. Q: What is the Breakpoint in the Oracle Procedure builder tool?440.441. Q: What is the DBA_DEPENDENCIES dictionary view?442.443. Q: What is a PL/SQL package?444.445. Q: What is a package specification?446.447. Q: What is a package body?448.449. Q: What is a public and private procedure in the PL/SQL package?450.451. Q: In what sequence do you compile a package body and specification?452.453. Q: What is a database trigger?454.455. Q: What are the differences between the statement and row triggers in the

    Oracle database?

    456.457. Q: What do the UPDATING, DELETING, or INSERTING keywords?458.459. Q: How do you enable, disable, and drop a trigger in the Oracle database?460.461. What are the various types of queries ?

    Answer: The types of queries are:

    Normal Queries

    Sub QueriesCo-related queries

    Nested queries

    Compound queries

    462. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    18/32

    463. What is a transaction ?Answer: A transaction is a set of SQL statements between any two COMMIT and

    ROLLBACK statements.

    464. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is implicit cursor and how is it used by Oracle ?Answer: An implicit cursor is a cursor which is internally created by Oracle.It is created

    by Oracle for each individual SQL.

    465. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Which of the following is not a schema object : Indexes, tables, public synonyms,

    triggers and packages ?

    Answer: Public synonyms

    466. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is PL/SQL?

    Answer: PL/SQL is Oracle's Procedural Language extension to SQL.The language includes

    object oriented programming techniques such as encapsulation, function overloading,

    information hiding (all but inheritance), and so, brings state-of-the-art programming to

    the Oracle database server and a variety of Oracle tools.

    467. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Is there a PL/SQL Engine in SQL*Plus?

    Answer: No.Unlike Oracle Forms, SQL*Plus does not have a PL/SQL engine.Thus, all your

    PL/SQL are send directly to the database engine for execution.This makes it much more

    efficient as SQL statements are not stripped off and send to the database individually.

    468. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    469. Is there a limit on the size of a PL/SQL block?Answer: Currently, the maximum parsed/compiled size of a PL/SQL block is 64K and the

    maximum code size is 100K.You can run the following select statement to query the size

    of an existing package or procedure. SQL> select * from dba_object_size where name =

    'procedure_name'

    470.471. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can one read/write files from PL/SQL?Answer: Included in Oracle 7.3 is a UTL_FILE package that can read and write files.The

    directory you intend writing to has to be in your INIT.ORA file (see

    UTL_FILE_DIR=...parameter).

    472. Before Oracle 7.3 the only means of writing a file was to use DBMS_OUTPUTwith the SQL*Plus SPOOL command.

    DECLARE

    fileHandler UTL_FILE.FILE_TYPE;

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    19/32

    BEGIN

    fileHandler := UTL_FILE.FOPEN('/home/oracle/tmp', 'myoutput','W');

    UTL_FILE.PUTF(fileHandler, 'Value of func1 is %sn', func1(1));

    UTL_FILE.FCLOSE(fileHandler);

    END;

    473. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    474. How can I protect my PL/SQL source code?Answer: PL/SQL V2.2, available with Oracle7.2, implements a binary wrapper for PL/SQL

    programs to protect the source code.This is done via a standalone utility that transforms

    the PL/SQL source code into portable binary object code (somewhat larger than the

    original).This way you can distribute software without having to worry about exposing

    your proprietary algorithms and methods.SQL*Plus and SQL*DBA will still understand

    and know how to execute such scripts.Just be careful, there is no "decode" command

    available. The syntax is: wrap name=myscript.sql

    475. oname=xxxx.yyy476. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can one use dynamic SQL within PL/SQL? OR Can you use a DDL in a procedure ? How ?

    Answer: From PL/SQL V2.1 one can use the DBMS_SQL package to execute dynamic SQL

    statements.

    Eg: CREATE OR REPLACE PROCEDURE DYNSQL AS

    cur integer;

    rc integer;

    BEGIN

    cur := DBMS_SQL.OPEN_CURSOR;

    DBMS_SQL.PARSE(cur,'CREATE TABLE X (Y DATE)',477. DBMS_SQL.NATIVE);

    rc := DBMS_SQL.EXECUTE(cur);

    DBMS_SQL.CLOSE_CURSOR(cur);

    END;

    478. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    479. What are the various types of Exceptions ?Answer: User defined and Predefined Exceptions.

    480. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Can we define exceptions twice in same block ?

    Answer: No.

    481. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the difference between a procedure and a function ?

    Answer: Functions return a single variable by value whereas procedures do not return

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    20/32

    any variable by value.Rather they return multiple variables by passing variables by

    reference through their OUT parameter.

    482. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you have two functions with the same name in a PL/SQL block ?

    Answer: Yes.483. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can you have two stored functions with the same name ?

    Answer: Yes.

    484. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you call a stored function in the constraint of a table ?

    Answer: No.

    485. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the various types of parameter modes in a procedure ?

    Answer: IN, OUT AND INOUT.

    486. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is Over Loading and what are its restrictions ?

    Answer: OverLoading means an object performing different functions depending upon

    the no.of parameters or the data type of the parameters passed to it.

    487. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can functions be overloaded ?

    Answer: Yes.488. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can 2 functions have same name & input parameters but differ only by return datatype

    Answer: No.

    489. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    490. What are the constructs of a procedure, function or a package ?Answer: The constructs of a procedure, function or a package are :

    491. variables and constantscursorsexceptions

    492. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    493. Why Create or Replace and not Drop and recreate procedures ?Answer: So that Grants are not dropped.

    494. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    21/32

    Can you pass parameters in packages ? How ?

    Answer: Yes.You can pass parameters to procedures or functions in a package.

    495. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the parts of a database trigger ?

    Answer: The parts of a trigger are:496. A triggering event or statement

    A trigger restriction

    A trigger action

    497. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    498. What are the various types of database triggers ?Answer: There are 12 types of triggers, they are combination of :

    499. Insert, Delete and Update Triggers.Before and After Triggers.

    Row and Statement Triggers.

    500. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    501. What is the advantage of a stored procedure over a database trigger ?Answer: We have control over the firing of a stored procedure but we have no control

    over the firing of a trigger.

    502. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the maximum no.of statements that can be specified in a trigger statement ?

    Answer: One.

    503. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Can views be specified in a trigger statement ?

    Answer: No

    504. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the values of :new and :old in Insert/Delete/Update Triggers ?

    Answer: INSERT : new = new value, old = NULL

    DELETE : new = NULL, old = old value

    UPDATE : new = new value, old = old value

    505. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    506. What are cascading triggers? What is the maximum no of cascading triggers at atime?

    Answer: When a statement in a trigger body causes another trigger to be fired, the

    triggers are said to be cascading.Max = 32.

    507. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    22/32

    What are mutating triggers ?

    Answer: A trigger giving a SELECT on the table on which the trigger is written.

    508. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are constraining triggers ?

    Answer: A trigger giving an Insert/Updat e on a table having referential integrityconstraint on the triggering table.

    509. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    510. Describe Oracle database's physical and logical structure ?Answer:

    511. Physical : Data files, Redo Log files, Control file.Logical : Tables, Views, Tablespaces, etc.

    512.513. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    514. Can you increase the size of a tablespace ? How ?Answer: Yes, by adding datafiles to it.

    515. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you increase the size of datafiles ? How ?

    Answer: No (for Oracle 7.0)

    Yes (for Oracle 7.3 by using the Resize clause )

    516. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the use of Control files ?

    Answer: Contains pointers to locations of various data files, redo log files, etc.517. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    What is the use of Data Dictionary ?

    Answer: It Used by Oracle to store information about various physical and logical Oracle

    structures e.g.Tables, Tablespaces, datafiles, etc

    518. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the advantages of clusters ?

    Answer: Access time reduced for joins.

    519.

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the disadvantages of clusters ?

    Answer: The time for Insert increases.

    520. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can Long/Long RAW be clustered ?

    Answer: No.

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    23/32

    521. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can null keys be entered in cluster index, normal index ?

    Answer: Yes.

    522. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Can Check constraint be used for self referential integrity ? How ?

    Answer: Yes.In the CHECK condition for a column of a table, we can reference some

    other column of the same table and thus enforce self referential integrity.

    523. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the min.extents allocated to a rollback extent ?

    Answer: Two

    524. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the states of a rollback segment ? What is the difference between partly

    available and needs recovery ?

    Answer: The various states of a rollback segment are :

    525. ONLINEOFFLINE

    PARTLY AVAILABLE

    NEEDS RECOVERY

    INVALID.

    526. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    527. What is the difference between unique key and primary key ?Answer: Unique key can be null; Primary key cannot be null.

    528. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    An insert statement followed by a create table statement followed by rollback ? Will the

    rows be inserted ?

    Answer: No.

    529. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you define multiple savepoints ?

    Answer: Yes.

    530.

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you Rollback to any savepoint ?

    Answer: Yes.

    531. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the maximum no.of columns a table can have ?

    Answer: 254.

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    24/32

    532. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the significance of the & and && operators in PL SQL ?

    Answer: The & operator means that the PL SQL block requires user input for a

    variable.The && operator means that the value of this variable should be the same as

    inputted by the user previously for this same variable533. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can you pass a parameter to a cursor ?

    Answer: Explicit cursors can take parameters, as the example below shows.A cursor

    parameter can appear in a query wherever a constant can appear.

    534. CURSOR c1 (median IN NUMBER) ISSELECT job, ename FROM emp WHERE sal > median;

    535. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    536. What are the various types of RollBack Segments ?Answer: The types of Rollback sagments are as follows :

    537. Public Available to all instancesPrivate Available to specific instance

    538. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    539. Can you use %RowCount as a parameter to a cursor ?Answer: Yes

    540. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Is the query below allowed :

    Select sal, ename Into x From emp Where ename = 'KING' (Where x is a record ofNumber(4) and Char(15))

    Answer: Yes

    541. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Is the assignment given below allowed :

    ABC = PQR (Where ABC and PQR are records)

    Answer: Yes

    542. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Is this for loop allowed : For x in &Start..&End LoopAnswer: Yes

    543. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    How many rows will the following SQL return : Select * from emp Where rownum < 10;

    Answer: 9 rows

    544. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    25/32

    How many rows will the following SQL return : Select * from emp Where rownum = 10;

    Answer: No rows

    545. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Which symbol preceeds the path to the table in the remote database ?

    Answer: @546. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Are views automatically updated when base tables are updated ?

    Answer: Yes

    547. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can a trigger written for a view ?

    Answer: No

    548. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    If all the values from a cursor have been fetched and another fetch is issued, the output

    will be : error, last record or first record ?

    Answer: Last Record

    549. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    A table has the following data : [[5, Null, 10]].What will the average function return ?

    Answer: 7.5

    550. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Is Sysdate a system variable or a system function?

    Answer: System Function551. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    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 an rollback and

    again issue a nextval.What will the output be ?

    Answer: 3

    552. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Definition of relational DataBase by Dr.Codd (IBM)?

    Answer: A Relational Database is a database where all data visible to the user isorganized strictly as tables of data values and where all database operations work on

    these tables.

    553. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is Multi Threaded Server (MTA) ?

    Answer: In a Single Threaded Architecture (or a dedicated server configuration) the

    database manager creates a separate process for each database user.But in MTA the

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    26/32

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    27/32

    564. Cannot drop a fieldCannot rename a field

    Cannot manage memory

    Procedural Language option not provided

    Index on view or index on index not provided

    View updation problem565. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    566. When to create indexes ?Answer: To be created when table is queried for less than 2% or 4% to 25% of the table

    rows.

    567. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    How can you avoid indexes ?

    Answer: To make index access path unavailable Use FULL hint to optimizer for full table

    scan Use INDEX or AND-EQUAL hint to optimizer to use one index or set to indexes

    instead of another. Use an expression in the Where Clause of the SQL.

    568. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    569. What is the result of the following SQL : Select 1 from dual UNION Select 'A' fromdual;

    Answer: Error

    570. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    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.

    Answer: Yes, database trigger would fire.571. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    Can you alter synonym of view or view ?

    Answer: No

    572. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can you create index on view

    Answer: No.

    573. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------What is the difference between a view and a synonym ?

    Answer: Synonym is just a second name of table used for multiple link of database.View

    can be created with many tables, and with virtual columns and with conditions.But

    synonym can be on view.

    574. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    28/32

    575.What's the length of SQL integer ?

    Answer: 32 bit length

    576. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is the difference between foreign key and reference key ?Answer: Foreign key is the key i.e.attribute which refers to another table primary key.

    Reference key is the primary key of table referred by another table.

    577. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can dual table be deleted, dropped or altered or updated or inserted ?

    Answer: Yes

    578. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    If content of dual is updated to some value computation takes place or not ?

    Answer: Yes

    579. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    If any other table same as dual is created would it act similar to dual?

    Answer: Yes

    580. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    For which relational operators in where clause, index is not used ?

    Answer: , like '%...' is NOT functions, field +constant, field||''

    581. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Assume that there are multiple databases running on one machine.How can you switchfrom one to another ?

    Answer: Changing the ORACLE_SID

    582. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are the advantages of Oracle ?

    Answer: Portability : Oracle is ported to more platforms than any of its competitors,

    running on more than 100 hardware platforms and 20 networking protocols. Market

    Presence : Oracle is by far the largest RDBMS vendor and spends more on R & D than

    most of its competitors earn in total revenue.This market clout means that you are

    unlikely to be left in the lurch by Oracle and there are always lots of third partyinterfaces available. Backup and Recovery : Oracle provides industrial strength support

    for on-line backup and recovery and good software fault tolerence to disk failure.You

    can also do point-in-time recovery. Performance : Speed of a 'tuned' Oracle Database

    and application is quite good, even with large databases.Oracle can manage > 100GB

    databases. Multiple database support : Oracle has a superior ability to manage multiple

    databases within the same transaction using a two-phase commit protocol.

    583.

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    29/32

    584. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What is a forward declaration ? What is its use ?

    Answer: PL/SQL requires that you declare an identifier before using it.Therefore, you

    must declare a subprogram before calling it.This declaration at the start of a

    subprogram is called forward declaration.A forward declaration consists of asubprogram specification terminated by a semicolon.

    585. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    What are actual and formal parameters ?

    Answer: Actual Parameters : Subprograms pass information using parameters.The

    variables or expressions referenced in the parameter list of a subprogram call are actual

    parameters.For example, the following procedure call lists two actual parameters

    named emp_num and amount:

    Eg.raise_salary(emp_num, amount);Formal Parameters : The variables declared in a

    subprogram specification and referenced in the subprogram body are formal

    parameters.For example, the following procedure declares two formal parameters

    named emp_id and increase:

    Eg.PROCEDURE raise_salary (emp_id INTEGER, increase REAL) IS current_salary REAL;

    586. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    587. What are the types of Notation ?588. Answer: Position, Named, Mixed and Restrictions.589. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    What all important parameters of the init.ora are supposed to be increased if you wantto increase the SGA size ?

    Answer: In our case, db_block_buffers was changed from 60 to 1000 (std values are 60,

    550 & 3500) shared_pool_size was changed from 3.5MB to 9MB (std values are 3.5, 5 &

    9MB) open_cursors was changed from 200 to 300 (std values are 200 & 300)

    db_block_size was changed from 2048 (2K) to 4096 (4K) {at the time of database

    creation}. The initial SGA was around 4MB when the server RAM was 32MB and The

    new SGA was around 13MB when the server RAM was increased to 128MB.

    590. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    If I have an execute privilege on a procedure in another users schema, can I execute his

    procedure even though I do not have privileges on the tables within the procedure ?

    Answer: Yes

    591. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    30/32

    What are various types of joins ?

    Answer: Types of joins are:

    592. EquijoinsNon-equijoins

    self join

    outer join593. -----------------------------------------------------------------------------------------------------------

    -------------------------------------------------------------------------------------------------

    594. What is a package cursor ?Answer: A package cursor is a cursor which you declare in the package specification

    without an SQL statement.The SQL statement for the cursor is attached dynamically at

    runtime from calling procedures.

    595. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    596. If you insert a row in a table, then create another table and then say Rollback.Inthis case will the row be inserted ?

    Answer: Yes.Because Create table is a DDL which commits automatically as soon as it is

    executed.The DDL commits the transaction even if the create statement fails internally

    (eg table already exists error) and not syntactically.

    597.598. How do you convert a date to a string?599. What is an aggregate function?600. What is the dual table?601. What are cursors? Distinguish between implicit and explict cursors?602. Explain how cursors are used by Oracle?603. What is PL/SQL? Describe the block structure of PL/SQL?604. What is a nested subquery?605. What are the various types of queries ?606. Which of the following is not a schema object : Index, table, public synonym,

    trigger and package ?

    607. What is dynamic sql in oracle?608. What is the difference between delete, drop and truncating a table?609. How many triggers are supported in Oracle?610. Are you aware of FLASHBACK concept ? What is it?611. Describe oracles logical and physical structure?612. What is data dictionary?613.

    What is the use of control files?

    614. How would store XML data in table ? What data type would be used for thecolumns?

    615. Difference between post and commit?616. Difference between commit and rollback?617. What are savepoints?618. Difference between a View and Synonym.619. How would you fetch system date from oracle?

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    31/32

    620. What is the difference between primary key, unique key, foreign key?621. What is the difference between NO DATA FOUND and %NOTFOUND?622. What is cursor for loop?623. What are cursor attributes?624. What will you use in Query : IN or EXISTS? Why?625. Explain the difference between a data block, an extent and a segment.626. What's the difference between logical and physical I/O?627. What is an anonymous block?628. What is a PL/SQL collection?629. How can you tell if an UPDATE updated no rows?630. How can you tell if a SELECT returned no rows?631. What are the different types of joins?632. What is the difference between procedure and function?633. What is group by function634. What is the difference between a where clause and having clause635. What are indexes. Advantages of indexes636. What does i represent in Oracle8i / 9i637. Difference between primary key and foreign key638. Can we have null in a primary key?639. Can we have null in a foreign key, if yes , how many in a table?640. Give example of how SQL tuning can be done?641. What is normalization?642. Difference between delete and truncate?643. Are you aware of water level mark in oracle database? What is it?644. What are views, snapshots and synonyms?645. What value one gets for Select * from dual646. Have you used Decode function? Give an example647. Example when inner joins was used?648. Example when outer joins was used?649. Datatypes supported by Oracle650. Can you explain how do index retrieve records from database651. What is commit and rollback652. What is the difference between these 2 queries 1.Select count(*) from table and

    2.Select count(1) from table.

    653. What is referential integrity?654. What are constraints?655.

    What are transaction isolation levels?

    656. What are materialized views?657. What is DDL, DML ? How are they different?658. How do you select unique rows using SQL?659. What is the difference between DELETE and TRUNCATE ?660. What is the difference between a "where" clause and a "having" clause?661. What is the difference between "translate" and "replace" ?662. How to remove duplicate records from a table?

  • 8/13/2019 Commonly asked SQL and Plsql Questions

    32/32

    663. What is a "trigger"?664. What is the difference between "translate" and "replace"?665. What is a VIEW?666. What is the difference among "dropping a table", "truncating a table" and

    "deleting all records" from a table

    667. Explain new feature of 9i Database ? Explain new feature of 10g Database ?668. How to use DECODE function?669. What is Group by clause?670. What are cursors and what are the situations you will use them?671. What default packages are provided by Oracle?672. How do you debug a oracle procedure /function?673. How many triggers are available?674. How are procedures executed?