Sunteți pe pagina 1din 27

1)interfaces(data is comes into the oracle system and goes out to the legacy system

based on need.)
The interfaces are mainly used to either transfer data from Oracle Applications to a flat
file
or data from legacy system to Oracle Applications.
R12 to 11i
--> inbound interface(example :-download data from 11i)

1. Extract data from legacy system into a flat file.


2. Use SQL*Loader or equivalent tool to upload information into a temporary table.
3. Write a PL/SQL program to take data from the temp table and insert into the

Open Interface Tables.


4. Through the concurrent manager in Oracle Applications, run the standard Oracle
Interface program to transform interface tables into Oracle data.

-->Outbound Interfaces(example :- uploading of data into 11i)


An outbound interface takes data from Oracle tables and inserts it into an external
system (via tables or flat file).
1. Write a PL/SQL program to extract data from Oracle base tables into a flat file.
2. Use a custom program to read that data and post it into the legacy system

1] Identification:
Find out if the api to use

2] Creation of Pre-Interface table ( staging Table):


A table in the format of the data file which can be pruned to load as clean a data into the
Interface table.
3] Load data into Pre-Interface table:
SQL*LOADER can be used to load the flat file into the pre-interface table.
4] Validate data in the Pre-Interface table:
Basic validation of the data loaded into the Pre-Interface table can be carried out like:

For checking NULL values in required columns

Duplication Validation

Business Rule validation

5] Mapping the values:


Generated fields in Oracle Applications can be mapped in this step to either default
values or sequences.
6] Load data into Interface table:

Once the data is as clean as you can get it, the data can be inserted into the
Interface table.
7] Run the interface program
8] Check for Errors

2 p_datetrack_update_mode
Value
UPDATE
CORRECTION
UPDATE_OVERRIDE
UPDATE_CHANGE_INSERT

Description
Keep history of existing information
Correct existing information
Replace all scheduled changes
Insert this change before next scheduled chang

p_datetrack_delete_mode
Value
ZAP
DELETE
FUTURE_CHANGE
DELETE_NEXT_CHANGE
5. USER HOOKS

Description
Completely remove from the database
Set end date to effective date
Remove all scheduled changes
Remove next change

This Hook validates to add father in the contacts. Father is mandatory in the
contacts.
1. Creation of package (if father's name does not exist then application error will be
thrown for an employee)

Hr_Utility.set_message(800,'XXMB_FATHER_CONTACT_ERROR');

2. Register user hook


a. l_hook_package

VARCHAR2 (32) := 'HR_CONTACT_REL_

BK1';
l_hook_procedure
l_call_package

VARCHAR2 (32) := 'CREATE_CONTACT_B';


VARCHAR2 (32) := 'XXMB_HR_CONTACT_REL_BK1';

l_call_procedure

VARCHAR2 (32) := 'CREATE_CONTACT_B';

b. Hr_Api_Hook_Call_Api.create_api_hook_call

c. Hr_Api_User_Hooks_Utility.create_hooks_one_module (l_api_module_id);

3. Check your Hook in hr_api_hooks_call


SELECT * FROM hr_api_hooks_call WHERE CALL_PACKAGE LIKE
Upper(XXMB_HR_CONTACT_REL_BK1);

4. Deletion
Get Hook Call ID and Object Version_number

Select api_hook_call_id,object_version_number from HR_API_HOOK_CALLS where


call_package like 'XXMB_HR_CONTACT_REL_BK1' and call_procedure =
UPPER('Validate_Objectives_Weight')

Hook Deletion
BEGIN
Hr_Api_Hook_Call_Api.delete_api_hook_call (

p_validate

=> FALSE,

p_api_hook_call_id => <Hook Call


ID>,
p_object_version_number =>2
);

DBMS_OUTPUT.PUT_LINE('deleted Successfully');
END;

6. Integration(r12 to 11i)

integration :r12 to 11i

Business scenario :-

Finance module + hrms implemeneted in 11i


HRMS module implemented in R12 .
To keep the data in sync(as employee data is reqd in finance 11i)interface is used.
The Interface will check all the lookup n valuesets b/w the 2
fr eg :1.orgazin created or not
2.position created
3.dff valuesets will b migrated

only personl n assignmnet Data was reqd so only these 2 were migrated.
1. new emp or any update (transfer,supervisor change)

