Tuesday, 19 June 2012

R12 Supplier Payment Method Table/view description

IBY_EXTERNAL_PAYEES_ALL : This stores supplier information and customer information
IBY_EXT_BANK_ACCOUNTS : This storage for bank accounts
IBY_EXT_PARTY_PMT_MTHDS : This storage for payment method usage rules.
IBY_CREDITCARD : stores the credit card information for a customer
IBY_EXT_BANK_ACCOUNTS :This Stores external bank accounts . These records have       bank_account_type = Supplier
IBY_ACCOUNT_OWNERS :stores the joint account owners of a bank account
IBY_PMT_INSTR_USES_ALL : This stores data from AP_BANK_ACCOUNT_USES_ALL for payment instruments assignments .This information is stored in the following iPayment (IBY) tables

script to kill the session when there is a lock on the objects you are working in TOAD or SQLPLUS or sql developer

steps to kill sessions:

step1:we need to see table need to be killed,query to see
     
        select *from dba_dml_locks -->from this query copy the session id to which table we need kill session

 step2: now with the above session id we need to see the sessions table i.e

        select *from v$session where sid in ('above table copied session id');
        ex:select *from v$session where sid in ('81');  -->with this query we get record,from that copy   SID,SERIAL# values

step3:to kill sessions we need to write below query,in which we need to keep the
         above copied   SID,SERIAL#  values.below is the query
     
         alter system kill session 'SID,SERIAL# ';
         ex:alter system kill session '328,33875';

Thursday, 14 June 2012

ORACLE APPS questions and answers

1.
 What is the Diff between APPS Schema and other Schemas?
Apps schema contains only Synonyms we can't create tables in apps schema,where as other schemas contains tables, & all the objects. Here only we will create the tables and giving grants on created tables. Almost all every time we  will conenct to apps schema only.
             


2.
 What is meant by Custom Top and what is the Purpose?
Custom Top is nothing but Customer Top, which is created for customer only. we can have multiple custom
tops based on client requirement. It is used to store developed & customized components. whenever oracle
corp appling patches it will over ride on all the modules except custom top. that's why we will use custom top.
              
3.
 What is the Significancy of US Folder?
It is nothing but language specification by default it is in american language. We can have multiple languages folders  based on installed languages. from backend we can get it from
FND_LANGUAGES -- COL --INSTALLED_FLAG I,B,D

              I--INSTALLED,
              B--BASE,
              D--DISABLE
              select language_code,nls_language from fnd_languages where installed_flag like 'B'


4.
 Where did U find the Applcation short name and basepath names?
select basepath,application_short_name from fnd_application from the backend. From the from end we can get it Navigation Application Developer.-----> Application---->Register The application name we will get from FND_APPLICATION_TL
              
5.
 Where can U find the release version from backend?
SELECT release_name from FND_PRODUCT_GROUPS; ---11.5.10.2             .


6.
 What are the Folders we will find below the 11.5.0 Folder?
Reports,forms,sql,lib,log,out,bin,admin,html,xml,msg,def, etc              


7.
 Can we create Tables in the Apps Schema?
No.              


8.
 Can we have custom schema when it it required?
yes, we can have custom schema, when we want to create a new table we required custom schema.               


9.
 What is meant by concurrent Program?
It is nothing but Instance of the execution along with parameters & Incompatables. Here Incompatables nothing but if we  are submiting cc programs if any one can be execute in those program , which programs r not imp yet this time we will  mention those programs in incompatables tab.               


10.
 
What are the steps we will follow to register Reports as Concurrent Program?
 First develop the report & save it in local machine. upload into custom_top/11.5.0/reports/us/ go to system  administrator  open executable form create executable by mentioning executable method as reports ,executable  as report name which  was created. go to cc program form create ccprogram by attach executable name in executable section. then attach this  ccprogram to request group, Request group to Responsibility.Responsibility to User.                    


11.
 What is meant by Request group?
It is nothing but collection of cc programs.          


12.
 What is Application Top? What are the types and Purpose?

 A) When we connect to the server we will find the top called application top. Under application top we have

 Product top.
 Custom top

 Product top is the default top built by the manufacturer. Custom top is used to select the Client for his business purposes. Customizations are done with the Custom top.
13.
 What is US folder in the Custom Top?
             It is a language specific folder used to store the G.U.I like reports and forms.
