Monday, 22 April 2013

SQL * LOADER


SQL * LOADER
=============================================
It is one of the Oracle Tool will be used to transfer the data from Flat files into
Oracle Base tables.
When we are developing the Interfaces or Conversion program in Oracle Applications
then we will be using the SQL Loader Programs.
while working with SQL * Loader we will come across 5 Files.


1)Flat File OR data File:
Data file contains the data in the specific format which we will receive from the
client. this file will be generated by the legacy system(Other Systems) program.
It may be either .txt format
.dat
.csv(Comma Separated View) Excell sheet.
Most of the times we will receive in the (.csv) format


2)Control File :
—————–
Is nothing but a SQL*Loader Program will be used to load the data from file into table.
we will develop the control File
Execute the Control File.
While developing the Control file we will specify follwoing things.
1)Data File path
2)Database Table Name
3)Column Mapping.
Control file Extension is (.ctl)


3)Bad File:
———–
when we execute the COntrol file if any records are rejected by SQL *Loader then we
will find those rejecteds record in the Bad file.
SQl loader recjects the records if there are any datatype mismatch
Internal Errors
Data file Format problem
Bad File Extension is (.bad)


4)Discard File:
—————
when we execute the COntrol file if any records are rejected by Control File then we
will find those rejecteds record in the Discard file.
Control file Recjects the record when the record is not satisfying the record which
are not satisfied the condition specified in the Control file.
Discard File Extension is (.dis)


5)Log File :
————-
It contains the Log information like Program start time,End Time
No of succesfully records upload
Rejected Records into the Bad file
Rejected records into the Discard file
Any errors are there in the Control file those error message details we will find.
Log file Extension is (.log)


Control File Syntax:
———————-
LOAD DATA
INFILE ‘Data File Path’
Insert into table
FIELDS TERMINATED by ‘,’ OPTIONALLY ENCLOSED BY’”‘
TRAILING NULLCOLS
(Column1 ,
column2 ,
column3 ,……)


Execution of Control File :
—————————–
Goto Command Prompt where the SQl loader is Installed.
D:Oracle\Proddb\8.1.7\bin\ SQLLDR Username/Password@PROD
Control = Control file Path.
============================================
1)Connect to Scott schema create temp table
2)Prepare the data file having some sample records save in the local mechine.
3)Develop the control file like follows.

load data
infile ‘C:\22\LOAD\EMP.txt’
INSERT INTO TABLE EMP_DETAILS22
fields terminated by ‘,’
(empno ,
ename ,
sal ,
job ,
comm ,
tax ,
deptno ,
jdate)

Note: Save the file extension as “.ctl”.
4)Goto Command Propmt through Start Menu = Run = > CMD
5)Connect to following path and execute the control file
D:\Oracle\Proddb\8.1.7\Bin\SQLLDR Scott/Tiger@PROD
Control = C:\22\LOAD\emp_details.ctl

Goods Received Note Query


SELECT
A.ORG_ID "ORG ID",
E.VENDOR_NAME "VENDOR NAME",
UPPER(E.VENDOR_TYPE_LOOKUP_CODE) "VENDOR TYPE",
F.VENDOR_SITE_CODE "VENDOR SITE",
F.ADDRESS_LINE1 "ADDRESS",
F.CITY "CITY",
F.COUNTRY "COUNTRY",
TO_CHAR(TRUNC(D.CREATION_DATE)) "PO DATE",
D.SEGMENT1 "PO NUMBER",
D.TYPE_LOOKUP_CODE "PO TYPE",
C.QUANTITY_ORDERED "QTY ORDERED",
C.QUANTITY_CANCELLED "QTY CANCALLED",
G.ITEM_DESCRIPTION "ITEM DESCRIPTION",
G.UNIT_PRICE "UNIT PRICE",
(NVL(C.QUANTITY_ORDERED,0)-NVL(C.QUANTITY_CANCELLED,0))*NVL(G.UNIT_PRICE,0) "PO Line Amount",
(SELECT
DECODE(PH.APPROVED_FLAG, 'Y', 'Approved')
FROM PO.PO_HEADERS_ALL PH
WHERE PH.PO_HEADER_ID = D.PO_HEADER_ID) "PO STATUS",
A.INVOICE_TYPE_LOOKUP_CODE "INVOICE TYPE",
A.INVOICE_AMOUNT "INVOICE AMOUNT",
TO_CHAR(TRUNC(A.INVOICE_DATE)) "INVOICE DATE",
A.INVOICE_NUM "INVOICE NUMBER",
(SELECT
DECODE(X.MATCH_STATUS_FLAG, 'A', 'Approved')
FROM AP.AP_INVOICE_DISTRIBUTIONS_ALL X
WHERE X.INVOICE_DISTRIBUTION_ID = B.INVOICE_DISTRIBUTION_ID)"Invoice Approved?",
A.AMOUNT_PAID,
H.AMOUNT,
I.CHECK_NUMBER "CHEQUE NUMBER",
TO_CHAR(TRUNC(I.CHECK_DATE)) "PAYMENT DATE"
FROM AP.AP_INVOICES_ALL A,
AP.AP_INVOICE_DISTRIBUTIONS_ALL B,
PO.PO_DISTRIBUTIONS_ALL C,
PO.PO_HEADERS_ALL D,
PO.PO_VENDORS E,
PO.PO_VENDOR_SITES_ALL F,
PO.PO_LINES_ALL G,
AP.AP_INVOICE_PAYMENTS_ALL H,
AP.AP_CHECKS_ALL I
WHERE A.INVOICE_ID = B.INVOICE_ID
AND B.PO_DISTRIBUTION_ID = C. PO_DISTRIBUTION_ID 
AND C.PO_HEADER_ID = D.PO_HEADER_ID 
AND E.VENDOR_ID  = D.VENDOR_ID
AND F.VENDOR_SITE_ID  = D.VENDOR_SITE_ID
AND D.PO_HEADER_ID = G.PO_HEADER_ID
AND C.PO_LINE_ID = G.PO_LINE_ID
AND A.INVOICE_ID = H.INVOICE_ID
AND H.CHECK_ID = I.CHECK_ID
AND F.VENDOR_SITE_ID = I.VENDOR_SITE_ID
AND C.PO_HEADER_ID IS NOT NULL
AND A.PAYMENT_STATUS_FLAG = 'Y'
AND D.TYPE_LOOKUP_CODE != 'BLANKET'; 