oracle api to move from stage table to custom table


1. last update date compare from control table and base tables
2. the delta empolyees will be changed in 11i

fnd_lookup_values_pkg.insert_row

hr_job_api.create_job
hr_grade_api.create_grade

7. web adi
9. Data Migration/conversion( Example :-The company is acquired or merged with
some other company, and the whole data need to move into the parent or child
company .)
Assignment data, contact data migrated into oracle system
Api used :- dt_api.find_dt_upd_modes,
hr_assignment_api.update_emp_asg_criteria
hr_person_address_api.create_person_address
hr_contact_rel_api.create_contact
hr_employee_api.re_hire_ex_employee
hr_employee_api.create_employee

10. alerts

11. basic OAF FORM personalization in PMS Module

Functionally:-

1. PMS 2. SSHR 3. Succession planning and AME in 4.irecruitment

Process Cycle:-

1. reqmt gathering
2. md50 -functional document
3. technicl
4. md70-technical document
5. technical document review
6. sit -->approval
7. unit tstin -->succesfful -->go live prod instance-->br100(setup define)

version mgmt ?
sharepoint directory ,cvs
check in check out(cannot make changes after check out)
version control, avoids redundancy

oracle Support
csi (cust support identifier)number frm oracle... go to oracle support..customersci no.
goes to custoer admin.. get access to csi....
u cn create sr using tht csi no,

they gv u patches.. solutions etc they give diagnostic scripts

) Difference between

PER_PEOPLE_F and PER_ALL_PEOPLE_F


PER_PEOPLE_F is a secured view on top of PER_ALL_PEOPLE_F.
The secure view uses an API hr_security.show_person.
This API internally checks for an entry in table PER_PERSON_LIST for the logged in
person's security profile.

To define person type


Per_all_people_F,
per_person_types
per_people_usages_f

papf.person_id = pptuf.person_id
and pptuf.person_type_id = ppt.person_type_id
party_id
When an employee is rehired the person_id changes but party_id remains the same in
the oracle apps
Sit
Per_analysis_criteria

Married- 01-nov-2010
1. 01-jan-2010 data -31-dec-2010
2. 01-jan-2011 31-dec-4712

Person_Type_ID in PER_PERSON_TYPE_USAGES_F will correspond to System


Person Type EX_EMP

Sql loader
LOAD DATA
3 INFILE 'sample.dat'
4 BADFILE 'sample.bad'
5 DISCARDFILE 'sample.dsc'
6 APPEND
7 INTO TABLE emp
8 WHEN (57) = '.'
9 TRAILING NULLCOLS
10 (hiredate SYSDATE,
deptno POSITION(1:2) INTEGER EXTERNAL(2)
NULLIF deptno=BLANKS,
job POSITION(7:14) CHAR TERMINATED BY WHITESPACE
NULLIF job=BLANKS "UPPER(:job)",
mgr POSITION(28:31) INTEGER EXTERNAL
TERMINATED BY WHITESPACE, NULLIF mgr=BLANKS,
ename POSITION(34:41) CHAR
TERMINATED BY WHITESPACE "UPPER(:ename)",
empno POSITION(45) INTEGER EXTERNAL
TERMINATED BY WHITESPACE,
sal POSITION(51) CHAR TERMINATED BY WHITESPACE
"TO_NUMBER(:sal,'$99,999.99')",
comm INTEGER EXTERNAL ENCLOSED BY '(' AND '%'
":comm * 100"
)

1. The LOAD DATA statement tells SQL*Loader that this is the beginning of a new
data load.
2. The INFILE clause specifies the name of a data file containing the data you want
to load.
3. The BADFILE clause specifies the name of a file into which rejected records are
placed.
4. The DISCARDFILE clause specifies the name of a file into which discarded
records are placed.
5. The APPEND clause is one of the options you can use when loading data into a
table that is not empty
To load data into a table that is empty, you would use the INSERT clause.
6. The INTO TABLE clause enables you to identify tables, fields, and datatypes. It
defines the relationship between records in the data file and tables in the
database.