14.
 What are mandatory parameters of Procedures and what the use of those?
 Errorbuf: It is used to returns the error messages and sent it to the log file.
 Retcode: It is used to show the status of the Procedure with 0, 1, and 2 0 for Completed Normal

 1 for Completed Warning
2 for Completed Error
15
 What is Apps Schema and Schema?
 Schema: Schema is the location in database contains database objects like views, tables, and synonyms.

 Apps Schema: It is used to connect the all schemas to get the information from The database.
16.
 What is Token?
            a) Use to transfer values to report builder and it is not case sensitive.
17.
 Difference between FORM, Function and Menu?

a) A menu is a hierarchical arrangement of functions and menus. Each responsibility has a menu assigned to it. A function is a part of an application that is registered under a unique name for the purpose of assigning it to be including it from a menu.
18.
Tell me something about SQL-LOADER.

Sql * loader is a bulk loader utility used for moving data from external files into the oracle database.
Sql* loader supports various load formats, selective loading, and multi-tables loads.

1) Conventional --The conventional path loader essentially loads the data by using standard ‘insert’ statement.
2) Direct -- The direct path loader (direct = true) by possess of logic involved with that, and loads directly in to the oracle data files.
EX:- My data.csv file
1001, “scott tiger”,1000,40
1002,”gvreddy”,2345,50
Load data
Infile ‘c:\data\mydata.csv’
insert Into table emp Fields terminated by “,” optionally enclosed by‘”’
(empno, empname,sal,deptno)
>sqlldr scott/tiger@vis control=loader.ctl log= gvlog.log bad=gvbad.bad discard=gvdis.dsc .
19.
 What is SET-OF-BOOKS?


Collection of Chart of Accounts and Currency and Calendars is called SOB
20.
 Tell me what r the Base tables in the AR?


hz_parties (party_id) (store info about org, groups and people)
HZ_PARTIES stores information about parties such as organizations,
people, and groups, including the identifying address information for the party.
hz_cust_accounts (cust_account_id)
HZ_CUST_ACCOUNTS stores information about customer relationships. If a
party becomes a customer, information about the customer account is stored in this table. You can establish multiplecustomer relationships with a single party, so each party can have multiple customer account records in this table.
hz_cust_acct_sites_all (cust_acct_site_id)
HZ_CUST_ACCT_SITES_ALL stores information about customer sites. One
customer account can have multiple sites. The address is maintained in HZ_LOCATIONS.
hz_cust_site_uses_all (site_use_id)
HZ_CUST_SITE_USES_ALL stores information about site uses or business
purposes. A single customer site can have multiple site uses, such as bill to or ship to, and each site use is stored as a record in this table.
hz_party_sites (party_site_id)
HZ_PARTY_SITES stores information about the relationship between Parties
and Locations. The same party can have multiple party sites. Physical addresses are stored in HZ_LOCATIONS.
hz_locations (location_id)
HZ_LOCATIONS stores information about physical locations.
hz_Person_Profiles (person_profile_id)
HZ_PERSON_PROFILES stores detail information about people.
hz_Organization_Profiles (organization_profile_id)
HZ_ORGANIZATION_PROFILES stores credit rating, financial statistics,
socioeconomic and corporate linkage information for business sites. The primary key for this table is ORGANIZATION_PROFILE_ID.

21.
 FND USER EXITS:-


FND SRWINIT sets your profile option values, multiple organizations and allows
Oracle Application Object Library user exits to detect that they have been called by an Oracle Reports program.
FND SRWEXIT ensures that all the memory allocated for AOL user exits have been freed up properly.
FND FLEXIDVAL are used to display flex field information like prompt, value etc
FND FLEXSQL these user exits allow you to use flex fields in your reports
FND FORMAT_CURRENCY is used to print currency in various formats by using formula column

22.
 What is Value Set?


The value set is a collection (or) container of values.
Whenever the value set associated with any report parameters. It provides list of values to the end user to accept one of the values as report parameter value.

If the list of values needed to be dynamic and ever changing and define a table
based values set.

12) What are the validation types?

1) None -------- validation is minimal.
2) Independent ------input must exist on previously defined list of values
3) Dependent ------input is checked against a subset of values based on a
Prior value.
3) Table ----- input is checked against values in an application table
4) Special ------values set uses a flex field itself.
5) Pair ------ two flex fields together specify a range of valid values.
6) Translatable independent ----- input must exist on previously defined list
of values; translated values can be used.
7) Translatable dependent ------- input is checked against a subset of values
based on a prior values; translated value can be used.
23.
 Form development process?