Apps Technical Interview Questions


Apps Technical Interview Questions


            1) How to delete duplicate rows?
            2) What is cursor what is the different types of cursors?
            3) What is exception and what are different type’s exceptions?
            4) What is others exception?
            5) How to raise user defined exceptions?
            6) In a procedure I have one select stmt that is not retrieving any rows and I have predefined NO_DATA_FOUND exception and user defined no_data_found then which error will raise first?
            7) What is materialized view?
            8) Can we update a view?
            9) What are the types of joins and what is outer join?
            10) How will you mention outer join?
            11) What is autonomous transaction?
            12) What is purpose of autonomous transaction?
            13) How to find how many ‘a’ are there in the specified string ‘aasfdhhjkgjaaaa’?
            14) What is LSTRING?
            15) What are the error codes u faced frequently in your experience?
            16) What is primary key?
            17) I want to specify 5 columns in a table as NOTNULL and UNIQUE how to do that?
            18) What are database triggers? How many types of database triggers are there?
            19) When a specific row in a table is updated then I want to insert that row into another table how to do that by using the trigger?
            20) What is %row type and %type?
            21) I have declare a variable x as emp%rowtype and I have passed a value ‘10’ in run time then is it work successfully if not what error you will get?
            22) How you will do performance tuning?
            23) What are the forms u developed?
            24) What are the types in master details forms?
            25) What are the procedures that will gets created when a master details form created?
            26) How call a form from another form in apps?
            27) What are the triggers that will fire when the cursor moves from master form to detail forms?
            28) I want to validate a field not to enter wrong data how to that in forms/
            29) What is when validate item trigger?
            30) What is the trigger firing sequence in forms?
            31) I have developed a form on a complex view now I want to insert on that view is it possible? If not how to do that?
            32) What are the work flows you have developed and customized?
            33) How you have sent your message to preparer?
            34) What are the parameters you pass to a function in work flow?
            35) What is role?
            36) What are the interfaces you have done?

             
            37) What is FILLER in sql*loader?
            38) What are the validations you have done in gl interface?
            39) What are the conversions you have done?
            40) What is procedure to do a conversion?
            41) What is the concurrent program name for customer conversion?
            42) What are the tables you have used in customer &vendor conversions?
            43) What is the links between these tables?
            44) Where will you write plsql code in reports?
            45) Where will you execute your plsql code in reports i.e. in which trigger?
            46) In a report if we enter any parameters that time the report should not run? How to do that? In which trigger you will write the code?
            47) How will you do debugging in reports?
            48) What is report tuning?
            49) What are the different procedures available in srw.package?
            50) What is user exit?
            51) What is lexical and bind parameters?
            52) What is token?
            53) What are the precautions you will take while customizing a report?
            54) If I run a report values like profiles have to store in different table how to do that where will you write the code (In which trigger)?



Apps Technical Interview Questions asked in Oracle


1. What are steps of interface?
2. What are the validations you have done in uploading date from Pre interface-to-interface table?
3. What are the forms you have customized and developed?
4. What is your role to develop a new form?
5. Who is giving you specification?
6. What are the steps to develop a new form?
7. What are the problems you had faced after developing a new form’s?
8. Is this form is working fine or not?
9. Tell me about the functionality of the new form you have developed?
10. How to set up Multi Org?
11. How to hide the data from different users in the same Organization?
12. what is the difference between Alert and WF?
13. What is the difference between Data Log file and Tablespace?
14. Can a view be updated? How?
15. What are the lookups of PO?
16. what are the steps to create and customize Forms?
17. What for CUSTOM.PLL is used?
18. How to call a WF in your form?
19. How can you set Value sets in Flex Field?
20. How can you create a module in APPs and how to make it working?
21. What is the structure of Multi Org?
22. Where the ORG ID exists in Multi Org?
23. How to check the Multi Org is enabled or not ?
24. How can you hide some columns of DFF?
25. How can you call the API in any program, especially in Forms and reports?
 26. How can you allow the official to see the information of two employees and not to each other?