7. The WHEN clause specifies one or more field conditions. SQL*Loader decides
whether to load the data based on these field conditions.
8. The TRAILING NULLCOLS clause tells SQL*Loader to treat any relatively
positioned columns that are not present in the record as null columns.
9. The remainder of the control file contains the field list, which provides information
about column formats in the table being loaded.
Bad file
When SQL*Loader executes, it can create a file called a bad file or reject file in which it
places records that were rejected because of formatting errors or because they caused
Oracle errors. If you have specified that a bad file
Discard file
During execution, SQL*Loader can create a discard file for records that do not meet any
of the loading criteria.
Core flexfields are:

Job

Position

Grade

Competency

Validation types:

Dependent

Independent

None

Pair

Special

Table

Proc vs func
1. Procedure can performs one or more tasks where as function performs a
specific task.
2. Procedure may or may not return value where as function should return
one value.
3. we can call functions in select statement where as procedure we cant.
5.A FUNCTION must be part of an executable statement, as it cannot be
executed independently where as procedure represents an independent
executable statement.

6. Function can be called form SQL statement where as procedure can not
be called from the SQL statement.
7. Function are normally used for computation where as procedure are
normally used for executing business logic.
8. Stored procedure supports deferred name resolution where as function
wont support.
9. Stored procedure returns always integer value by default zero. whrer as
function returns type could be scalar or table or table value.
10.Stored procedure is precompiled execution plan where as function are
not.

KFF DFF

ERRBUFF RETCODE
ERRBUFF It return the error message. For you program if you get any error in
exception block you can assign the error message to this parameter. This error
message you can see after concurrent program run go to details button it will
open details in that Completion Text filed will show your errbuf.
This parameter returns the status of the concurrent program.
0- Success --Completed
1- Warning -- Yellow color
2- Error -- Red
p_errbuf

OUT VARCHAR2,

p_retcode OUT NUMBER

Set up bg
Now, go to Global HRMS Manager --> Work Structures ->Organization ->
Description
Specify name of your Business group, select Business group as type and also
select BG location . From Org. Classification, select Business Group , check
Enable Checkbox. Now, Click other --> BG Info
Select your KFFs here and also mention the Employee number generation rule
and Fiscal year date. Close this window.
You may also select GRE/Legal Entity and HR Organization in Org. Classification
list.
Setup hrms
Following are the steps to implement Oracle HRMS,
-- Define Key Flexfields
-- Define Descriptive Flexfields
-- Define Business Group

-- Set required Profile Options


-- Define Location
-- Define Organization
-- Define Grades
-- Define Jobs
-- Define Positions
-- Set required Lookup values
-- Set person type and Assignments type as per requirement
-- Associate Special Informationa with your Responsibility
-- Register Extra Information and associate with your Responsibility

Eit and sit


Language Proficiency,DRIVINGLICENSE
SIT--> Special Information Type
1. This is a KFF
2. This field is date tracked
2. This is value added in this field is available through out the Business group
POSITION AND JOB LEVEL AS WELL
PER_ALL_PEOPLE_F PAPF,
PER_PERSON_ANALYSES PPA,
PER_ANALYSIS_CRITERIA PAC,
FND_ID_FLEX_STRUCTURES FIFL,
PER_ALL_ASSIGNMENTS_F PAAF,
PER_JOBS PJ
WHERE
PAPF.PERSON_ID = PPA.PERSON_ID
AND PAC.ANALYSIS_CRITERIA_ID = PPA.ANALYSIS_CRITERIA_ID
AND PAC.ID_FLEX_NUM = PPA.ID_FLEX_NUM
AND PAC.ID_FLEX_NUM = FIFL.ID_FLEX_NUM
EIT--> Extra Information Type
1. This is a DFF field
2. This Field is not date tracked
3. This Field can e restricted and Responsibility level it is more secure than SIT
Pei_information1 pei_information2
http://documents.club-oracle.com/downloads.php?do=file&id=1437

rehire vs reverser termination


rehire new service record though person record may remain the same
reverser continue with same assignment
concurrent prog
o Go to Programs and Define Executables.
o Go to Programs and Define Concurrent Program
o Go to Responsibility and attach the Request group you want.
What are the different types of executable available in Concurrent Programming?
o Host
o Oracle Reports
o PL/SQL Stored Procedures
o SQL*LOADER
o SQL*PLUS
o Spawned
o JSP
1. What are the FlexField Qualifiers?
A Flex field qualifier identifies a particular segment of a key flex field.
Segment Qualifier :- A segment qualifier identifies a particular type of value in a
single segment of a key flexfield.
243)Significance of ALL in apps tables.
Tables which are related with Multiorg is suffixed with ALL.
Profile Levels
Site Level
Application Level
Responsibility Level
User Level
Note: Site Level is the lowest level.
1. Designing New Forms, Programs and Reports
2. Forms and Reports customization
3. Developing Interfaces
4. Developing PL/SQL stored procedures