a) Open template form
b) Save as <your form>.fmb
c) Change the form module name as form name.
d) Delete the default blocks, window, and canvas
e) Create a window.
f) Assign the window property class to window
g) Create a canvas (subclass info)
h) Assign canvas property class to the canvas
I) assign the window to the canvas and canvas to the window
j) Create a data block
k) Modify the form level properties. (sub class item Text item)
l) Modify the app_custom package. In the program unit.
m) Modify the pre-form trigger (form level)
n) Modify the module level properties ((console window, First navigation
p) Save and compile the form.
Place the .fmx in the server directory.
24.
 How does u customize the Reports?


a. Identify the Short name of the standard report in which module we have
to customize
Ex: - if u wants to customize in the AR module path is
Appl top\ar\11.5.0\reports\US\ .rdf
b. Open the .rdf file in Report builder and change the name of the module.
c.
Open the data module and modify the query (what is client requirements)
assign the columns to the attributes.
d.
Go to report wizard and select, what r the newly created columns.
e. Then Compile it. Then u will get a .rep file in the specified module. If it is
not in the specified directory then we have to put in the server directory.
f. Then Register in the AOL Concurrent Executable and
Concurrent Program.
g. Go to system administrator Security àResponsibility àrequest.
h. Add and assign a concurrent program to a request group
25.
 FLEX FIELDS?


Used to capture the additional business information.

DFF
                                       KFF
 Additional Unique Info, Mandatory
 Captured in attribute prefixed columns Segment prefixed
 Not reported on standard reports Is reported on standard reports
 To provide expansion space on your form With  the  help of [].
 [] Represents descriptive Flex field.
 FLEX FILED : DESCRIPTIVE : REGISTER
Used for entering and displaying key information
For example Oracle General uses a key Flex field called Accounting Flex field to uniquely identify a general account.
FLEX FILED : KEY : REGISTER
26.
 Difference between Bind and Lexical parameters?


BIND VARIABLE:
are used to replace a single value in sql, pl/sql
bind variable may be used to replace expressions in select, where, group, order
by, having, connect by, start with cause of queries.
bind reference may not be referenced in FROM clause (or) in place of
reserved words or clauses.
LEXICAL REFERENCE:
You can use lexical reference to replace the clauses appearing AFTER select,
from, group by, having, connect by, start with.
You can’t make lexical reference in pl/sql statements.
27.
 what is Flex mode and Confine mode?


Confine mode:

On: child objects cannot be moved outside their enclosing parent objects.
Off: child objects can be moved outside their enclosing parent objects.

Flex mode:

On: parent borders "stretch" when child objects are moved against them.
Off: parent borders remain fixed when child objects are moved against
them.
28.
 What is Place holder Columns?


A placeholder is a column is an empty container at design time. The placeholder can hold a value at run time has been calculated and placed in to It by pl/sql code from anther object.
You can set the value of a placeholder column is in a Before Report trigger.
Store a Temporary value for future reference. EX. Store the current max salary as records are retrieved.
29.
 What is Formula Column?


A formula column performs a user-defined computation on another column(s) data, including placeholder columns.
30.
 What is Summary columns?


A summary column performs a computation on another column's data. Using the Report Wizard or Data Wizard, you can create the following summaries: sum, average, count, minimum, maximum, % total. You can also create a summary column manually in the Data Model view, and use the Property Palette to create the following additional
summaries: first, last, standard deviation, variance.
31.
 What is TCA (Trading Community Architecture)?


Ans. Oracle Trading Community Architecture (TCA) is a data model that allows you to manage complex information about the parties, or customers, who belong to your commercial community, including organizations, locations, and the network of hierarchical relationships among them. This information is maintained in the TCA Registry, which is the single source of trading community information for Oracle E-Business Suite applications.
32.
 Difference between Application Developer and System Administrator?


Ans.
Role of Technical Consultant:

a. Designing New Forms, Programs and Reports
b. Forms and Reports customization
c. Developing Interfaces
d. Developing PL/SQL stored procedures
e. Workflow automations
Role of System Administrator:
a. Define Logon Users
b. Define New/Custom Responsibility
c. Define Data Groups
d. Define Concurrent Managers
e. Define Printers
f. Test Network Preferences
g. Define/Add new Modules
Role of an Apps DBA:
a. Installing of Application
b. up gradation
c. Migration
d. Patches
e. Routing maintenance of QA
f. Cloning of OA
33.
 What are Flex fields?


Ans.
Ans. A Flex field is a customizable field that opens in a window from a regular Oracle Applications window. Defining flex fields enables you to tailor Oracle Applications to your own business needs. By using flex fields, you can:
(a) Structure certain identifiers required by oracle applications according to your own business environment.
(b) Collect and display additional information for your business as needed.
Key Flex fields: You use key flex fields to define your own structure for many of the identifiers required by Oracle Applications. Profile – ‘Flexfields:Open Key Window’ (FND_ID_FLEXS)
Descriptive Flex field: You use descriptive flex fields to gather additional information about your business entities beyond the information required by Oracle Applications. Profile – Flex fields: Open Descr Window’ (FND_DESCRIPTIVE_FLEXS)

34.
 Report registration process?


Ans.
1. Create the report using the report builder.
2. Place the report definition file in the module specific reports directory.
3. Create an executable for the report definition file.
4. Create a concurrent program to that executable.
5. Associate the concurrent program to a request group.

35.
 Define Request Group?


Ans.
A request security group is the collection of requests, request sets, and concurrent programs that a user, operating under a given responsibility, can select from the Submit Requests window.

36.
 Value Sets?


Ans.
Oracle Application Object Library uses values, value sets and validation tables as important components of key flex fields, descriptive flex fields, Flex Builder, and Standard Request Submission.
When you first define your flex fields, you choose how many segments you want to use and what order you want them to appear. You also choose how you want to validate each of your segments. The decisions you make affect how you define your value sets and your values.
You define your value sets first, either before or while you define your flex field
segment structures. You typically define your individual values only after your flex field has been completely defined (and frozen and compiled). Depending on what type of value set you use, you may not need to predefine individual values at all before you can use your flex field.
You can share value sets among segments in different flex fields, segments in
different structures of the same flex field, and even segments within the same flex field structure. You can share value sets across key and descriptive flex fields. You can also use value sets for report parameters for your reports that use the Standard Report Submission feature.
Navigation Path:
Login – Application Developer -> Application -> Validation -> Set

37.
 Value Validation Types?


Ans.
1. Dependant
2. Independent
3. None
4. Pair
5. Special
6. Table
7. Translate Independent
8. Translate Dependent

38.
 Incompatibility in report registration and Run Alone?


Ans.
Identify programs that should not run simultaneously with your concurrent program because they might interfere with its execution. You can specify your program as being incompatible with itself.
Application: Although the default for this field is the application of your concurrent program, you can enter any valid application name.
Name: The program name and application you specify must uniquely identify a
concurrent program. Your list displays the user-friendly name of the program, the short name, and the description of the program.
Scope: Enter Set or Program Only to specify whether your concurrent program is zincompatible with this program and all its child requests (Set) or only with this program (Program Only).
Run Alone: Indicate whether your program should run alone relative to all other programs in the same logical database. If the execution of your program interferes with the execution of all other programs in the same logical database (in other words, if your program is incompatible with all programs in its logical database, including itself), it should run alone.

PLSQL PROGRAMS TO PRACTICE1

1) WRITE A PROGRAM TO PRINT HELLO WORLD