27. What are the Concurrent Interface Programs you have run for your developed Interfaces?
28. What is the Tablespace, Segment and Extent in Database?
29. Draw the Multi Org structure.
30. What is Set Of Books Id and Chart Of Account?
31. What will be your approach for the assignment to develop the new Form?
a) Analyse the Form
b) Check whether the requirement can be implemented doing Flex Field? If Not then Check, whether the requirement can be accommodated in the existing form by adding some more functionality in the existing form?Else Create a new form.
32. How can you set your Operating Id (Org Id)?
33. what is the methodology of Documentation you use?
34. what is the hierarchy of Organization?
a) Set Of Books B) Legal Entity C) Operating Unit d) Inventory
35. What is the difference between Accruals and Payables?
It’s the recognition of Revenue when you sell goods and recognition of Expense when the supplier provides services or goods.
36. How can you make the program incompatible with itself?



PL/SQL Interview Questions


            1. What is Exception? Types of Exceptions? Exception Propagations?
            2. What is RAISE_APPLICATION_ERROR?and what is PRAGMA INIT_EXCEPTION?
            3. What are the Predefined exceptions we have?
            4. When we is SELECT statement in the Execution block what are the Predefined exceptions we have to use in the Exception Block?
            5. What is the diff between NO_DATA_FOUND and %NOT FOUND
            6. What is CURSOR? What are the Cursor types? what are cursor declaration steps?
            7. What is the diff between Implicit and Explicit and Ref Cursor?
            8. In which program u has used the Cursor? One example for implicit cursor?
            9. What are the Cursor attributes we have?
            10. Can we issue the commit inside of the Cursor for Loop?
            11. What is For Update OF Clause in the Cursors?
            12. What is Procedure and what is Function?
            13. What is the RND and WND?
            14. What is the diff between Procedure and Function?
            15. When we will create Procedure and when we will create function?
            16. What is the diff between Package procedure and Standalone procedure?
            17. If we drop the table which we have used in the procedure do we need to recompile the procedure then how?
            18. How to get the Procedure Source code from database?
            19. What is the Advantage of Package?
            20. What are the other objects we can group inside of Package?
            21. How to Recompile the Package?
            22. When we will go for creation of Package? Can we create Package body without creation of Package Specification?
            23. Can we declare Procedure directly in the package body without declaring in the package specification?
            24. What is Trigger
            25. Can we commit inside of trigger? How to delete the Trigger? How many triggers we can use maximum?
            26. What are The DML Triggers? What is diff between Row and Statement level trigger?
            27. How to Debug PL/SQL Code?
            28. What are the Trigger Predicates we have?
            29. What is diff between Trigger and Procedure?
            30. What is Package Variable what is advantage?
            31. What are the Collections?
            32. What is PL/SQl Table what is the advantage of that when we will use PL/SQL Table?
            33. What is Global temporary table what diff between PL/SQL table and Temporary table?
            34. What is %ROWTYPE?
            35. What is Instead of Trigger? How can u use that?
            36. What is mutating trigger how can you handle this?
            37. What are PL/SQL table attributes?


Apps Technical Interview Questions asked in wipro


            1. What are different cursors available?
            2. What are cursor attributes?
            3. Can we use sql%found in Explicit cursors opened in cursor for loop?
            4. What is token?
            5. What is init pragma exception?
            6. How do you define a table type value set depending on another table value set?
            7. In this case, if the child parameter has sequence no. as 5 and the parent parameter has sequence no. as 10, what is the effect? When you will get the error and what is the error?
            8. What is the order flow including tables effected at each stage?
            9. What is the hierarchy of Multi org concept?
            10. Where do you define the ‘Set of Books’ in Multi Org Concept?
            11. In which table, you will get Organization_id and in which tables, you will get org_id?
            12. What is Run alone report?
            13. What is incompatibility in Report definition?
            14. What you have done for an interface?
            15. What is the procedures you have done?
            16. Any API used in your procedures?
            17. What are different APIs available in Oracle Apps?
            18. How the oracle Applications recognizes the print style?
            19. what is the use of Row & column columns in Report Definition above the printer style?
            20. When the workflow back end process will run in the order cycle?
            21. Can you customize a workflow?
            22. How a multi org concept effects in GL module?
            23. What is a miscellaneous receipts & issues?
            24. Do you face any performance related issues in your work?
            25. What is TCA architecture?
            26. What are the tables effected when ‘ship confirm’?
            27. In the order cycle, where it is interrelate with other oracle modules like INV, AR etc.
            28. what are the table affected when you make a customer under credit hold?

Sql Interview Question


Sql Interview Question


1) What is SQL and where does it come from?   Home
Structured Query Language (SQL) is a language that provides an interface to Relational database systems. SQL was developed by IBM in the 1970s for use in System, and are a de facto standard, as well as an ISO and ANSI standard. SQL is often pronounced SEQUEL.
In common usage SQL also encompasses DML (Data Manipulation Language), for Inserts, Updates, Deletes and DDL (Data Definition Language), used for creating and modifying tables And other database structures.

The development of SQL is governed by standards. A major revision to the SQL standard was completed in 1992, called SQL2. SQL3 support object extensions and will be (partially?) Implemented in Oracle8.

2) DDL home
DDL is Data Definition Language statements. Some examples:
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the records
Are removed
COMMENT - add comments to the data dictionary
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
 Difference between Delete and truncate
