SQL Interview
SQL Interview
SQL Interview
31. Which function is used to find the largest integer less than or equal to a specific value?
FLOOR.
32. Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Data Definition Language (DDL).
33. What is the use of DESC in SQL?
DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.
Explanation :
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order.
34. What command is used to create a table by copying the structure of another table?
CREATE TABLE .. AS SELECT command
Explanation:
To copy only the structure, the WHERE clause of the SELECT command should contain a FALSE statement as in the
following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.
35. TRUNCATE TABLE EMP;DELETE FROM EMP;
Will the outputs of the above two commands differ?
Both will result in deleting all the rows in the table EMP..
36. What is the output of the following query SELECT TRUNC(1234.5678,-2) FROM DUAL;?
1200.
37. What are the wildcards used for pattern matching.?
_ for single character substitution and % for multi-character substitution.
38. What is the parameter substitution symbol used with INSERT INTO command?
&
39. What's an SQL injection?
SQL Injection is when form data contains an SQL escape sequence and injects a new SQL query to be run.
40. What is difference between TRUNCATE & DELETE
TRUNCATE commits after deleting entire table i.e., cannot be rolled back. Database triggers do not fire on
TRUNCATE
DELETE allows the filtered deletion. Deleted records can be rolled back or committed. Database triggers fire on
DELETE.
41. What is a join? Explain the different types of joins?
Join is a query, which retrieves related columns or rows from multiple tables.
Self Join - Joining the table with itself.
Equi Join - Joining two tables by equating two common columns.
Non-Equi Join - Joining two tables by equating two common columns.
Outer Join - Joining two tables in such a way that query can also retrieve rows that do not have corresponding join
value in the other table.
42. What is the sub-query?
Sub-query is a query whose return values are used in filtering conditions of the main query.
43. What is correlated sub-query?
Correlated sub-query is a sub-query, which has reference to the main query.
44. Explain CONNECT BY PRIOR?
Retrieves rows in hierarchical order eg.
The integrity constraints can be enabled or disabled by ALTER TABLE ENABLE CONSTRAINT / DISABLE CONSTRAINT.
59. If unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE?
It won't, Because SYSDATE format contains time attached with it.
60. What is a database link?
Database link is a named path through which a remote database can be accessed.
61. How to access the current value and next value from a sequence? Is it possible to access the current value in a
session before accessing next value?
Sequence name CURRVAL, sequence name NEXTVAL. It is not possible. Only if you access next value in the session,
current value can be accessed.
62.What is CYCLE/NO CYCLE in a Sequence?
CYCLE specifies that the sequence continue to generate values after reaching either maximum or minimum value.
After pan-ascending sequence reaches its maximum value, it generates its minimum value. After a descending
sequence reaches its minimum, it generates its maximum.
NO CYCLE specifies that the sequence cannot generate more values after reaching its maximum or minimum value.
63. What are the advantages of VIEW?
- To protect some of the columns of a table from other users.
- To hide complexity of a query.
- To hide complexity of calculations.
64. Can a view be updated/inserted/deleted? If Yes - under what conditions?
A View can be updated/deleted/inserted if it has only one base table if the view is based on columns from one or
more tables then insert, update and delete is not possible.
65. If a view on a single base table is manipulated will the changes be reflected on the base table?
If changes are made to the tables and these tables are the base tables of a view, then the changes will be
reference on the view.
66. 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.
67. 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.
66. 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.
67. Which three of the following are implicit cursor attributes?
1. %found
2. %too_many_rows
3. %notfound
4. %rowcount
5. %rowtype
68. 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
69. 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.
70. 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.
71. 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
72. 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
73. 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)
74. 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
77. 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
78. Read the following code:
CREATE OR REPLACE FUNCTION get_budget(v_studio_id IN NUMBER)
RETURN number IS
v_yearly_budget NUMBER;
BEGIN
SELECT yearly_budget
INTO v_yearly_budget
FROM studio
WHERE id = v_studio_id;
RETURN v_yearly_budget;
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
31. CREATE OR REPLACE PROCEDURE update_theater
32. (v_name IN VARCHAR v_theater_id IN NUMBER) IS
33. BEGIN
34. UPDATE theater
35. SET name = v_name
36. WHERE id = v_theater_id;
37. END update_theater;
79. 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.
80. Read the following code:
40. CREATE OR REPLACE PROCEDURE calculate_budget IS
41. v_budget studio.yearly_budget%TYPE;
42. BEGIN
43. v_budget := get_budget(11);
44. IF v_budget < 30000
45. THEN
46. set_budget(11,30000000);
47. END IF;
48. 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.
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
combinations of the BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and
ALL key words:
BEFORE ALL ROW INSERT
AFTER ALL ROW INSERT
BEFORE INSERT
AFTER INSERT etc.
SQL / SQLPlus Interview Questions
1. How can variables be passed to a SQL routine?
Expected answer: By use of the & symbol. For passing in variables the numbers
1-8 can be used (&1, &2,...,&8) to pass the values after the command into the
SQLPLUS session. To be prompted for a specific variable, place the ampersanded
variable in the code itself:
"select * from dba_tables where owner=&owner_name;" . Use of double
ampersands tells SQLPLUS to resubstitute the value for each subsequent
use of the variable, a single ampersand will cause a reprompt for the
value unless an ACCEPT statement is used to get the value from the user.
2. You want to include a carriage return/linefeed in your output from a SQL script, how can you do this?
Expected answer: The best method is to use the CHR() function (CHR(10) is a return/linefeed) and the
concatenation function "". Another method, although it is hard to document and isn?t always portable is to use the
return/linefeed as a part of a quoted string.
3. How can you call a PL/SQL procedure from SQL?
Expected answer: By use of the EXECUTE (short form EXEC) command.
4. How do you execute a host operating system command from within SQL?
Expected answer: By use of the exclamation point "!" (in UNIX and some other OS) or the HOST (HO) command.
5. You want to use SQL to build SQL, what is this called and give an example
Expected answer: This is called dynamic SQL. An example would be:
set lines 90 pages 0 termout off feedback off verify off
spool drop_all.sql
select ?drop user ?username? cascade;? from dba_users
where username not in ("SYS?,?SYSTEM?);
spool off
Essentially you are looking to see that they know to include a command (in this case DROP USER...CASCADE;) and
that you need to concatenate using the ?? the values selected from the database.
6. What SQLPlus command is used to format output from a select?
Expected answer: This is best done with the COLUMN command.
7. You want to group the following set of select returns, what can you group on?
Max(sum_of_cost), min(sum_of_cost), count(item_no), item_no
Expected answer: The only column that can be grouped on is the "item_no" column, the rest have aggregate
functions associated with them.
8. What special Oracle feature allows you to specify how the cost based system treats a SQL statement?
Level: Intermediate to high Expected answer: The COST based system allows the use of HINTs to control the
optimizer path selection. If they can give some example hints such as FIRST ROWS, ALL ROWS, USING INDEX, STAR,
even better.
9. You want to determine the location of identical rows in a table before attempting to place a unique index on
the table, how can this be done?
Level: High Expected answer: Oracle tables always have one guaranteed unique column, the rowid column. If you
use a min/max function against your rowid and then select against the proposed primary key you can squeeze out
the rowids of the duplicate rows pretty quick. For example: select rowid from emp e where e.rowid > (select
min(x.rowid) from emp x where x.emp_no = e.emp_no); In the situation where multiple columns make up the
proposed key, they must all be used in the where clause.
10. What is a Cartesian product?
Expected answer: A Cartesian product is the result of an unrestricted join of two or more tables. The result set of
a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows
in each table involved in the join.
11. You are joining a local and a remote table, the network manager complains about the traffic involved, how can
you reduce the network traffic?
Level: High Expected answer: Push the processing of the remote data to the remote instance by using a view to
pre-select the information for the join. This will result in only the data required for the join being sent across.
12. What is the default ordering of an ORDER BY clause in a SELECT statement?
Expected answer: Ascending
13. What is tkprof and how is it used?
Level: Intermediate to high Expected answer: The tkprof tool is a tuning tool used to determine cpu and execution
times for SQL statements. You use it by first setting timed_statistics to true in the initialization file and then
turning on tracing for either the entire database via the sql_trace parameter or for the session using the ALTER
SESSION command. Once the trace file is generated you run the tkprof tool against the trace file and then look at
the output from the tkprof tool. This can also be used to generate explain plan output.
14. What is explain plan and how is it used?
Level: Intermediate to high Expected answer: The EXPLAIN PLAN command is a tool to tune SQL statements. To use
it you must have an explain_table generated in the user you are running the explain plan for. This is created using
the utlxplan.sql script. Once the explain plan table exists you run the explain plan command giving as its argument
the SQL statement to be explained. The explain_plan table is then queried to see the execution plan of the
statement. Explain plans can also be run using tkprof.
15. How do you set the number of lines on a page of output? The width?
Level: Low Expected answer: The SET command in SQLPLUS is used to control the number of lines generated per
page and the width of those lines, for example SET PAGESIZE 60 LINESIZE 80 will generate reports that are 60 lines
long with a line width of 80 characters. The PAGESIZE and LINESIZE options can be shortened to PAGES and LINES.
16. How do you prevent output from coming to the screen?
Level: Low
Expected answer: The SET option TERMOUT controls output to the screen. Setting TERMOUT OFF turns
off screen output. This option can be shortened to TERM.
17. How do you prevent Oracle from giving you informational messages during and after a SQL statement
execution?
Level: Low Expected answer: The SET options FEEDBACK and VERIFY can be set to OFF.
Application/menu
Enter the following details
o Menu: sunil_menu
o User menu name: sunil menu
o Seq: 1
o Prompt: sunil form
o Function: SUNIL_FUNCT( previously deined)
o SAVE
Attach MENU to RESPONSIBILITY
Attach RESPONSIBILITY to USER
Login as the new USER
See the form
Posted by Sunil Dutt at 3:03 AM 7 comments: Links to this post
TRIGGERS
TRIGGERS
EITHER OR
IDENTIFIES THE DML THAT CAUSES THE TRIGGER TO FIRE.
EITHER ,, OR ALL OF THE THREE.
NAME OF THE TABLE ASSOCIATED WITH THE TRIGGER.
EXPLAINS ABOUT THE ACTIONS PERFORMED.
IT BEGINS WITH A DECALERE AND END OR A CALL OF PROCEDURE.
USING COLUMNS NAMES WITH UPDATE TRIGGERS INCREASE THE PERFORMANCE BECAUSE THE TRIGGER IS FIRED
ONLY WHEN THE UPDATION OF CONCERNED COLUMN OCCURS.IT IS NO WHERE CONCERNNED WITH THE UPDATION OF
ANY OTHER COLUMNS OF THE DESCRIBED TABLE IN THE TRIGGER.
EXAMPLE:
IN THE DESCRIBED TRIGGER WHICH IMPLEMENTS THE BUSSINESS RULES THAT RESTRICTS THE ACCESS OF DATABASE
TABLE AFTER THE OFFICE HOURS AND HOLIDAYS PROVIDED THE WORK DAY CALENDER IS 5 DAYS A WEEK.
CREATE OR REPLACE TRIGGER SECURE_EMPLOYEES
BEFORE INSERT OR DELETE OR UPDATE ON EMPLOYEES
BEGIN
IF (TO_CHAR (SYSDATE,DY) IN (SAT,SUN)) OR
(TO_CHAR (SYSDATE,HH24) NOT BETWEEN 08 AND 18)
THEN
IF INSERTING THEN
RAISE_APPLICATION_ERROR (-20500,UR STATEMENT);
ELSIF DELETING THEN
RAISE_APPLICATION_ERROR (-20500,UR STATEMENT);
ELSIF UPDATING THEN
RAISE_APPLICATION_ERROR (-20500,UR STATEMENT);
ELSE
RAISE_APPLICATION_ERROR (-20500,UR SATAMENT2);
END IF;
END IF;
END;
DML ROW TRIGGERS
WE HAVE TO SPECIFY A SPECIAL PHRASE FOR INITIATING A ROW TRIGGER.REFERENING TO THE ABOVE MENTIONED
SYNTAX OF TRIGGER AFTER THE TABLE NAME FOR EACH ROW PHRASE IF SPECIFIED INDICATES THE TRIGGER TO BE
A ROW TRIGGER.HERE THE NEW VALUES AND THE OLD VALUES ARE ALSO REFERED FOR CORELATION BETWEEN THE
OLD VALUES AND NEW VALUES.
WE CAN ALSO RESTRICT THE FIRING OF A ROW TRIGGER BY SPECIFING A WHEN CLAUSE AFTER THE PHRASE
MENTIONED ABOVE.
EXAMPLE
CREATE OR REPLACE TRIGGER RESTRICT_SALARY
BEFORE INSERT OR UPDATE OF SALARY ON EMPLOYEES
FOR EACH ROW
BEGIN
IF NOT (:NEW.JOB_ID IN (AD_PRES,AD_VP))
AND (:NEW.SALARY) > 15000
THEN
RAISE_APPLICATION_ERROR (-20500, )
END IF;
END;
EXPALAINATION
FOR AN UPDATE OR INSERT UPON EMPLOYEES TABLE IF THE JOB_ID SPECIED IS OTHER THAN AD_PRES AND AD_VP
AND SALARY SPECIFIED IS GREATER THAN 15000 IN THE CASE TRIGGER IS FIRED.IN STRAIGHT EAPLAINTION THE
EMPLOYEES WHICH HAVE A JOB_ID OF AD_PRES AND AD_VP CAN ONLY EARN A SALARY GREATER THAN 15000.
RESTRICTING A ROW TRIGGER
CREATE OR REPLACE TRIGGER RESTRICT_SALARY
BEFORE INSERT OR UPDATE OF SALARY ON EMPLOYEES
FOR EACH ROW
WHEN (NEW.JOB_ID = SA_REP)
BEGIN
IF INSERTING THEN
: NEW .COMMISSION_PCT:= 0;
ELSIF (:OLD.COMMISSION_PCT) IS NULL THEN
: NEW.COMMISSION_PCT:= 0;
ELSE
: NEW.COMMISSION_PCT:=:OLD.COMMISSION_PCT + 0.05;
END IF;
END;
EXPLAINATION
IF AN INSERT OPERATION IS OPERATED UPON THE EMPLOYEES TABLE WITH A JOB_ID SPECIFIED AS SA_REP AND
COMMISSION_PCT WITH SOME VALUE THEN THE TRIGGER RESTRICT_SALARY WILL FIRE CAUSING A INSERTION OF
ZERO IN COMMISION_PCT IN THE TABLE. (PLEASE NOTE LINE NO 7).OTHER WISE IF THE JOB IS OTHER THAN SA_REP
THEN ROW IS FULLY INSERTED AS DESIRED.
IF AN UPDATE OPERATION IS OPERATED UPON THE TABLE THERE ARE TWO CASES TO BE NOTICED.
1) IF THE OLD VALUE OF COMMISSION_PCT IS A NULL THEN WHILE UPDATION OF SALARY RESTRICT_SALARY WILL FIRE
AND THE COMMISSION_PCT WILL BE ASSIGNED A VALUE OF ZERO.(PLEASE SEE LINE NO 9)
2) IF THE OLD VALUE OF COMMISSION_PCT IS NOT NULL THEN RAISE_SALARY WILL FIRE AND NEW VALUE WILL BE
WHAT EVER VALUE THAT HAS BEEN SPECIFIED IN THE ACTION.(PLEASE SEE LINE NO 11)
INSTEAD OF TRIGGERS
IF THE MODIFICATION IS REQUIERD TO BE DONE ON THE DATA OWNED BY AN UNUPDATEABLE VIEW I.E (A VIEW
CONTAINING THE SET OPERATORS, DISTINCT CLAUSE, GROUP FUNCTIONS, OR JOINS BECOMES AN UNUPDATEABLE
VIEW) THEN THE INSTEAD OF TRIGGERS ARE USED WHICH ARE FIRED BY THE ORACLE SERVER WITHOUT EXECUTING
THE TRIGGERING STATEMENT OPERATING THE DML UPON THE UNDERLYING TABLES SPECIFIED.
CREATE OR REPLACE TRIGGER
INSTEAD OF
OR OR
ON VIEW_NAME
FOR EACH ROW
IF THE VIEW IS UPDATEABLE AND CONTAINS THE INSTEAD OF TRIGGERS THEN THESE TRIGGERS TAKE PRECEDENCE.
ALSO THE CHECK OPTIONS ARE NOT TAKEN CARE OF AT THE TIME OF FIRING OF INSTEAD OF TRIGGERS.RATHER IF
WANTED THEY MUST BE SPECIFIED IN THE BODY OF INSTEAD OF TRIGGER.
SEE FOR MORE DETAILS ORACLE HAND BOOK
MANAGING TRIGGERS
PARALLEL WITH THE BASE TABLES THE SNAPSHOT SHOULD BE REFRESHED REGULARLY.
BENEFITS OF DATABASE TRIGGERS
IT PROVIDES US THE IMPROVED DATA SECURITY
IT ALSO FACILIATES IMPROVED DATA INTEGRITY.
THANK YOU
THIS DATA DOES NOT MAKE YOU MASTER IN TRIGGERS.THERE ARE SO MANY CONCEPTS I JUST TRIED MY LEVEL BEST
TO CONCENTRATE ON BASICS
Posted by Sunil Dutt at 9:35 AM 1 comment: Links to this post
FA_INV_INTERFACE TABLE
FA_PRODUCTION_INTERFACE TABLE
FA_TAX_INTERFACE TABLE
INVENTORY INTERFACE TABLES
TNAME TABTYPE
------------------------------ ------- -----------------------------------MTL_CC_ENTRIES_INTERFACE TABLE
MTL_CC_INTERFACE_ERRORS TABLE
MTL_CI_INTERFACE TABLE
MTL_CI_XREFS_INTERFACE TABLE
MTL_COPY_ORG_INTERFACE TABLE
MTL_CROSS_REFERENCES_INTERFACE TABLE
MTL_DEMAND_INTERFACE TABLE
MTL_DESC_ELEM_VAL_INTERFACE TABLE
MTL_EAM_ASSET_NUM_INTERFACE TABLE
MTL_EAM_ATTR_VAL_INTERFACE TABLE
MTL_INTERFACE_ERRORS TABLE
TNAME TABTYPE
------------------------------ ------- -------------------------------------MTL_INTERFACE_PROC_CONTROLS TABLE
MTL_ITEM_CATEGORIES_INTERFACE TABLE
MTL_ITEM_CHILD_INFO_INTERFACE TABLE
MTL_ITEM_REVISIONS_INTERFACE TABLE
MTL_ITEM_SUB_INVS_INTERFACE TABLE
MTL_OBJECT_GENEALOGY_INTERFACE TABLE
MTL_RELATED_ITEMS_INTERFACE TABLE
MTL_RESERVATIONS_INTERFACE TABLE
MTL_RTG_ITEM_REVS_INTERFACE TABLE
MTL_SECONDARY_LOCS_INTERFACE TABLE
MTL_SERIAL_NUMBERS_INTERFACE TABLE
TNAME TABTYPE
------------------------------ ------- -----------------------------------MTL_SO_RMA_INTERFACE TABLE
MTL_SYSTEM_ITEMS_INTERFACE TABLE
MTL_TRANSACTIONS_INTERFACE TABLE
MTL_TRANSACTION_LOTS_INTERFACE TABLE
MTL_TXN_COST_DET_INTERFACE TABLE
PO INTERFACE TABLES
TNAME TABTYPE
------------------------------ ------- ------------------------PO_DISTRIBUTIONS_INTERFACE TABLE
PO_HEADERS_INTERFACE TABLE
PO_INTERFACE_ERRORS TABLE
PO_LINES_INTERFACE TABLE
PO_REQUISITIONS_INTERFACE_ALL TABLE
PO_REQ_DIST_INTERFACE_ALL TABLE
PO_RESCHEDULE_INTERFACE TABLE
RCV_HEADERS_INTERFACE TABLE
RCV_LOTS_INTERFACE TABLE
RCV_SERIALS_INTERFACE TABLE
RCV_TRANSACTIONS_INTERFACE TABLE
GL interface Diagram
Trigger Solutions
END;
Problems (For DDL Triggers):
Q.1 Create a DDL trigger to prevent removal of any table under scott schema.
ANS. CREATE OR REPLACE TRIGGER Drop_Check_For_Scott
BEFORE DROP ON scott.SCHEMA
BEGIN
RAISE_APPLICATION_ERROR (-20001, 'No table can not be droped from SCOTT schema');
END;
2. Create a DDL trigger to prevent removal of emp table under scott schema.
ANS. CREATE OR REPLACE TRIGGER Drop_Check_For_Scott_on_Emp
BEFORE DROP ON scott.SCHEMA
BEGIN
IF UPPER(RTRIM(LTRIM(sys.dictionary_obj_name))) = 'EMP'
THEN
RAISE_APPLICATION_ERROR (-20001, 'EMP table can not be droped from SCOTT schema'); END IF;
END;
Q.3 create a DDL trigger to prevent removal of any table under any schema. (User must have ADMINISTER
DATABASE TRIGGER privilege).
ANS. CREATE OR REPLACE TRIGGER Drop_Check_For_Any_Table
BEFORE DROP ON DATABASE
BEGIN
IF UPPER(RTRIM(LTRIM(sys.sysevent))) = 'DROP' AND UPPER(RTRIM(LTRIM(sys.dictionary_obj_Type))) = 'TABLE
THEN
RAISE_APPLICATION_ERROR (-20001, 'Drop Table is not allowed under this Database');
END IF;
END;
Problems (For Instead Of Triggers)
1. create a trigger to allow Data Manipulation on EMP and DEPT tables via the View.
1.1 Create a view on emp and dept tables combination.
END;
Q.2 Create a trigger to load a package into KEEP buffer as soon as Database is started.
Ans. CREATE OR REPLACE TRIGGER pin_package
AFTER STARTUP ON DATABASE
BEGIN
DBMS_SHARED_POOL.KEEP ('SCOTT.EMP_PG', 'P');
END;
Posted by Sunil Dutt at 1:45 AM 1 comment: Links to this post
Entire - Oracle
Good zip file of Entire Oracle worth reading this have a look friends
http://www.esnips.com/doc/d327c757-49b3-47f7-bf7d-36d6a854c497/Entire-Oracle
Posted by Sunil Dutt at 1:44 AM 3 comments: Links to this post
17. What structure is used to prevent more than one user from updating the same data in a table at the same
time? Ans ) locks
18. The default length for char data type is Ans ) one
19. The default order in which records are retrieved when an order by clause is used is
Ans ) Ascending
20. The operator precedence between AND & OR is Ans) AND over OR
21. The output of ltrim (\"BILL CLINTON\",BALL) is
Ans) ILL CLINTON
22. The output of substr (\"CREATE\",3,3) is Ans) EAT
23. The number of minimum join condition that are required to join n tables is N-1
24. In an outer join (+) sign is placed on the Ans) deficient table side
25. A sub-query can appear within which of the following clauses & operators 1. Select 2. Where 3. Having 4. Set
operators Ans ) select , having and set operators
26. If where clause is not specified in an update statement then
Ans ) all rows updated
27. The database object from which multiple users may generate unique integer is
Ans ) sequence
28. Cluster columns must correspond to columns in each of the cluster tables in
Ans ) size and column name
29. The clause in the computer command that helps in computing count of rows is
Ans ) number
30. The elements, which are mandatory for a PL/SQL blocks are
Ans ) begin and end;
31. The concatenation operator in PL/SQL is Ans)
32. Which of the following are available in PL/SQL and not in SQL
Ans ) data access compatibility
33. The assignment operator in PL/SQL is Ans) =
34. The procedure which lets you issue user-defined error messages from a stored sub-program or database trigger
is
Ans ) exception_unit and raise_application_error
35. Data can be retrieved into variables using which of the following options
Ans ) select into and fetch
36. Which of the following does a cursor For Loop do 1. Open a cursor 2. Fetch 3. close cursor Ans) ALL
37. Which statement can appear in a trigger body Ans) SQL set
38. To create a database trigger, the user must have the privilege.
Ans ) create trigger privilege
39. Which operator finds common rows from 2 or more different queries?
Ans ) intersect
40. Foreign key constraint can be enforced by using constraint.
Ans ) references
41. The statement fetches rows from a table to a cursor. Ans) select
42. The NVL() function is used to Ans) substitute a new value
43. The maximum size of LOB is Ans) 4gb
44. How many triggers can create per table Ans) 12
45. Maximum how many constraints can enforce on a single column Ans) four
46. PL/SQL stands for Ans ) procedural language of sql
47. which are the character functions will take string parameter and it will return numeric Ans) length and instr
48. Select trunc(199.99) from dual Ans) 199
49. Which constraint is only a table level Ans) composite primary key
50. Triggers can call in subprograms Ans) yes
51. The NULL columns do not participate in arithmetic computations
52. You cannot create more than one trigger per table.
53. Which Procedure produces output on the screen
Ans ) dbms_output.putline()
54. The cursor is created by any SQL statement. Ans) implicit
55 Which triggers are used for views? Ans) instead of triggers
56 select statement is Ans ) DRL
57 trigger is fired Ans ) implicitly
Ans ) long
94 The comprises set of files that protect altered database data that has not been written to data files Ans) redo
log
95 Maximum size of raw data type is Ans) 2kb
96 Which one of the following is not applicable on INSTEAD OF Trigger
Ans ) Can be applied on tables
97 In Oracle 8, a char database can hold up to Ans) 2000 bytes
98 After creating a sequence, to view the first value we use which keyword
Ans ) nextval
99 In PL/SQL assignment operator is replaced using the reserved word
Ans) default
100 is a valid pseudo column
Ans) rowid, rownum, sysdate, uid, nextval, curval
101 The Index created by the Primary key column is called ans) unique index
102 The operation cannot be performed using views when the view definition includes more than on table Ans)
insert
103 The parameter cannot be changed while altering a sequence
Ans ) start with n (n cant be changed)
104 To check the source code for the object types use the data dictionary view Ans user_source
105 Which of the following is most restrictive of table level locks?
Ans) exclusive lock
106 In PL/SQL block what is the default value of the variable Ans) null
107 Find output of the following ( Select substr( \"christmas\" , 4,3) from dual)
Ans ) ist
108 The ability of object to take more than one form is known as
Ans ) polymorphism
109 When the user is trying to assign values to the attributes of an uninitialized object, which of the following
exception is raised Ans) VALUEERROR
110 The attribute in the create sequence syntax specifies that the sequence continues to generate values from the
beginning after reaching either its max or min value Ans) increment
111 A composite unique key can contain how many number of columns Ans) 16
112 What operations can be performed on sequence Ans) Alter, Select
113 Restriction on triggers can be achieved using what clause Ans) when
114 To check the partition type which data dictionary can be used.
Ans ) user_tab_partitions
115 Outer joins retrieves Ans) both matched and unmatched rows
116 A function used to convert a null value to value is Ans) decode
117 Role is Ans ) group of privileges
118 A returns all rows returned by the simple join as well as those rows from one table that do not match any row
from the other table Ans) outer join
119 The data that stored in the cursor is called as Ans ) active data set
120 what is the format mask for Julian data Ans ) j
121 Label is a word associated with an statements Ans) conditional
122 level locks are not released by rolling back to save point Ans ) row level
123 you can use the CASE function in place of Ans) decode
124 The writes modified blocks from the database buffer cache to the data files
Ans ) database writer
125 The magnitude range of a binary integer value in pL/sql is
Ans ) -231-1 to 231-1
126 Trigger name should not exceed characters Ans) 30 characters
127 The REF operator returns of the row object Ans) OID
128 PL/SQL is a structured language? Ans ) block structured language
129 Raw types are used to store which type of data Ans ) binary
130 PCTFREE is a portion of the data block that is not filled by rows as they are inserted in to a table but is
reserved for Ans ) 'Future insert
131 Sign function returns Ans) +, - and =
132 Syntax of MERGE function
Ans) merge into using /<> on when matched these update set when not matched then insert values
133 The oracle engine provides procedure named that allows programmers to show user defined messages Ans)
Raise_Application_Error
134 Which are called as trigger actions Ans) Before and after
135 A function that act on only one value at a time are called as
Ans ) Scalar function
136 is used to get cross tabulation & cumulative values
ans ) CUBE and ROLLUP
137 Which is used for bulk bind? Ans) for all
138 which is used to modify any operating system files Ans) UTL_File
139 which is used to insert values in to multiple tables using select statements
ans ) INSERTALL
140 Which appends on operating system specific line terminator Ans) put_line
141 Which is an object , that is completely contained within another
Ans ) embedded object
142 Which of the following is false regarding data files?
Ans ) Data files can be associated with two or more table spaces
143 In which data dictionary table the object type information will be stored
Ans ) User_Types
144 When you use the THE class in DML statements Ans) Nested table
145 Which is used to store complete column information at a time in to a variable
Ans ) bulk collect
146 when you use for update class in a cursor which is compulsory
ans ) where current of
147 When cursor is in for loop which operations are not necessary
Ans ) Open, Fetch, Close
148 RowID consistes of
Ans ) Data file Id, Object Id , Block Id, Row_Sequence_ID
149 What is a object, which can be created only at run time Ans ) Timer
150 what is the extension of .PLL Ans) Programming Link Library
151 what is the extension of object library module Ans) OBL
152 How many styles are there in alert property Ans) three
153 Display item doesnt have which property Ans) navigational
154 When Timer Expired is correspondent to which object Ans) timer
155 When we compare with radio button & push button, push button will not have
Ans ) Button value property
156 Which function is used to create runtime record group Ans) create_group
157 which trigger and code is used to run application without connecting to database
ans ) on_logon,NULL
158 Form 6i is a ans ) 2 and 3 Tier architecture
159 When we select value from LOV, by default where the value is going to store
Ans ) return item
160 LOV always return ans ) boolean value
161 Alert always return ans) number value
162 Which procedure is used to change alert button label
Ans ) set_alert_button_properly
163 When we create a LOV automatically created ans ) record group
164 which function is used to create dynamic query record group
ans ) create_group_from_query
165 How many types of canvas are there ans ) five
166 Which variable cannot assign a value ans) system
167 When you have cascade delete behavior which trigger gets created
Ans ) PRE-DELETE
168 Which Trigger fires when an operator double clicks on a image item
Ans ) WHEN_IMAGE_ACTIVATED
169 The data type of an image item is ans ) BLOB
170 The default window name is ans ) window1
171 What needed to create for making a master/detail report Ans) Data link
172 A group of radio buttons are placed under the item ans ) Radio Group
SQL*Loader Examples
What is SQL*Loader and what is it used for?
SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database. Its syntax is
similar to that of the DB2 Load utility, but comes with more options. SQL*Loader supports various load formats,
selective loading, and multi-table loads.
How does one use the SQL*Loader utility?
One can load data into an Oracle database by using the sqlldr (sqlload on some platforms) utility. Invoke the utility
without arguments to get a list of available parameters. Look at the following example:
sqlldr scott/tiger control=loader.ctl
This sample control file (loader.ctl) will load an external data file containing delimited data: load data
infile 'c:\data\mydata.csv'
into table emp ( empno, empname, sal, deptno )
fields terminated by "," optionally enclosed by '"'
The mydata.csv file may look like this:
10001,"Scott Tiger", 1000, 40
10002,"Frank Naude", 500, 20
Another Sample control file with in-line data formatted as fix length records. The trick is to specify "*" as the name
of the data file, and use BEGINDATA to start the data section in the control file.
load data
infile *
replace
into table departments
( dept position (02:05) char(4),
deptname position (08:27) char(20) )
begindata
COSC COMPUTER SCIENCE
ENGL ENGLISH LITERATURE
MATH MATHEMATICS
POLY POLITICAL SCIENCE
Is there a SQL*Unloader to download data to a flat file?
Oracle does not supply any data unload utilities. However, you can use SQL*Plus to select and format your data and
then spool it to a file:
set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
spool oradata.txt
select col1 ',' col2 ',' col3
from tab1
where col2 = 'XYZ';
spool off
Alternatively use the UTL_FILE PL/SQL package:
Remember to update initSID.ora, utl_file_dir='c:\oradata' parameter
declare
fp utl_file.file_type;
begin
fp := utl_file.fopen('c:\oradata','tab1.txt','w');
utl_file.putf(fp, '%s, %s\n', 'TextField', 55);
utl_file.fclose(fp);
end;
/
You might also want to investigate third party tools like TOAD or ManageIT Fast Unloader from CA to help you
unload data from Oracle.
Can one load variable and fix length data records?
Yes, look at the following control file examples. In the first we will load delimited data (variable length):
LOAD DATA
INFILE *
INTO TABLE load_delimited_data
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
( data1, data2 )
BEGINDATA
11111,AAAAAAAAAA
22222,"A,B,C,D,"
If you need to load positional data (fixed length), look at the following control file example: LOAD DATA
INFILE *
INTO TABLE load_positional_data
( data1 POSITION(1:5),
data2 POSITION(6:15) )
BEGINDATA
11111AAAAAAAAAA
22222BBBBBBBBBB
Can one skip header records load while loading?
Use the "SKIP n" keyword, where n = number of logical rows to skip. Look at this example: LOAD DATA
INFILE *
INTO TABLE load_positional_data
SKIP 5
( data1 POSITION(1:5),
data2 POSITION(6:15) )
BEGINDATA
11111AAAAAAAAAA
22222BBBBBBBBBB
Can one modify data as it loads into the database?
Data can be modified as it loads into the Oracle Database. Note that this only applies for the conventional load
path and not for direct path loads.
LOAD DATA
INFILE *
LOAD DATA
TRUNCATE
INTO TABLE T1
FIELDS TERMINATED BY ','
( field1,
field2 FILLER,
field3 )
How does one load multi-line records?
One can create one logical record from multiple physical records using one of the following two clauses:
CONCATENATE: - use when SQL*Loader should combine the same number of physical records together to form one
logical record.
CONTINUEIF - use if a condition indicates that multiple records should be treated as one. Eg. by having a '#'
character in column 1.
How can get SQL*Loader to COMMIT only at the end of the load file?
One cannot, but by setting the ROWS= parameter to a large value, committing can be reduced. Make sure you have
big rollback segments ready when you use a high value for ROWS=.
Can one improve the performance of SQL*Loader?
A very simple but easily overlooked hint is not to have any indexes and/or constraints (primary key) on your load
tables during the load process. This will significantly slow down load times even with ROWS= set to a high value.
Add the following option in the command line: DIRECT=TRUE. This will effectively bypass most of the RDBMS
processing. However, there are cases when you can't use direct load. Refer to chapter 8 on Oracle server Utilities
manual.
Turn off database logging by specifying the UNRECOVERABLE option. This option can only be used with direct data
loads.
Run multiple load jobs concurrently.
What is the difference between the conventional and direct path loader?
The conventional path loader essentially loads the data by using standard INSERT statements. The direct path
loader (DIRECT=TRUE) bypasses much of the logic involved with that, and loads directly into the Oracle data files.
More information about the restrictions of direct path loading can be obtained from the Utilities Users Guide.
Posted by Sunil Dutt at 5:43 AM 1 comment: Links to this post