BEGIN
DBMS_OUTPUT.PUT_LINE ('HELLO WORLD');
END;
/

2) WRITE A PROGRAM TO PRINT EVEN NUMBERS FROM 1 TO 100

DECLARE
N NUMBER(3) :=0;
BEGIN
WHILE N<=100
LOOP
N :=N+2;
DBMS_OUTPUT.PUT_LINE(N);
END LOOP;
END;
/

3) WRITE A PROGRAM TO FIND SUM OF NUMBERS FROM 1 TO 100

DECLARE
N NUMBER(3):=1;
S NUMBER(4):=0;
BEGIN
WHILE N<=100
LOOP
S := S+N;
N :=N+1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('THE SUM IS '||S);
END;

4) WRITE A PROGRAM TO ACCEPT A NUMBER AND FIND SUM OF THE DIGITS

DECLARE
N NUMBER(5):=&N;
S NUMBER:=0;
R NUMBER(2):=0;
BEGIN
WHILE N !=0
LOOP
R:=MOD(N,10);
S:=S+R;
N:=TRUNC(N/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE('SUM OF DIGITS OF GIVEN NUMBER IS '||S);
END;
/

5) Write a program to accept a number and print it in reverse order

DECLARE
N NUMBER(5):=&N;
REV NUMBER(5):=0;
R NUMBER(5):=0;
BEGIN
WHILE N !=0
LOOP
R:=MOD(N,10);
REV:=REV*10+R;
N:=TRUNC(N/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE('THE REVERSE OF A GIVEN NUMBER IS '||REV);
END;
/

6) Write a program accept the value of A,B&C display which is greater