1) Delete-DML                                                             Truncate
        -It will mark the records to delete                   -It is DDL
        -We can rollback                                                 -WE CAN'T ROLLBACK
        -We can delete the records by condition         -WE CAN'T APPLY CONDITIONS
                                                            -IF ANY LOCKS ARE THREE ON THE TABLE
                                                                                      THEY WILL RELEASED
-It will releases the space and we can latter we use that space From oracle 8i onwards we can a drop a column
Alter table <Table_name> drop column <column_name>
Alter table <table_name> set unused (last_name)
Alter table <table_name> drop unused columns

All this type of values are stored in user_unused_col_tab table

3) DCL

DCL is Data Control Language statements. Some examples:

COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like what rollback segment to use
Savepoint
Rollback: Oracle Issues implicit commit before and after any DDL statement. Even if your DDL statement does not execute then also it issues commit statement
If we issue commit all savepoints will be erased and all locks are released.

4) DML
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency
MUTATING TABLE: Mutating Table is a table that is currently being modified by a DML statement. For a         Trigger, this is the table on which the table is defined.
DML Statement: Select, Update, Delete, Insert

Commit->it we issue the commit all savepoints are erased and all locks are released; If we disconnect the database then implicit commit statement will be issued.
Diff between POST and COMMIT:
POST puts the data from client to the server’s Rollback segment whereas COMMIT put the data from rollback segment to the Table.


5 Transaction->
A transaction is an operation against the database, which comprises a series of changes to one or more tables
A transaction begins when the first executable DML and DDL command is encountered and ends when one of the following occurs
* commit/Rollback/DDL command /log off/machine failure

6Locks                                                              
Shared/exclusive -When 2 transaction wants to read/write from db at the same time.
1) Table level2) row level
 Row Exclusive locks are obtained when updating, inserting or deleting rows

Duration of locks
) All locks acquired during a transaction are released when the transaction is committed
2) All locks are acquired during a transaction are released when the transaction is rolled back
3) All locks are acquired after a savepoint are released when the transaction is rolled back to the savepoint

Dead lock-It is will come in multi-user environment
When the two users issues update statements then dead lock will come
Dead- 1trans updates EMP and dep
2 trans update dep and EMP
Dead locks are released when commit/rollback statements are issued or logging off

7) How does one code a tree-structured query?                              
Select LEVEL, EMPNO, ENAME, MGR
          From EMP
        Connect by prior EMPNO = MGR
          start with MGR is NULL;

8.JOINS
 Def: -A join is used when a SQL query requires data from more than one table or the same table on the database.

TYPES OF JOINS:

1) EQUI-JOIN: a join that is formed as a result of an exact match b/w two columns is called as                 equi-join or simple join or inner join.

2) NON-EQUI-JOIN: - NON-EQUI-JOIN is a join condition containing something other than an equality                     operator.
A join is that is formed based on the comparison operators (except "=") is called non-equi join.

EX: - SQL> SELECT e.last_name, e.salary, j.grade_level
          FROM employee e, job_grades j
            WHERE e.salary
                BETWEEN j.lowest_sal AND j.highest_sal;

3) SELF-JOIN: A join relates a table to itself is called a self-join.

EX: - SQL> SELECT e.empno, e.ename, m.mgr from emp e, emp m where e.empno=m.mgr;

4) OUTER-JOIN: (+) always at the child side.
           --You can use OUTER-JOIN to also see rows that do not meet the join condition.
             --The outer-join operator is the plus sigh (+).
           --The missing rows can be returned if outer-join operator is used in join condition.

EX: -SQL> SELECT E.EMPNO, D.DEPTNO FROM EMP E, DEPT D WHERE E.DEPTNO (+)=D.DEPTNO;

9.FUNCTINS->
CONVERSION FUNCTIONS:
                             TO_CHAR, TO_DATE, TO_NUMBER.
DATE FUNCTIONS:
ADD_MONTHS,            LAST_DAY,                            MONTHS_BETWEEN,
NEW_TIME,                           NEXT_DAY,                            ROUND,
SYSDATE,                     TRUNC.

DECODE:
                   Nested IF THEN ELSE
                   SELECT DECODE (ename, ‘Smith’, ’a’, ‘Something’);
GROUP FUNCTIONS:

MAX ()                MIN ()                           COUNT () AVG ()                 SUM ()                 VARIANCE ()
STDDEV ()

GROUP FUNCTION WITH having CLAUSE CONDITION:
NOTE: ALL GROUP FUNCTIONS IGNORE MULL VALUES IN THE COLUMN.

EX: SQL> SELECT job_id, SUM (salary) PAYROLL
           FROM        employee
           WHERE job_id NOT LIKE '%REP%'
           GROUP BY job_id
           HAVING SUM (salary)>1000
           ORDER BY SUM (salary);

10.SUB QUERIES
A Subquery is a SELECT statement that is embedded in a clause of another SELECT statement.
The inner query or the subquery returns a value that is used by the outer query or the                                  main query.
You can write upto 255 subqueries.

TYPES OF SUBQUERIES:
1.Single-Row subquery: Query that returns only one row from the inner SELECT statement.
          Simple Query--Which fires every time for entire stmt
2.Multiple-Row subquery: Query that returns more than one row from the inner SELECT statement.