5. Workflow automations
Role of System Administrator:
1. Define Logon Users
2. Define New/Custom Responsibility
3. Define Data Groups
4. Define Concurrent Managers
5. Define Printers
6. Test Network Preferences
7. Define/Add new Modules
Role of an Apps DBA:
1. Installing of Application
2. Upgradation
3. Migration
4. Patches
5. Routing maintenance of QA
6. Cloning of OA
Interface vs api
Rowid vs rownum
Just as your home address uniquely identifies where you live, an Oracle ROWID
uniquely identifies where a row resides on disk. The information in a ROWID gives
Oracle everything he needs to find your row, the disk number, the cylinder, block and
offset into the block.
The ROWNUM is a "pseudo-column", a placeholder that you can reference in
SQL*Plus. The ROWNUM can be used to write specialized SQL and tune SQL.

What is Value Set?


--The value set is a collection (or) container of values.
--When ever 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.

6) What r 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.
Composite Datatypes :
PL/SQL TABLES / PL/SQL RECORDS / Nested TABLE / VARRAY
What is the sequence of functions group by,having,orderby in a select statements ?
Select..Group byHavingOrderby..
How to call WHO columns into the form
By using FND_STANDARD APIS
1. FND_STANDARD.FORM_INFO 6
What is a Profile Option?
- profile options are the set of changeable options that affects how the application looks
and behaves.
- By setting profile options, the applications can be made to react in different ways for
different users depending on the specific user attributes.
How to submit concurrent program through pl/sql
fnd_request.submit_request(parameters) by using this we can submit the concurrent
program thru pl/sql.
Can you submit a concurrent request from the operating system directly?
Write a Shellscript.
Login to database
Run the function FND_REQUEST.Submit()
FND_GLOBAL.APPS_INITIALIZE (user_id,resp_id, resp_appl_id)
42) What are the types of Concurrent Managers 25

3 MASTER CONCURRENT MANAGERS:


1. Internal Conccurent Manager (ICM): This is the one which monitors all other CMs
2. Standard Manager (SM) : This takes care of report running and batch jobs
3. Conflict Resolution Manager (CRM): checks concurrent program definitions for
incompatability checks.
We cannot delete a concurrent manager... but we can disable it... but
it's not recommended.
How to submit concurrent program through l/sql
fnd_request.submit_request(parameters) by using this we can submit the concurrent
program thru pl/sql.
FND_GLOBAL.APPS_INITIALIZE (user_id,resp_id, resp_appl_id)

106)Why we use token field for Concurrent program?


Ans: The Token is used as for binding purpose. The parameter value is passed to the
.rdf/procedure through this token. The input (user) parameter value passes to the
report / stored procedure after binding with this token. The concurrent program won t
get impact even the user parameter names get changed, but got impacted when the
token name changed.
107) What are the mandatory parameters in concurrent programs?
Ans: errbuf
errcode.
108)Those are IN or OUT parameters.
Ans: Out Parameters
10)
Truncate vvs delete
>TRUNCATE is a DDL command whereas DELETE is a DML command.
2>TRUNCATE is much faster than DELETE.
Reason:When you type DELETE.all the data get copied into the Rollback Tablespace
first.then delete operation get performed.Thatswhy when you type ROLLBACK after
deleting a table ,you can get back the data(The system get it for you from the Rollback
Tablespace).All this process take time.But when you type TRUNCATE,it removes data
directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is
faster.Once you Truncate you cann't get back the data.

3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE


removes the record permanently.
4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like
DELETE .Trigger get fired.
5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can
write conditions using WHERE clause
13)Can we use truncate and delete command to disable the referential integrity
constraint
Referential integrity is a relational database concept in which multiple tables share a
relationship based on the data stored in the tables, and that relationship must remain
consistent.
The concept of referential integrity, and one way in which its enforced, is best illustrated
by an example. Suppose company X has 2 tables, an Employee table, and an
Employee Salary table. In the Employee table we have 2 columns the employee ID
and the employee name. In the Employee Salary table, we have 2 columns the
employee ID and the salary for the given ID.