DECLARE
A NUMBER(4,2):=&A;
B NUMBER(4,2):=&B;
C NUMBER(4,2):=&C;
BEGIN
IF (A>B AND A>C) THEN
DBMS_OUTPUT.PUT_LINE('A IS GREATER '||''||A);
ELSIF B>C THEN
DBMS_OUTPUT.PUT_LINE('B IS GREATE '||''||B);
ELSE
DBMS_OUTPUT.PUT_LINE('C IS GREATER '||''||C);
END IF;
END;
/

7) Write a program accept a string and check whether it is palindrome or not

DECLARE
S VARCHAR2(10):='&S';
L VARCHAR2(20);
TEMP VARCHAR2(10);
BEGIN
FOR I IN REVERSE 1..LENGTH(S)
LOOP
L:=SUBSTR(S,I,1);
TEMP:=TEMP||''||L;
END LOOP;
IF TEMP=S THEN
DBMS_OUTPUT.PUT_LINE(TEMP ||''||' IS PALINDROME');
ELSE
DBMS_OUTPUT.PUT_LINE(TEMP ||''||' IS NOT PALINDROME');
END IF;
END;
/

8) WAP to accept the empno and display all the details of emp. If emp does not exist display the message

DECLARE
EMPNOV NUMBER:=&EMPNO;
EMPV EMP%ROWTYPE;
BEGIN
SELECT * INTO EMPV FROM EMP WHERE EMPNO=EMPNOV;
DBMS_OUTPUT.PUT_LINE('EMPNO '||EMPV.EMPNO);
DBMS_OUTPUT.PUT_LINE('ENAME '||EMPV.ENAME);
DBMS_OUTPUT.PUT_LINE('JOB '||EMPV.JOB);
DBMS_OUTPUT.PUT_LINE('SALARY '||EMPV.SAL);
DBMS_OUTPUT.PUT_LINE('HIREDATE '||EMPV.HIREDATE);
DBMS_OUTPUT.PUT_LINE('DEPTNO '||EMPV.DEPTNO);
DBMS_OUTPUT.PUT_LINE('MGRNO '||EMPV.MGR);
DBMS_OUTPUT.PUT_LINE('COMMISSION '||EMPV.COMM);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('EMP NUMBER DOES NOT EXIST');
END;
/

9) Write a program to accept the grade and display emps belongs to that grade?

DECLARE
GRADEV SALGRADE.GRADE%TYPE:=&GRADE;
CURSOR A IS
SELECT EMP.*,GRADE FROM EMP,SALGRADE WHERE SAL BETWEEN LOSAL AND HISAL AND GRADE=GRADEV;
B A%ROWTYPE;
BEGIN
OPEN A;
LOOP
FETCH A INTO B;
EXIT WHEN A%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);
DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);
DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);
DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);
DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);
DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);
DBMS_OUTPUT.PUT_LINE('GRADE IS ' || B.GRADE);
DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);
DBMS_OUTPUT.PUT_LINE('*************************');
END LOOP;
CLOSE A;
END;
/

10) Write a program to accept a deptno and display who are working in that dept?

DECLARE
DEPTV EMP.DEPTNO%TYPE:=&DEPTNO;
CURSOR A IS
SELECT * FROM EMP WHERE DEPTNO=DEPTV;
B A%ROWTYPE;
BEGIN
OPEN A;
LOOP
FETCH A INTO B;
EXIT WHEN A%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);
DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);
DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);
DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);
DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);
DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);
DBMS_OUTPUT.PUT_LINE('DEPTNO IS ' || B.DEPTNO);
DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);
DBMS_OUTPUT.PUT_LINE('*************************');
END LOOP;
CLOSE A;
END;
/

11) Write a program to display all the information of emp table?