CORRELATED SUBQUERY:
SQL*Plus performs a subquery repeatedly once for every row of the main query.
Correlated Subquery -Which fires only once/ per row for entire stmt.
Operators:
Logical Operators:      NOT, AND, OR
Comparison Operators:       NOT IN, LIKE
Set Operators: UNION, UNION ALL, INTERSECTION, MINUS

11.SET OPERATORS:
          - The SET operator combine the result of two or more component queries into one result.
            - Queries containing SET operator are called COMPOUND QUERIES.
            - All SET operators have equal precedence.

1.UNION: All distinct rows selected by either query
 EX:   select job from emp where deptno=10
          union
          Select job from emp where deptno=20
2.UNION ALL: All rows selected by either query, including all duplicates.
EX:    select job from emp where deptno=10
          union all
          Select job from emp where deptno=20

3.INTERSECT: All distinct rows selected by both queries.
EX:    select job from emp where deptno=10
          intersect
          Select job from emp where deptno=20

4.MINUS: All distinct rows that are selected by the first SELECT statement and not selected in the          second SELECT statement.
EX:    select job from emp where deptno=10
          minus
          Select job from emp where deptno=20
12.PSEUDO COLUMNS:
They behave like table columns, but are not actually stored in the table.
CURRVAL, NEXTVAL, ROWID, ROWNUM, SYSDATE, LEVEL, USER, UID PARSING:
It checks the Syntax of SQL Statements.

13.INTEGRITY CONSTANTS:
Null, Not Null, Default, Check, Primary Key, Foreign Key

PRIMARY KEY: NOT NULL, UNIQUE, IF U WANT CREATE MORE THEN ONE COLUM WE SHOULD DEFINE AT TABLE LEVEL, IT'S ALSO CALLED COMPOSITE PRIMARY KEY, WE CAN'T CREATE MORE THAN ONE PRIMARY KEY.

UNIQUE:IT WILL NOT ALLOW DUPLICATE VALUES AND IT ACCEPT NULL VALUES CAN BE DEFINED AT THE COLUMN LEVEL AND TABLE LEAVEL
CHECK: IT WILL CHECK WITH COLUMN DEFINATION BEFORE ACCEPT.CHECK CONSTRAINT DEFINES A CONDITION THAT EACH ROW MUST SATISFY REFERENCES TO THE CURRVAL, NEXTVAL, LEVEL, ROWNUM PSEUDOCOLUMNS CALLS TO SYSDATE UID USER, AND USERENV. CHECK CONS. CAN BE DEFINED AT THE COLUMN LEVEL AND TABLE LEVEL

FORIEGN KEY:
- foreign KEYS POVIDE REFERENTIAL INTEGRITY RULES WITHER WITHIN A TABLE OR B/W TABLES
- CAN BE DEFINED AT TABLE LEVEL OR COLUMN LEVEL.A COMPOSITE FORIEGN KEY MUST BE CREATED BY USING THE TABLE-LEVEL DEFINATION
- A FORIEGN KEY IS USED IN A RELATIONSHIP WITH EITHER PRIMARY OR UNIQUE KEY.
   
References - identifies the table and column in the parent table.
 
ON DELETE CASCADE - Deletes the dependent rows in the child table when a row in the parent                                                                                                                                                                                        table is deleted.
ON DELETE SET NULL - CONVERTS DEPENDENT FORIEGN KEY VALUES TO NULL.
CASCADE CONSTRAINT - The CASCADE CONSTRAINTS clause drops all referential integrity constraints that refer to the primary and unique keys defined on the dropped columns.
The CASCADE CONSTRAINTS clause also drops all multicolumn constraints                                                                                                                                                                                         defined in the dropped columns.


14.INDEXES:
CREATE INDEXES IF U FREQUENTLY WANT TO RETRIEVE LESS THAN 15% OF THE ROWS IN A LARGE                     TABLE
       - INDEX CLOUMNS USED FOR JOINS TO IMPROVE THE PERFORMANCE ON JOINS.
      - DONT USE INDEXES ON TABLES HAVING LESS NO ROWS.
          - IF THE COLUMN HAS NON-UNIQUE VALUES U CAN USE INDEXES ON THESE COLUMNS.
          - DONT USE INDEXES IF THE DATATYPE IS LOB, CLOB & BLOB.
          - IF THE TABLE IS read only WE CAN CREATE MORE INDEXES ON THE TABLE.
          - WE CAN'T CREATE INDEXES ON VIEWS.
       *- INDEXES ARE LOGICALLLY & PHISICALLY INDEPENDENT OF DATA
       *- IF THE INDEX IS DEVLOPED ALL APLLICATIONS CONTINUE TO FUNCTION

Index is an ordered list of contents of a column or group of columns in a table. Index created on a single table Simple Index and which is created on multiple tables is called Composite Index.

CREATE INDEX Index_Name ON Table_Name (Column_Name);
DROP INDEX (Index_Name);

15.CLUSETER:
 Cluster is a method of storing tables that are intimately related and are often joined              
          Together into the same area on disk

16.SYNONYM:
          - SYNONYM IS AN ALIAS FOR A TABLE, VIEW, SEQUENCE & PROGRAM UNIT.
          - A SYNONYM IS A NOT A SCHEMA OBJECT, IT WILL REFER SCHEMA OBJECT.
          - MASK THE REAL NAME AND OWNER OF A SCHEMA OBJECT.
          - PROVIDE PUBLIC ACCESS TO SCHEMA OBJECT.
          - PROVIDE LOCATION TRANSPARENCY FOR TABLES, VIEWS, OR PROGRAM UNITS IF A REMOTE DATABASE.
          - SIMPLIFY THE sql STATEMENTS FOR DATABASE USERS