Now, suppose we wanted to remove an employee because he no longer works at


company X. Then, we would remove his entry in the Employee table. Because he also
exists in the Employee Salary table, we would also have to manually remove him from
there also. Manually removing the employee from the Employee Salary table can
become quite a pain. And if there are other tables in which Company X uses that
employee then he would have to be deleted from those tables as well an even bigger
pain.
By enforcing referential integrity, we can solve that problem, so that we wouldnt have to
manually delete him from the Employee Salary table (or any others). Heres how: first
we would define the employee ID column in the Employee table to be our primary key.
Then, we would define the employee ID column in the Employee Salary table to be a
foreign key that points to a primary key that is the employee ID column in the Employee
table. Once we define our foreign to primary key relationship, we would need to add
whats called a constraint to the Employee Salary table. The constraint that we would
add in particular is called a cascading delete this would mean that any time an
employee is removed from the Employee table, any entries that employee has in the
Employee Salary table would alsoautomatically be removed from the Employee Salary
table.
Note in the example given above that referential integrity is something that must
beenforced, and that we enforced only one rule of referential integrity (the cascading
delete). There are actually 3 rules that referential integrity enforces:

1.We may not add a record to the Employee Salary table


unless the foreign key for that record points to an existing
employee in the Employee table.
2.If a record in the Employee table is deleted, all corresponding
records in the Employee Salary table must be deleted using a
cascading delete. This was the example we had given earlier.
3.If the primary key for a record in the Employee table changes,
all corresponding records in the Employee Salary table must be
modified using what's called a cascading update.

You cannot truncate the parent table of an enabled foreign key constraint. You must
disable the constraint before truncating the table. An exception is that you can truncate
the table if the integrity constraint is self-referential.
This is presumably because truncate is DDL and doesn't do any checks on data in the
target table, even to see if it has any rows. It would have to do that DML, and look for
any matching rows in all child tables (or at least check there are no rows), etc, which
would change the nature of the command and potentially impact performance. And it
would have to consider uncommitted transactions against the child tables, which would
have expected an error on insert rather than commit if the constraint wasn't defferred.

18 WHAT IS A VIEW IN ORACLE?


An Oracle VIEW, in essence, is a virtual table that does not physically exist. Rather, it is created
by a query joining one or more tables.
CREATE VIEW
Syntax
The syntax for the Oracle CREATE VIEW Statement is:
CREATE VIEW view_name AS
SELECT columns
FROM tables
WHERE conditions;
view_name is the name of the Oracle VIEW that you wish to create.

Example
Here is an example of how to use the Oracle CREATE VIEW:
CREATE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Microsoft';
This Oracle CREATE VIEW example would create a virtual table based on the result set of the
SELECT statement. You can now query the Oracle VIEW as follows:
SELECT *
FROM sup_orders;
UPDATE VIEW
You can modify the definition of an Oracle VIEW without dropping it by using the Oracle
CREATE OR REPLACE VIEW Statement.
Syntax
The syntax for the Oracle CREATE OR REPLACE VIEW Statement is:
CREATE OR REPLACE VIEW view_name AS
SELECT columns
FROM table
WHERE conditions;
Example
Here is an example of how you would use the Oracle CREATE OR REPLACE VIEW Statement:
CREATE or REPLACE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price

FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Apple';
This Oracle CREATE OR REPLACE VIEW example would update the definition of the Oracle
VIEW called sup_orders without dropping it. If the Oracle VIEW did not yet exist, the VIEW
would merely be created for the first time.
DROP VIEW
Once an Oracle VIEW has been created, you can drop it with the Oracle DROP VIEW
Statement.
Syntax
The syntax for the Oracle DROP VIEW Statement is:
DROP VIEW view_name;
view_name is the name of the view that you wish to drop.
Example
Here is an example of how to use the Oracle DROP VIEW Statement:
DROP VIEW sup_orders;
This Oracle DROP VIEW example would drop/delete the Oracle VIEW called sup_orders.
FREQUENTLY ASKED QUESTIONS
Question: Can you update the data in an Oracle VIEW?
Answer: A VIEW in Oracle is created by joining one or more tables. When you update record(s)
in a VIEW, it updates the records in the underlying tables that make up the View.
So, yes, you can update the data in an Oracle VIEW providing you have the proper privileges to
the underlying Oracle tables.

