like

Sunday, August 28, 2016

ORACLE Interview

1.What is SQL?
SQL stands for 'Structured Query Language'.
2.What is SELECT statement?
The SELECT statement lets you select a set of values from a table in a database. The values selected from the database table would depend on the various conditions that are specified in the SQL query.
3.How can you compare a part of the name rather than the entire name?
SELECT * FROM people WHERE empname LIKE '%ab%'
Would return a recordset with records consisting empname the sequence 'ab' in empname .
4.What is the INSERT statement?
The INSERT statement lets you insert information into a database.
5.How do you delete a record from a database?
Use the DELETE statement to remove records or any particular column values from a database.
6.How could I get distinct entries from a table?
The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query. Example
SELECT DISTINCT empname FROM emptable
7.How to get the results of a Query sorted in any order?
You can sort the results and return the sorted results to your program by using ORDER BY keyword thus saving you the pain of carrying out the sorting yourself. The ORDER BY keyword is used for sorting.

SELECT empname, age, city FROM emptable ORDER BY empname
8.How can I find the total number of records in a table?
You could use the COUNT keyword , example
SELECT COUNT(*) FROM emp WHERE age>40
9.What is GROUP BY?
The GROUP BY keywords have been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible.
10.What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a table.
Dropping :  (Table structure  + Data are deleted), Invalidates the dependent objects ,Drops the indexes
Truncating:  (Data alone deleted), Performs an automatic commit, Faster than delete
Delete : (Data alone deleted), Doesn?t perform automatic commit
What are the Large object types suported by Oracle?
Blob and Clob.
11.Difference between a "where" clause and a "having" clause.
Having clause is used only with group functions whereas Where is not used with.
12.What's the difference between a primary key and a unique key?
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.
13.What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?
Cursors allow row-by-row prcessing of the resultsets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
Most of the times, set based operations can be used instead of cursors.
14.What are triggers? How to invoke a trigger on demand?
Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table.
Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.
Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster.
15.What is a join and explain different types of joins.
Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.
16.What is a self join?
Self join is just like any other join, except that two instances of the same table will be joined in the query.
1.      Explain the difference between a hot backup and a cold backup and the benefits associated with each. - A hot backup is basically taking a backup of the database while it is still up and running and it must be in archive log mode. A cold backup is taking a backup of the database while it is shut down and does not require being in archive log mode. The benefit of taking a hot backup is that the database is still available for use while the backup is occurring and you can recover the database to any point in time. The benefit of taking a cold backup is that it is typically easier to administer the backup and recovery process. In addition, since you are taking cold backups the database does not require being in archive log mode and thus there will be a slight performance gain as the database is not cutting archive logs to disk.
2.      You have just had to restore from backup and do not have any control files. How would you go about bringing up this database? - I would create a text based backup control file, stipulating where on disk all the data files where and then issue the recover command with the using backup control file clause.
3.      How do you switch from an init.ora file to a spfile? - Issue the create spfile from pfile command.
4.      Explain the difference between a data block, an extent and a segment. - A data block is the smallest unit of logical storage for a database object. As objects grow they take chunks of additional storage that are composed of contiguous data blocks. These groupings of contiguous data blocks are called extents. All the extents that an object takes when grouped together are considered the segment of the database object.
5.      Give two examples of how you might determine the structure of the table DEPT. - Use the describe command or use the dbms_metadata.get_ddl package.
6.      Where would you look for errors from the database engine? - In the alert log.
7.      Compare and contrast TRUNCATE and DELETE for a table. - Both the truncate and delete command have the desired outcome of getting rid of all the rows in a table. The difference between the two is that the truncate command is a DDL operation and just moves the high water mark and produces a now rollback. The delete command, on the other hand, is a DML operation, which will produce a rollback and thus take longer to complete.
8.      Give the reasoning behind using an index. - Faster access to data blocks in a table.
9.      Give the two types of tables involved in producing a star schema and the type of data they hold. - Fact tables and dimension tables. A fact table contains measurements while dimension tables will contain data that will help describe the fact tables.
10.  What type of index should you use on a fact table? - A Bitmap index.
11.  Give two examples of referential integrity constraints. - A primary key and a foreign key.
12.  A table is classified as a parent table and you want to drop and re-create it. How would you do this without affecting the children tables? - Disable the foreign key constraint to the parent, drop the table, re-create the table, enable the foreign key constraint.
13.  Explain the difference between ARCHIVELOG mode and NOARCHIVELOG mode and the benefits and disadvantages to each. - ARCHIVELOG mode is a mode that you can put the database in for creating a backup of all transactions that have occurred in the database so that you can recover to any point in time. NOARCHIVELOG mode is basically the absence of ARCHIVELOG mode and has the disadvantage of not being able to recover to any point in time. NOARCHIVELOG mode does have the advantage of not having to write transactions to an archive log and thus increases the performance of the database slightly.
14.  What command would you use to create a backup control file? - Alter database backup control file to trace.
15.  Give the stages of instance startup to a usable state where normal users may access it. - STARTUP NOMOUNT - Instance startup. STARTUP MOUNT - The database is mounted. STARTUP OPEN - The database is opened
16.  What column differentiates the V$ views to the GV$ views and how? - The INST_ID column which indicates the instance in a RAC environment the information came from.
17.  How would you go about generating an EXPLAIN plan? - Create a plan table with utlxplan.sql. Use the explain plan set statement_id = ‘tst1′ into plan_table for a SQL statement. Look at the explain plan with utlxplp.sql or utlxpls.sql
18.  How would you go about increasing the buffer cache hit ratio? - Use the buffer cache advisory over a given workload and then query the v$db_cache_advice table. If a change was necessary then I would use the alter system set db_cache_size command.
19.  Explain an ORA-01555 - You get this error when you get a snapshot too old within rollback. It can usually be solved by increasing the undo retention or increasing the size of rollbacks. You should also look at the logic involved in the application getting the error message.
20.  Explain the difference between $ORACLE_HOME and $ORACLE_BASE. - ORACLE_BASE is the root directory for oracle. ORACLE_HOME located beneath ORACLE_BASE is where the oracle products reside.
21.  What’s the command to see the current user name? Sql> show user;
22.  What’s the command to change the SQL prompt name?
SQL> set sqlprompt “database-1 > ”
database-1 >
database-1 >
23.  How do I eliminate duplicate rows in an Oracle database?
SQL> delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
or
SQL> delete duplicate_values_field_name dv from table_name ta where rowid < (select min(rowid) from table_name tb where ta.dv=tb.dv);
24.  How do I display row number with records? Use the row-num pseudocolumn with query, like
SQL> select rownum, ename from emp;
25.  How do you display the records within a given range?
select rownum, empno, ename from emp where rowid in
(select rowid from emp where rownum < =&rangeend
minus
select rowid from emp where rownum<&rangebegin);
26.  The NVL function only allows the same data type. But here’s the task: if the commission field is null, then the text “Not Applicable” should be displayed, instead of blank space. How do you write the query?
SQL> select nvl(to_char(comm.),’Not Applicable’) from emp;
27.  Explain explicit cursor attributes. There are four cursor attributes used in Oracle: cursor_name%Found, cursor_name%NOTFOUND, cursor_name%ROWCOUNT, cursor_name%ISOPEN
28.  Explain implicit cursor attributes. Same as explicit cursor but prefixed by the word SQL: SQL%Found, SQL%NOTFOUND, SQL%ROWCOUNT, SQL%ISOPEN
29.  How do you view version information in Oracle?
SQL> select banner from $version;
   10.  How do you switch to DOS prompt from SQL prompt? SQL> host