22
PUBLIC SYNONYM & PRIVATE SYNONYM

17.VIEWS:
      - VIEW IS A LOGICAL TABLE BASED ON A TABLE OR ANOTHER VIEW.
      - VIEW CONTAINS NO DATA OF ITS OWN BUT IS LIKE A WINDOW THROUGH WHICH DATA FROM TABLES CAN                   BE VIEWED OR CHANGED.        
      - VIEW IS STORED AS SELECT STATEMENT IN THE DATA DICTIONARY.
WHY USE VIEWS:
          - TO RESTRICT DATA ACCESS
          - TO MAKE  QUERIES EASY.
          - TO PROVIDE DATA INDEPEMDENCE
          - TO PRESENT DIFFERENT VIEWS OF THE SAME DATA.

SIMPLE VIEW:  DERIVES DATA FROM ONLY ONE TABLE, CONTAINS NO FUNCTIONS OR GROUPS OF DATA, WE CAN  PERFORM dml OPERATIONS THROUGH THE VIEW.

COMPLEX VIEW: DERIEVE DATA FROM MANY TABLES, CONTAINS FUNCTIONS OR GROUPS OF DATA, DOES NOT ALWAYS ALLOW dml OPERATIONS THROUGH THE VIEW.


NOTE: - U CAN'T CREATE INDEXES ON VIEWS.
      - U CAM CREATE A VIEW WITHOUT A TABLE USING force OPTION.
      - CAM CREATE with check option & with read only.
      - We can modify, drop view.
 SYNTAX: CREATE OR REPLACE force/noforce VIEW viewname alias subquery with check option
                   Constraint with read only.
If we use NOT NULL constraint in the base table without default values then we can't insert the row in the base table using the view
 If we use decode function in creating the view we can't update the row in the base table

If we use these words
1) Distinct, avg, count, max, min, stddev, sum, union, union all, intersect, minums, rownum, start with prior to the we can't update the base table through view
If we rename the table then the view become invalid
But one can add the columns and the columns must not be not null columns in the base table

18.Table:
One can rename the table. If we rename the table then all views, synonyms, proceudres, triggers, functions become invalid

If we drop the table all the indexes are dropped
All rows corresponding cluster table are deleted from the blocks of the cluster

We can decrease the length of the column if the data is not there in the table.
I one can change the datatype at any point of time

If we drop the column from the base table if the view is based on that column then the view become invalid.

TO add a not null column to a table which has already some records -
Alter table a
Add (b number default 1 not null)

Portioned table
If we want to store the data of one table depending upon the range in different blocks. By using this we can reduce the network traffic. Table partitioning divides table data between two or more table spaces and physical data file on separate disk.
     Select * from emp partion (p1)

19.TUNING SQL Statements:
Using TK_PROF, EXPLAIN PLAN.

If you have a system that is performing badly, a good way to identify problem SQL statements is to trace a typical user session and then use TkProf to format the output using the sort functions on the tkprof command line.

Explain plan is a representation of the access path that is taken when a query is executed within Oracle.
1.      SET TIME ON;
2.      ALTER SESSION SET SQL_TRACE = ‘TRUE’;
3.      Then run the required program unit
4.      Sql_trace file will be created in User_dump_dest (dir)
5.      Since this trace_file is in the binary format, run tkprof
6.      $ Tkprof <trace_file.trc> <output_file.txt> [options]
7.      $ Tkprof <trace_file.trc> <output_file.txt> [EXPLAIN=user/password]
TKPROF allows you to analyze a trace file to determine where time is being spent and what query plans are being used on SQL statements. Tkprof is an executable that 'parses' Oracle trace files to produce more readable output. Remember that all the information in TkProf is available from the base trace file.
8.      Elapsed time/num of rows * 1000 --> 'X' Mille Second.

20.Explain plan
To discover the execution plan for a select statement. The explain plan statement is most often used from sql* plus. Before that you must create the <plan table> to hold the results
Find INDEXES is being used:
                                      By using EXPLAIN PLAN.
                                      Output is put into PLAN_TABLE.
21.Sql trace:
To diagnosing performance problems on running systems.
To know
No of times the sql statement executed.
Total CPU and elapsed time used by the statement
Total no of physical reads trigger by the statement
Total no of records processed by the statement
Total no of the logical reads trigger by the statement

Hints:
They can be placed into your Sql statements to force the optimizers to utilize a particular execution path for absolute best performance.

/*+ ALL_ROWS */
/*+ FIRST_ROWS */
/*+ CHOOSE */
/*+ HASH_SJ */àWhen using subquery after EXISTSàIt improves the response time.



22.MATERIALLIZED VIEWS:
                       - Materialized views provide indirect access to table data by storing the                                                                                             results of a query in a separate schema object.
                       - Another name for materialized view is SNAPSHOT.
                       - MATERIALIZED VIEW CAN BE STORED IN A SAME DATABASE OR DIFF DATABASE.
                       - DATA CAN BE REPLICATED USING MATERIALIZED VIEW.E