Question: Does the Oracle View exist if the table is dropped from the database?
Answer: Yes, in Oracle, the VIEW continues to exist even after one of the tables (that the Oracle
VIEW is based on) is dropped from the database. However, if you try to query the Oracle VIEW
after the table has been dropped, you will receive a message indicating that the Oracle VIEW has
errors.
If you recreate the table (the table that you had dropped), the Oracle VIEW will again be fine.

19) materialized view


Materialized views are an Oracle Silver Bullet when pre-joining tables together for super-fast
response time.
One issue with highly-normalized, non-redundant Oracle table designs (e.g. third normal form) is
that Oracle experiences a high degree of overhead (especially CPU consumption) when joining
dozens of tables together, over-and-over again, and partitioning may help.
Using materialized views we pre-join the tables together, resulting in a single, fat, wide and
highly-redundant table.
This can reduce logical I/O from tens of thousands to a single row fetch, resulting in blisteringly
fast response time, but careful attention must be paid to choosing the proper materialized view
partition keys and the best refresh interval.
Without materialized views you may see unnecessary repeating large-table full-table scans, as
summaries are computed, over and over:
Define PL/SQL Placeholders
Depending on the kind of data you want to store, you can define placeholders with a name and a
datatype. Few of the datatypes used to define placeholders are as given below.
Number (n,m) , Char (n) , Varchar2 (n) , Date , Long , Long raw, Raw, Blob, Clob, Nclob, Bfile
PL/SQL Variables
These are placeholders that store the values that can change through the PL/SQL Block.
General Syntax to declare a variable is
variable_name datatype [NOT NULL := value ];

variable_name is the name of the variable.

datatype is a valid PL/SQL datatype.

NOT NULL is an optional specification on the variable.

value or DEFAULT valueis also an optional specification, where you can initialize a
variable.

Each variable declaration is a separate statement and must be terminated by a semicolon.

For example, if you want to store the current salary of an employee, you can use a variable.
DECLARE
salary number (6);
* salary is a variable of datatype number and of length 6.
When a variable is specified as NOT NULL, you must initialize the variable when it is declared.
For example: The below example declares two variables, one of which is a not null.
DECLARE
salary number(4);
dept varchar2(10) NOT NULL := HR Dept;
The value of a variable can change in the execution or exception section of the PL/SQL Block.
We can assign values to variables in the two ways given below.
1) We can directly assign values to variables.
The General Syntax is:
variable_name:= value;
2) We can assign values to variables directly from the database columns by using a SELECT..
INTO statement. The General Syntax is:
SELECT column_name
INTO variable_name
FROM table_name
[WHERE condition];
Example: The below program will get the salary of an employee with id '1116' and display it on
the screen.
DECLARE
var_salary number(6);
var_emp_id number(6) = 1116;
BEGIN
SELECT salary
INTO var_salary
FROM employee
WHERE emp_id = var_emp_id;
dbms_output.put_line(var_salary);
dbms_output.put_line('The employee '
|| var_emp_id || ' has salary ' || var_salary);
END;
/

NOTE: The backward slash '/' in the above program indicates to execute the above
PL/SQL Block.
Scope of PS/SQL Variables
PL/SQL allows the nesting of Blocks within Blocks i.e, the Execution section of an outer block
can contain inner blocks. Therefore, a variable which is accessible to an outer Block is also
accessible to all nested inner Blocks. The variables declared in the inner blocks are not accessible
to outer blocks. Based on their declaration we can classify variables into two types.

Local variables - These are declared in a inner block and cannot be referenced by outside
Blocks.

Global variables - These are declared in a outer block and can be referenced by its itself
and by its inner blocks.