DECLARE
CURSOR A IS
SELECT * FROM EMP;
B A%ROWTYPE;
BEGIN
OPEN A;
LOOP
FETCH A INTO B;
EXIT WHEN A%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);
DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);
DBMS_OUTPUT.PUT_LINE('SAL IS ' || B.SAL);
DBMS_OUTPUT.PUT_LINE('MGR NO IS ' || B.MGR);
DBMS_OUTPUT.PUT_LINE('COMM IS ' || B.COMM);
DBMS_OUTPUT.PUT_LINE('HIREDATE IS ' || B.HIREDATE);
DBMS_OUTPUT.PUT_LINE('DEPTNO IS ' || B.DEPTNO);
DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);
DBMS_OUTPUT.PUT_LINE('*************************');
END LOOP;
CLOSE A;
END;
/

12) Write a program to accept a range of salary (that is lower boundary and higher boundary) and print the details of emps along with loc,grade and exp?

DECLARE
LOSALV SALGRADE.LOSAL%TYPE:=&LOSAL;
HISALV SALGRADE.HISAL%TYPE:=&HISAL;
EXP NUMBER(5,2);
CURSOR A IS
SELECT EMP.*,LOC,GRADE FROM EMP,DEPT,SALGRADE WHERE EMP.DEPTNO=DEPT.DEPTNO
AND SAL BETWEEN LOSALV AND HISALV
AND SAL BETWEEN LOSAL AND HISAL;
B A%ROWTYPE;
BEGIN
OPEN A;
LOOP
FETCH A INTO B;
EXIT WHEN A%NOTFOUND;
EXP:=MONTHS_BETWEEN(SYSDATE,B.HIREDATE)/12;
DBMS_OUTPUT.PUT_LINE('EMP NO IS ' || B.EMPNO);
DBMS_OUTPUT.PUT_LINE('ENAME IS ' || B.ENAME);
DBMS_OUTPUT.PUT_LINE('EMP JOB IS ' || B.JOB);
DBMS_OUTPUT.PUT_LINE('LOC IS ' || B.LOC);
DBMS_OUTPUT.PUT_LINE('EXP IS ' || EXP);
DBMS_OUTPUT.PUT_LINE('GRADE IS ' || B.GRADE);
DBMS_OUTPUT.PUT_LINE('*************************');
END LOOP;
CLOSE A;
END;
/

13) Write a function to accept the empno and return exp with minimum 3 decimal?

CREATE OR REPLACE FUNCTION E_DETAILS(EMPNOV NUMBER) RETURN NUMBER
IS
HIREDATEV EMP.HIREDATE%TYPE;
EXP NUMBER(6,3);
BEGIN
SELECT HIREDATE INTO HIREDATEV FROM EMP WHERE EMPNO=EMPNOV;
EXP:=MONTHS_BETWEEN(SYSDATE,HIREDATEV)/12;
RETURN EXP;
END;
/

14) Write a database trigger halt the transaction on Sunday on EMP table

CREATE OR REPLACE TRIGGER SUN_TRI
AFTER INSERT OR UPDATE OR DELETE ON EMP
DECLARE
DY VARCHAR2(200);
BEGIN
DY:=TO_CHAR(SYSDATE,'DY');
IF DY='SUN' THEN
RAISE_APPLICATION_ERROR(-20005,'TODAY IS SUNDAY TRANSACTION NOT ALLOWED TODAY');
END IF;
END;
/

15) Write a database trigger halt the transaction of USER SCOTT on table EMP

CREATE OR REPLACE TRIGGER SCOTT_TRI
BEFORE INSERT OR UPDATE OR DELETE ON EMP
BEGIN
IF USER = 'SCOTT' THEN
RAISE_APPLICATION_ERROR(-20006,'TRANSACTION NOT ALLOWED FOR SCOTT');
END IF;
END;
/



16) Write a database trigger stroe the username ,type of transaction ,date of transaction and time of transaction of table emp into the table EMP_LOG

CREATE OR REPLACE TRIGGER TRANS_TYPE
AFTER INSERT OR UPDATE OR DELETE ON EMP
DECLARE
V VARCHAR2(50);
BEGIN
IF INSERTING THEN
V:='I';
ELSIF UPDATING THEN
V:='U';
ELSE
V:='D';
END IF;
INSERT INTO EMP_LOG VALUES (USER,V,SYSDATE,TO_CHAR(SYSDATE,'HH:MI:SS'));
END;
/


17) Write a database trigger store the deleted data of EMP table in EMPDEL table