23.TWO-PHASE COMMIT:
                   - It is used in a DISTRIBUTED ENVIRONMENT.
                   - It guarantees that no matter what type of system or network failure might                   occur a distributed transaction either commits on all involve nodes or rollback                   on all involve nodes to maintain data consistency.

24.SITE AUTOMONY:
          - It means that each database participating in a distributed database is administered           separately and independently from other database.
25.ROLLING FORWARD:
          - The first step of recovery is to ROLL-FORWARD i.e. reapply to the data files all of the           changes that are recorded in the REDO-LOG FILE.
Rolling Forward -To reapply to Data file to all changes that are recorded in Redo log file

Due to which data file contains committed & uncommitted data.
Forward Declaration-To declare variable and procedures before using it.
2- Tier Arch. Disadv-When Business Rule changes.

11.CAN U SELECT PROCEDURE FROM SQL STATEMENT?
Ans: No we can't select procedure from select statement, but we can select SQL FUNCTIONS AND
          USER DEFINED FUNCTIONS.
26.Eliminate Duplicate records:
How does one eliminate duplicates rows from a table?
ROWID:
ROWID is the fastest way to locate records.
ROWID Uniquely identifies records.

Choose one of the following queries to identify or remove duplicate rows from a table
 Leaving unique records in the table:
Method 1:

   SQL> DELETE FROM table_name A WHERE ROWID > (
     2    SELECT min (rowid) FROM table_name B
     3    WHERE A.key_values = B.key_values);

Method 2:
   SQL> create table table_name2 as select distinct * from table_name1;
   SQL> drop table_name1;
   SQL> rename table_name2 to table_name1;

Method 3: (thanks to Kenneth R Vanluvanee)
   SQL> Delete from my_table where rowid not in (
   SQL> select max (rowid) from my_table
   SQL> group by my_column_name);

Method 4: (thanks to Dennis Gurnick)
   SQL> delete from my_table t1
   SQL> where exists (select 'x' from my_table t2
   SQL> where t2.key_value1 = t1.key_value1
   SQL> and t2.key_value2 = t1.key_value2
   SQL> and t2.rowid      > t1.rowid);

28.LOB Types:              
          Large Objects Datatypes. Lets us store blocks of unstructured data (text, graphic images,                    video files, audio files) of upto four Gb of size.
          Bfile: BFILE datatype stores large Binary Objects in OS files outside the database.
          Blob: BLOB datatype stores large Binary Objects in the database
          Clob: CLOB datatype stores large blocks of single-byte Character data in the database.
       
29. PVCS:                                                                                                    
          It is a version control utility. PVCS change manager for Oracle can identify the location                                  and impact of changes in Oracle Applications.
30. TOAD

          TOAD is a powerful tool that makes PL/SQL development faster, easier and simpler.

31. INIT.ORA:                                                                                          
          It is a System Parameter
32. Normalization

          It's a technique thru. Which we can design the DB.
          During normalization dependencies can be identified which can cause pbs during deletion &
          Updation .It is used in simplifying the structure of table.
          1NF-Unnorma;ised data transfer to normalized form.
          2NF-Functional dependencies can be find out & decompose the table without loss of data.
          3NF-Transist dependencies, every non-key attribute is functionally dependant on just PK.
          4NF(BCNF)-The relation, which has multiple candidate keys, then we have to go for BCNF.
Denormalization-
          At the same time when information is required from more than one table at faster rate                   then  it is wiser to add some sort of dependencies.

27.FAQ’S

1.      Which command in SQL*Plus is used to save the query output to a file?
          ANS: SPOOL

2.      How would you extract a SQL statement in the SQL buffer of SQL*Plus?
          ANS: Enter a SLASH (/)

3.      What is the default display length of the DATE Datatype column?
          ANS: Eight

4.      Which Clause in a query limits the rows selected?
          ANS: WHERE

5.      Which SQL*Plus command always overwrites a file?
          ANS: SPOOL

6.      Which single-row function could you use to return a specific portion of a character?
          ANS: SUBSTR

7.      Which of the following is not a Group Function? (AVG, COUNT, LEAST, STDDEV, VARIANCE)
          ANS: LEAST

8.      When using multiple tables to query information, in which Clause do you specify the table    names?
          ANS: FROM