For Example: In the below example we are creating two variables in the outer block and
assigning thier product to the third variable created in the inner block. The variable 'var_mult' is
declared in the inner block, so cannot be accessed in the outer block i.e. it cannot be accessed
after line 11. The variables 'var_num1' and 'var_num2' can be accessed anywhere in the block.
1> DECLARE
2> var_num1 number;
3> var_num2 number;
4> BEGIN
5> var_num1 := 100;
6> var_num2 := 200;
7> DECLARE
8> var_mult number;
9> BEGIN
10> var_mult := var_num1 * var_num2;
11> END;
12> END;
13> /
.
21 ) What is a table, view, snapshot?
Table: A table is the basic unit of data storage in an Oracle database. The tables of a database
hold all of the user accessible data. Table data is stored in rows and columns.a
Views: A view is a virtual table. Every view has a query attached to it. (The query is a SELECT
statement that identifies the columns and rows of the table(s) the view uses.) Snapshot: A

Snapshot is a recent copy of a table from database or in some cases ,a subset of rows/columns of
a table. It is also known as Materialized view. 9.Do a view contain data?
Ans: Views do not contain or store data What are the advantages of views? Ans: Provide an
additional level of table security, by restricting access to a predetermined set of rows and
columns of a table. - Hide data complexity. - Simplify commands for the user. - Present the data
in a different perspective from that of the base table. - Store complex queries.

22) What is a synonym? Ans: A synonym is an alias for a table, view, sequence or program unit.

12.What are the types of synonyms?


Ans: There are two types of synonyms private and public.
13.What is a private synonym? Ans: Only its owner can access a private synonym.
14.What is a public synonym? Ans: Any database user can access a public synonym
15.What is an Oracle index? Ans: An index is an optional structure associated with a table to
have direct access to rows, which can be created to increase the performance of data retrieval.
Index can be created on one or more columns of a table. Index may also be considered as a
ordered list of content of a column.
16.What is a schema? Ans: The set of objects owned by user account is called the schema.
24) Difference between SUBSTR and INSTR?
Ans: INSTR (String1, String2 (n, (m)), INSTR returns the position of the m-th occurrence of the
string 2 in string1. The search begins from nth position of string1. SUBSTR (String1 n, m)
SUBSTR returns a character string of size m in string1, starting from n-th position of string1.
19.What is difference between CHAR and VARCHAR2?
What is the maximum SIZE allowed for each type? Ans: CHAR pads blank spaces to the
maximum length. VARCHAR2 does not pad blank spaces. For CHAR the maximum length is
255 and 2000 for VARCHAR2
20.How to access the current value and next value from a sequence? Ans: Current Value :
Sequence name.CURRVAL Next Value sequence name.NEXTVAL.

21) What is the difference between alias and synonym ? Ans: Alias is
temporary and used with one query. Synonym is permanent and not used as
alias. Whats the length of SQL integer ? Ans: 32 bit length

22)What is Ref Cursor? Ans: A REF CURSOR is basically a data type. A


variable created based on such a data type is generally called a cursor
variable. A cursor variable can be associated with different queries at runtime. The primary advantage of using cursor variables is their capability to
pass result sets between sub programs (like stored procedures, functions,
packages etc.).
Using Ref Cursors
The example below uses a ref cursor to return a subset of the records in the EMP table.
The following procedure opens a query using a SYS_REFCURSOR output parameter. Notice the
cursor is not closed in the procedure. It is up to the calling code to manage the cursor once it has
been opened.
CREATE OR REPLACE
PROCEDURE get_emp_rs (p_deptno IN emp.deptno%TYPE,
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT ename,
empno,
deptno
FROM emp
WHERE deptno = p_deptno
ORDER BY ename;
END GetEmpRS;
/
The resulting cursor can be referenced from PL/SQL as follows.
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_cursor SYS_REFCURSOR;
l_ename emp.ename%TYPE;
l_empno emp.empno%TYPE;
l_deptno emp.deptno%TYPE;
BEGIN
get_emp_rs (p_deptno => 30,
p_recordset => l_cursor);
LOOP

FETCH l_cursor
INTO l_ename, l_empno, l_deptno;
EXIT WHEN l_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(l_ename || ' | ' || l_empno || ' | ' || l_deptno);
END LOOP;
CLOSE l_cursor;
END;
/
There are 2 basic types: Strong ref cursor and weak ref cursor
For the strong ref cursor the returning columns with datatype and length need to be known at
compile time.
For the weak ref cursor the structure does not need to be known at compile time.

S-ar putea să vă placă și