1.      Which of the following statements is true about implicit cursors?
1.      Implicit cursors are used for SQL statements that are not named.
2.      Developers should use implicit cursors with great care.
3.      Implicit cursors are used in cursor for loops to handle data processing.
4.      Implicit cursors are no longer a feature in Oracle.

2.      Which of the following is not a feature of a cursor FOR loop?
1.      Record type declaration.
2.      Opening and parsing of SQL statements.
3.      Fetches records from cursor.
4.      Requires exit condition to be defined.
3.      A developer would like to use referential datatype declaration on a variable. The variable name is EMPLOYEE_LASTNAME, and the corresponding table and column is EMPLOYEE, and LNAME, respectively. How would the developer define this variable using referential datatypes?
1.      Use employee.lname%type.
2.      Use employee.lname%rowtype.
3.      Look up datatype for EMPLOYEE column on LASTNAME table and use that.
4.      Declare it to be type LONG.
4.      Which three of the following are implicit cursor attributes?
1.      %found
2.      %too_many_rows
3.      %notfound
4.      %rowcount
5.      %rowtype
5.      If left out, which of the following would cause an infinite loop to occur in a simple loop?
1.      LOOP
2.      END LOOP
3.      IF-THEN
4.      EXIT
6.      Which line in the following statement will produce an error?
1.      cursor action_cursor is
2.      select name, rate, action
3.      into action_record
4.      from action_table;
5.      There are no errors in this statement.
7.      The command used to open a CURSOR FOR loop is
1.      open
2.      fetch
3.      parse
4.      None, cursor for loops handle cursor opening implicitly.
8.      What happens when rows are found using a FETCH statement
1.      It causes the cursor to close
2.      It causes the cursor to open
3.      It loads the current row values into variables
4.      It creates the variables to hold the current row values
9.      Read the following code:
10.  CREATE OR REPLACE PROCEDURE find_cpt
11.  (v_movie_id {Argument Mode} NUMBER, v_cost_per_ticket {argument mode} NUMBER)
12.  IS
13.  BEGIN
14.    IF v_cost_per_ticket  > 8.5 THEN
15.  SELECT  cost_per_ticket
16.  INTO            v_cost_per_ticket
17.  FROM            gross_receipt
18.  WHERE   movie_id = v_movie_id;
19.    END IF;
20.  END;
Which mode should be used for V_COST_PER_TICKET?
1.      IN
2.      OUT
3.      RETURN
4.      IN OUT
21.  Read the following code:
22.  CREATE OR REPLACE TRIGGER update_show_gross
23.        {trigger information}
24.       BEGIN
25.        {additional code}
26.       END;
The trigger code should only execute when the column, COST_PER_TICKET, is greater than $3. Which trigger information will you add?
1.      WHEN (new.cost_per_ticket > 3.75)
2.      WHEN (:new.cost_per_ticket > 3.75
3.      WHERE (new.cost_per_ticket > 3.75)
4.      WHERE (:new.cost_per_ticket > 3.75)
27.  What is the maximum number of handlers processed before the PL/SQL block is exited when an exception occurs?
1.      Only one
2.      All that apply
3.      All referenced
4.      None
28.  For which trigger timing can you reference the NEW and OLD qualifiers?
1.      Statement and Row
2.      Statement only
3.      Row only
4.      Oracle Forms trigger
29.  Read the following code:
30.  CREATE OR REPLACE FUNCTION get_budget(v_studio_id IN NUMBER)
31.  RETURN number IS
32.     
33.  v_yearly_budget NUMBER;
34.     
35.  BEGIN
36.         SELECT  yearly_budget
37.         INTO            v_yearly_budget
38.         FROM            studio
39.         WHERE   id = v_studio_id;
40.     
41.         RETURN v_yearly_budget;
42.  END;
Which set of statements will successfully invoke this function within SQL*Plus?
1.      VARIABLE g_yearly_budget NUMBER
EXECUTE g_yearly_budget := GET_BUDGET(11);
2.      VARIABLE g_yearly_budget NUMBER
EXECUTE :g_yearly_budget := GET_BUDGET(11);
3.      VARIABLE :g_yearly_budget NUMBER
EXECUTE :g_yearly_budget := GET_BUDGET(11);
4.      VARIABLE g_yearly_budget NUMBER
:g_yearly_budget := GET_BUDGET(11);
43.  CREATE OR REPLACE PROCEDURE update_theater
44.  (v_name IN VARCHAR v_theater_id IN NUMBER) IS
45.  BEGIN
46.         UPDATE  theater
47.         SET             name = v_name
48.         WHERE   id = v_theater_id;
49.  END update_theater;
50.  When invoking this procedure, you encounter the error:
ORA-000: Unique constraint(SCOTT.THEATER_NAME_UK) violated.
How should you modify the function to handle this error?
1.      An user defined exception must be declared and associated with the error code and handled in the EXCEPTION section.
2.      Handle the error in EXCEPTION section by referencing the error code directly.
3.      Handle the error in the EXCEPTION section by referencing the UNIQUE_ERROR predefined exception.
4.      Check for success by checking the value of SQL%FOUND immediately after the UPDATE statement.
51.  Read the following code:
52.  CREATE OR REPLACE PROCEDURE calculate_budget IS
53.  v_budget        studio.yearly_budget%TYPE;
54.  BEGIN
55.         v_budget := get_budget(11);
56.         IF v_budget < 30000
57.                     THEN
58.                 set_budget(11,30000000);
59.         END IF;
60.  END;
You are about to add an argument to CALCULATE_BUDGET. What effect will this have?
1.      The GET_BUDGET function will be marked invalid and must be recompiled before the next execution.
2.      The SET_BUDGET function will be marked invalid and must be recompiled before the next execution.
3.      Only the CALCULATE_BUDGET procedure needs to be recompiled.
4.      All three procedures are marked invalid and must be recompiled.
61.  Which procedure can be used to create a customized error message?
1.      RAISE_ERROR
2.      SQLERRM
3.      RAISE_APPLICATION_ERROR
4.      RAISE_SERVER_ERROR
62.  The CHECK_THEATER trigger of the THEATER table has been disabled. Which command can you issue to enable this trigger?
1.      ALTER TRIGGER check_theater ENABLE;
2.      ENABLE TRIGGER check_theater;
3.      ALTER TABLE check_theater ENABLE check_theater;
4.      ENABLE check_theater;
63.  Examine this database trigger
64.  CREATE OR REPLACE TRIGGER prevent_gross_modification
65.  {additional trigger information}
66.  BEGIN
67.         IF TO_CHAR(sysdate, DY) = MON
68.     THEN
   RAISE_APPLICATION_ERROR(-20000,Gross receipts cannot be deleted on
 Monday);
       END IF;
END;
This trigger must fire before each DELETE of the GROSS_RECEIPT table. It should fire only once for the entire DELETE statement. What additional information must you add?
1.      BEFORE DELETE ON gross_receipt
2.      AFTER DELETE ON gross_receipt
3.      BEFORE (gross_receipt DELETE)
4.      FOR EACH ROW DELETED FROM gross_receipt
69.  Examine this function:
70.  CREATE OR REPLACE FUNCTION set_budget
71.  (v_studio_id IN NUMBER, v_new_budget IN NUMBER) IS
72.  BEGIN
73.         UPDATE  studio
74.         SET             yearly_budget = v_new_budget
75.         WHERE   id = v_studio_id;
76.     
77.         IF SQL%FOUND THEN
78.                 RETURN TRUEl;
79.         ELSE
80.                 RETURN FALSE;
81.         END IF;
82.     
83.         COMMIT;
84.  END;
Which code must be added to successfully compile this function?
1.      Add RETURN right before the IS keyword.
2.      Add RETURN number right before the IS keyword.
3.      Add RETURN boolean right after the IS keyword.
4.      Add RETURN boolean right before the IS keyword.
85.  Under which circumstance must you recompile the package body after recompiling the package specification?
1.      Altering the argument list of one of the package constructs
2.      Any change made to one of the package constructs
3.      Any SQL statement change made to one of the package constructs
4.      Removing a local variable from the DECLARE section of one of the package constructs
86.  Procedure and Functions are explicitly executed. This is different from a database trigger. When is a database trigger executed?
1.      When the transaction is committed
2.      During the data manipulation statement
3.      When an Oracle supplied package references the trigger
4.      During a data manipulation statement and when the transaction is committed
87.  Which Oracle supplied package can you use to output values and messages from database triggers, stored procedures and functions within SQL*Plus?
1.      DBMS_DISPLAY
2.      DBMS_OUTPUT
3.      DBMS_LIST
4.      DBMS_DESCRIBE
88.  What occurs if a procedure or function terminates with failure without being handled?
1.      Any DML statements issued by the construct are still pending and can be committed or rolled back.
2.      Any DML statements issued by the construct are committed
3.      Unless a GOTO statement is used to continue processing within the BEGIN section, the construct terminates.
4.      The construct rolls back any DML statements issued and returns the unhandled exception to the calling environment.
89.  Examine this code
90.  BEGIN
91.         theater_pck.v_total_seats_sold_overall := theater_pck.get_total_for_year;
92.  END;
For this code to be successful, what must be true?
1.      Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist only in the body of the THEATER_PCK package.
2.      Only the GET_TOTAL_FOR_YEAR variable must exist in the specification of the THEATER_PCK package.
3.      Only the V_TOTAL_SEATS_SOLD_OVERALL variable must exist in the specification of the THEATER_PCK package.
4.      Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist in the specification of the THEATER_PCK package.
93.  A stored function must return a value based on conditions that are determined at runtime. Therefore, the SELECT statement cannot be hard-coded and must be created dynamically when the function is executed. Which Oracle supplied package will enable this feature?
1.      DBMS_DDL
2.      DBMS_DML
3.      DBMS_SYN
4.      DBMS_SQL


No comments:

Post a Comment