9.      What are the special characters allowed in a table name? (&, #, @, $)
          ANS: #, $

10.    What is the default length of a CHAR and Number   Datatype column, if no length is     specified in the table definition?
          ANS: 1 and 9

11.    At a minimum, how many join conditions should be there in the WHERE Clause to avoid a Cartesian join if there are Three Tables in the FROM Clause?
          ANS: 2
          There should be at least (n - 1) join conditions when joining (n) tables to avoid a       Cartesian join

12.    A view can only be used to query and update data, you cannot Insert into or delete from a     view. True or false
          ANS: FALSE

13.    Which option is not available in Oracle when modifying tables? (Add new                              Columns, Rename an Existing Column, Drop an Existing Column) Rename an Existing Column
          ANS: You cannot rename an Existing column using ALTER TABLE

14.    EDIT SAVE FILE SQL*PLUS Default:
          ANS: AFIEDT.buf

15.    Eliminate Duplicate Rows in a Table:
          ANS: ROWID (50).

16.    Eliminate Duplicate Rows in a BASE TABLE BLOCK:
          ANS: Create a SELECT DISTINCT VIEW on the base table

17     Set Transaction -To set a current transaction online offline

18     Optimization-Use of index (HINT)

19     Object Privilege - On a particular object- I/U/D/Exec

20     System Privilege -Entire collection object -C/A/D
       
21       Profile -To control system resources like memory, disk space, and CPU time.

22     Role -Collection of privileges.

23     Type of segment- Rollback, Temp, Data, Index
24     Snapshot-It's a read only table, to improve efficiency of query, which referred remote db, therefore reduce remote traffic.

25.       Describe Oracle database's physical and logical structure?
            Physical: Data files, Redo Log files, Control file.
            Logical: Tables, Views, Table spaces, etc.

26.Can you increase the size of a table space? How?
Yes, by adding datafiles to it.

27.Can you increase the size of datafiles? How?
No (for Oracle 7.0)
Yes (for Oracle 7.3 by using the Resize clause ----- Confirm!!).

28.What is the use of Control files?
Contains pointers to locations of various data files, redo log files, etc.

29.What is the use of Data Dictionary?
Used by Oracle to store information about various physical and logical Oracle structures e.g.
Tables, Tablespaces, datafiles, etc

30.What are the advantages of clusters?
Access time reduced for joins.

31.What are the disadvantages of clusters?
The time for Insert increases.

32.Can Long/Long RAW be clustered?
No.

33.Can null keys be entered in cluster index, normal index?
Yes.

34.Can Check constraint be used for self referential integrity? How?
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.

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

36.What are the states of a rollback segment?
      The various states of a rollback segment are:
      ONLINE, OFFLINE, PARTLY AVAILABLE, NEEDS RECOVERY and INVALID.

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

38.An insert statement followed by a create table statement followed by rollback? Will the rows be inserted?
No.

39.Can you define multiple savepoints?
Yes.

40.Can you Rollback to any savepoint?
Yes.

41.What is the maximum no? Of columns a table can have?
      254.

42.How many rows will the following SQL return?
Select * from emp Where rownum < 10;
9 rows

43.How many rows will the following SQL return?
Select * from emp Where rownum = 10;
No rows

44.Which symbol precedes the path to the table in the remote database?
@

45.Are views automatically updated when base tables are updated?
Yes

46.Can a trigger written for a view?
No

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

48.Is Sysdate a system variable or a system function?
System Function

49.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 a rollback and again issue a nextval. What will the output be?
3

50.What is the result of the following SQL?
Select 1 from dual
UNION
Select 'A' from dual;
Error

51.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.
Yes, database trigger would fire.

52.Can you alter synonym of view or view?
No

53.Can you create index on view
No.

54.What is the difference between a view and a synonym?
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.

55.What is the difference between alias and synonym?
Alias is temporary and used with one query. Synonym is permanent and not used as alias.

56.What is the effect of synonym and table name used in same Select statement?
Valid

57.What's the length of SQL integer?
32-bit length

58.What is the difference between foreign key and reference key?
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.

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

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

61.If any other table same as dual were created would it act similar to dual?
Yes



62.For which relational operators in where clause, index is not used?
<>, Like '%...' is NOT functions, field +constant, field || ''
63.Assume that there are multiple databases running on one machine. How can you switch from one to another?
Changing the ORACLE_SID

64.If you insert a row in a table, then create another table and then say Rollback. In this case will the row be inserted?
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 (e.g. table already exists error) and not syntactically.

65.What are the various types of queries?
Normal Queries
Sub Queries
Co-related queries
Nested queries
Compound queries

66.Which of the following is not a schema object: Indexes, tables, public synonyms, triggers and packages?
Public synonyms

67.What is the difference between a view and a snapshot?

68 Varrays:
They allow us to associate a single identifier with an entire collection. This association let you manipulate the collection as a whole and reference individual elements easily.

69.Create database link <link name> Test_link
Connect to <user name > apps
Identified by <passwd> fnd
Using <connect string> fintst

70 How do you tell the difference between a regular order and a return order?
      In so_headers you identify by order_category which will be RMA for
     Returns and R for Regular

71 the difference between partly available and needs recovery?

how to handle errors while doing bulk data uploading in through oracle pl sql procedure how to handle errors while porting bulk data in oracle pl sql:


how to handle errors while doing bulk data uploading in through oracle pl sql procedure
how to handle errors while porting bulk data in oracle pl sql:
if any record is rejected also i need to complete the remaining records without stoping the procedure execution

declare
--variable declaration;
begin
for c in (select statement)
loop
begin
-------------
---------
execute any procedures
 or any dml statements
-------------
-------------
exception 
---handle exceptions(i.e userdefined or predefined);
insert into error_log_temp(col1,col2,...)values(value1,value2,....);
end;
end loop;
end;

example:
================

create procedure p1 
is
v_error_no varchar2(100);
begin
for c1 in (select empno,ename,sal from emp)
loop
begin
insert into emp_dup (empno,ename,sal) values(c1.empno,c1.ename,c1.sal);
exception when others then
v_error_no :=sqlerrm;
insert into emp_error_log(error_name,empno,ename) values(v_error_no,c1.empno,c1.ename);
end;
end loop;
end p1;

in above insert statement if it gives any errors we are trapping in exception block and inserting into
error log table with out stopping the procedure execution.