CREATE OR REPLACE TRIGGER DEL_TRI
BEFORE DELETE ON EMP
FOR EACH ROW
BEGIN
INSERT INTO EMPDEL
VALUES (:OLD.EMPNO,:OLD.ENAME,:OLD.JOB,:OLD.MGR,:OLD.HIREDATE,:OLD.SAL,:OLD.COMM,
:OLD.DEPTNO,SYSDATE,TO_CHAR(SYSDATE,'HH:MI:SS));
END;
/

18) Write a database trigger halt the transaction of EMP table if the deptno is does not exist in the dept table

CREATE OR REPLACE TRIGGER DEPT_NO
BEFORE INSERT OR UPDATE OR DELETE ON EMP
FOR EACH ROW
DECLARE
DNO NUMBER:=0;
BEGIN
SELECT COUNT(*) INTO DNO FROM DEPT WHERE DEPTNO=:NEW.DEPTNO;
DBMS_OUTPUT.PUT_LINE(DNO);
IF DNO=0 THEN
RAISE_APPLICATION_ERROR(-20009,'DEPTNO NOT EXIST IN DEPT TABLE....');
END IF;
END;
/


PLSQL LEARNING CLASS9



DATABASE TRIGGERS

Triggers are similar to procedures or functions in that they are named PL/SQL blocks with declarative, executable, and exception handling sections. A trigger is executed implicitly whenever the triggering event happens. The act of executing a trigger is known as firing the trigger.

RESTRICTIONS ON TRIGGERES

  • Like packages, triggers must be stored as stand-alone objects in the database and cannot be local to a block or package.
  • A trigger does not accept arguments.

USE OF TRIGGERS

  • Maintaining complex integrity constraints not possible through declarative constraints enable at table creation.
  • Auditing information in a table by recording the changes made and who made them.
  • Automatically signaling other programs that action needs to take place when chages are made to a table.
  • Perform validation on changes being made to tables.
  • Automate maintenance of the database.

TYPES OF TRIGGERS

  • DML Triggers
  • Instead of Triggers
  • DDL Triggers
  • System Triggers
  • Suspend Triggers

CATEGORIES

Timing -- Before or After
Level -- Row or Statement
Row level trigger fires once for each row affected by the triggering statement. Row level trigger is identified by the FOR EACH ROW clause.
Statement level trigger fires once either before or after the statement.

DML TRIGGER SYNTAX

Create or replace trigger <trigger_name>
Before | after on insert or update or delete
[For each row]
Begin
-- trigger body
End <trigger_name>;

DML TRIGGERS

A DML trigger is fired on an INSERT, UPDATE, or DELETE operation on a database table. It can be fired either before or after the statement executes, and can be fired once per affected row, or once per statement.
The combination of these factors determines the types of the triggers. These are a total of 12 possible types (3 statements * 2 timing * 2 levels).

ORDER OF DML TRIGGER FIRING

  • Before statement level
  • Before row level
  • After row level
  • After statement level

Ex:
Suppose we have a follwing table.

SQL> select * from student;

NO NAME MARKS
----- ------- ----------
1 a 100
2 b 200
3 c 300
4 d 400

Also we have triggering_firing_order table with firing_order as the field.

CREATE OR REPLACE TRIGGER TRIGGER1
before insert on student
BEGIN
insert into trigger_firing_order values('Before Statement Level');
END TRIGGER1;

CREATE OR REPLACE TRIGGER TRIGGER2
before insert on student
for each row
BEGIN
insert into trigger_firing_order values('Before Row Level');
END TRIGGER2;

CREATE OR REPLACE TRIGGER TRIGGER3
after insert on student
BEGIN
insert into trigger_firing_order values('After Statement Level');
END TRIGGER3;

CREATE OR REPLACE TRIGGER TRIGGER4
after insert on student
for each row
BEGIN
insert into trigger_firing_order values('After Row Level');
END TRIGGER4;

Output:

SQL> select * from trigger_firing_order;

no rows selected

SQL> insert into student values(5,'e',500);

1 row created.

SQL> select * from trigger_firing_order;

FIRING_ORDER
--------------------------------------------------
Before Statement Level
Before Row Level
After Row Level
After Statement Level

SQL> select * from student;

NO NAME MARKS
---- -------- ----------
1 a 100
2 b 200
3 c 300
4 d 400
5 e 500

CORRELATION IDENTIFIERS IN ROW-LEVEL TRIGGERS

Inside the trigger, you can access the data in the row that is currently being processed. This is accomplished through two correlation identifiers - :old and :new.

A correlation identifier is a special kind of PL/SQL bind variable. The colon in front of each indicates that they are bind variables, in the sense of host variables used in embedded PL/SQL, and indicates that they are not regular PL/SQL variables. The PL/SQL compiler will treat them as records of type
Triggering_table%ROWTYPE.

Although syntactically they are treated as records, in reality they are not. :old and :new are also known as pseudorecords, for this reason.

TRIGGERING STATEMENT :OLD :NEW
-------------------------------------- ---------------------------- -----------------------------------------------
INSERT all fields are NULL. values that will be inserted
When the statement is completed.

UPDATE original values for new values that will be updated
the row before the when the statement is completed.
update.
DELETE original values before all fields are NULL.
the row is deleted.

Ex:
Suppose we have a table called marks with fields no, old_marks, new_marks.

CREATE OR REPLACE TRIGGER OLD_NEW
before insert or update or delete on student
for each row
BEGIN
insert into marks values(:old.no,:old.marks,:new.marks);
END OLD_NEW;

Output:

SQL> select * from student;

NO NAME MARKS
----- ------- ----------
1 a 100
2 b 200
3 c 300
4 d 400
5 e 500

SQL> select * from marks;

no rows selected

SQL> insert into student values(6,'f',600);

1 row created.

SQL> select * from student;

NO NAME MARKS
---- -------- ----------
1 a 100
2 b 200
3 c 300
4 d 400
5 e 500
6 f 600

SQL> select * from marks;

NO OLD_MARKS NEW_MARKS
---- --------------- ---------------
600

SQL> update student set marks=555 where no=5;

1 row updated.

SQL> select * from student;

NO NAME MARKS
----- ------- ----------
1 a 100
2 b 200
3 c 300
4 d 400
5 e 555
6 f 600

SQL> select * from marks;

NO OLD_MARKS NEW_MARKS
------ ---------------- ---------------
600
5 500 555
SQL> delete student where no = 2;

1 row deleted.

SQL> select * from student;

NO NAME MARKS
---- -------- ----------
1 a 100
3 c 300
4 d 400
5 e 555
6 f 600

SQL> select * from marks;

NO OLD_MARKS NEW_MARKS
----- -------------- ----------------
600
5 500 555
2 200

REFERENCING CLAUSE

If desired, you can use the REFERENCING clause to specify a different name for :old ane :new. This clause is found after the triggering event, before the WHEN clause.

Syntax:
REFERENCING [old as old_name] [new as new_name]

Ex:
CREATE OR REPLACE TRIGGER REFERENCE_TRIGGER
before insert or update or delete on student
referencing old as old_student new as new_student
for each row
BEGIN
insert into marks
values(:old_student.no,:old_student.marks,:new_student.marks);
END REFERENCE_TRIGGER;

WHEN CLAUSE

WHEN clause is valid for row-level triggers only. If present, the trigger body will be executed only for those rows that meet the condition specified by the WHEN clause.

Syntax:
WHEN trigger_condition;

Where trigger_condition is a Boolean expression. It will be evaluated for each row. The :new and :old records can be referenced inside trigger_condition as well, but like REFERENCING, the colon is not used there. The colon is only valid in the trigger body.

Ex:
CREATE OR REPLACE TRIGGER WHEN_TRIGGER
before insert or update or delete on student
referencing old as old_student new as new_student
for each row
when (new_student.marks > 500)
BEGIN
insert into marks
values(:old_student.no,:old_student.marks,:new_student.marks);
END WHEN_TRIGGER;

TRIGGER PREDICATES

There are three Boolean functions that you can use to determine what the operation is.
The predicates are

  • INSERTING
  • UPDATING
  • DELETING
Ex:

CREATE OR REPLACE TRIGGER PREDICATE_TRIGGER
before insert or update or delete on student
BEGIN
if inserting then
insert into predicates values('I');
elsif updating then
insert into predicates values('U');
elsif deleting then
insert into predicates values('D');
end if;
END PREDICATE_TRIGGER;

Output:

SQL> delete student where no=1;

1 row deleted.

SQL> select * from predicates;

MSG
---------------
D

SQL> insert into student values(7,'g',700);

1 row created.

SQL> select * from predicates;

MSG
---------------
D
I

SQL> update student set marks = 777 where no=7;

1 row updated.

SQL> select * from predicates;


MSG
---------------
D
I
U

INSTEAD-OF TRIGGERS

Instead-of triggers fire instead of a DML operation. Also, instead-of triggers can be defined only on views. Instead-of triggers are used in two cases:

  • To allow a view that would otherwise not be modifiable to be modified.
  • To modify the columns of a nested table column in a view.