Beruflich Dokumente
Kultur Dokumente
Method 1:
Will give you a zero if it is a number or greater than zero if not numeric (actually gives
the count of non numeric characters)
Method 2:
select instr(translate('wwww',
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX'),'X')
FROM dual;
Here N = 10
The following query has a Problem of performance in the execution of the following
query where the table ter.ter_master have 22231 records. So the results are obtained after
hours.
What are steps required tuning this query to improve its performance?
Be sure to get familiar with EXPLAIN PLAN. This can help you determine the
execution path that Oracle takes. If you are using Cost Based Optimizer mode, then be
sure that your statistics on TER_MASTER are up-to-date.
Also, you can change your SQL to:
SELECT a.*
FROM ter.ter_master a
WHERE NOT EXISTS (SELECT b.repno FROM ermast b
WHERE a.repno=b.repno) AND
(a.brepno = 'ALL' or a.repno > a.brepno)
ORDER BY a.repno;
3. What is the difference between Truncate and Delete interms of Referential Integrity?
TRUNCATE removes ALL records in a table. It does not execute any triggers.
Also, it only checks for the existence (and status) of another foreign key
Pointing to the table. If one exists and is enabled, then you will get
The following error. This is true even if you do the child tables first.
You should disable the foreign key constraints in the child tables before
issuing the TRUNCATE command, then re-enable them afterwards.
An event trigger, a segment of code which is associated with each event and is fired when
the event occurs.
When a stored procedure is called, only the procedure call is sent to the server and not the
statements that the procedure contains.
An integrity constraint allows the definition of certain restrictions, at the table level, on
the data that is entered into a table.
Database triggers can be used to enforce business rules, to maintain derived values and
perform value-based auditing.
What is a transaction ?
A transaction is a set of operations that begin when the first DML is issued and end when
a commit or rollback is issued. BEGIN COMMIT/ROLLBACK are the boundries of a
transaction.
Why is it better to use an integrity constraint to validate data in a table than to use a
stored procedure ?
.
II. USING RELATIONAL DATABASE :
ORACLE
I. SQL*PLUS :
SQL is an English like language consisting of commands to store, retrieve, maintain &
regulate access to your database.
SQL*PLUS is an application that recognizes & executes SQL commands & specialized
SQL*Plus commands that can customize reports, provide help & edit facility & maintain
system variables.
NVL : Null value function converts a null value to a non-null value for the purpose of
evaluating an expression.
Numeric Functions accept numeric I/P & return numeric values. They are MOD, SQRT,
ROUND, TRUNC & POWER.
Date Functions are ADD_MONTHS, LAST_DAY, NEXT_DAY, MONTHS_BETWEEN
& SYSDATE.
Character Functions are INITCAP, UPPER, LOWER, SUBSTR & LENGTH. Additional
functions are GREATEST & LEAST.
Group Functions returns results based upon groups of rows rather than one result per row,
use group functions. They are AVG, COUNT, MAX, MIN & SUM.
TTITLE & BTITLE are commands to control report headings & footers.
COLUMN command define column headings & format data values.
BREAK command clarify reports by suppressing repeated values, skipping lines &
allowing for controlled break points.
COMPUTE command control computations on subsets created by the BREAK
command.
SET command changes the system variables affecting the report environment.
SPOOL command creates a print file of the report.
JOIN is the form of SELECT command that combines info from two or more tables.
Types of Joins are Simple (Equijoin & Non-Equijoin), Outer & Self join.
Equijoin returns rows from two or more tables joined together based upon a equality
condition in the WHERE clause.
Non-Equijoin returns rows from two or more tables based upon a relationship other than
the equality condition in the WHERE clause.
Outer Join combines two or more tables returning those rows from one table that have no
direct match in the other table.
Self Join joins a table to itself as though it were two separate tables.
Set Operators supported by Oracle are :
Union is the product of two or more tables.
Intersect is the product of two tables listing only the matching rows.
Minus is the product of two tables listing only the non-matching rows.
Correlated Subquery is a subquery that is evaluated once for each row processed by the
parent statement. Parent statement can be Select, Update or Delete. Use CRSQ to answer
multipart questions whose answer depends on the value in each row processed by parent
statement.
Multiple columns can be returned from a Nested Subquery.
Sequences are used for generating sequence numbers without any overhead of locking.
Drawback is that after generating a sequence number if the transaction is rolled back,
then that sequence number is lost.
Synonyms is the alias name for table, views, sequences & procedures and are created for
reasons of Security and Convenience. Two levels are Public - created by DBA &
accessible to all the users. Private - Accessible to creator only. Advantages are
referencing without specifying the owner and Flexibility to customize a more meaningful
naming convention.
Indexes are optional structures associated with tables used to speed query execution
and/or guarantee uniqueness. Create an index if there are frequent retrieval of fewer than
10-15% of the rows in a large table and columns are referenced frequently in the WHERE
clause. Implied tradeoff is query speed vs. update speed. Oracle automatically update
indexes. Concatenated index max. is 16 columns.
Data types :
Max. columns in a table is 255. Max. Char size is 255, Long is 64K & Number is 38
digits.
Cannot Query on a long column.
Char, Varchar2 Max. size is 2000 & default is 1 byte.
Number(p,s) p is precision range 1 to 38, s is scale -84 to 127.
Long Character data of variable length upto 2GB.
Date Range from Jan 4712 BC to Dec 4712 AD.
Raw Stores Binary data (Graphics Image & Digitized Sound). Max. is 255 bytes.
Mslabel Binary format of an OS label. Used primarily with Trusted Oracle.
Order of SQL statement execution : Where clause, Group By clause, Having clause,
Order By clause & Select.
Transaction is defined as all changes made to the database between successive commits.
Commit is an event that attempts to make data in the database identical to the data in the
form. It involves writing or posting data to the database and committing data to the
database. Forms check the validity of the data in fields and records during a commit.
Validity check are uniqueness, consistency and db restrictions.
Posting is an event that writes Inserts, Updates & Deletes in the forms to the database but
not committing these transactions to the database.
Rollback causes work in the current transaction to be undone.
Savepoint is a point within a particular transaction to which you may rollback without
rolling back the entire transaction.
Set Transaction is to establish properties for the current transaction.
Locking are mechanisms intended to prevent destructive interaction between users
accessing data. Locks are used to achieve
Consistency : Assures users that the data they are changing or viewing is not changed
until the are thro' with it.
Integrity : Assures database data and structures reflects all changes made to them in the
correct sequence.
Locks ensure data integrity and maximum concurrent access to data. Commit statement
releases all locks. Types of locks are given below.
Data Locks protects data i.e. Table or Row lock.
Dictionary Locks protects the structure of database object i.e. ensures table's structure
does not change for the duration of the transaction.
Internal Locks & Latches protects the internal database structures. They are automatic.
Exclusive Lock allows queries on locked table but no other activity is allowed.
Share Lock allows concurrent queries but prohibits updates to the locked tables.
Row Share allows concurrent access to the locked table but prohibits for a exclusive table
lock.
Row Exclusive same as Row Share but prohibits locking in shared mode.
Shared Row Exclusive locks the whole table and allows users to look at rows in the table
but prohibit others from locking the table in share or updating them.
Share Update are synonymous with Row Share.
Deadlock is a unique situation in a multi user system that causes two or more users to
wait indefinitely for a locked resource. First user needs a resource locked by the second
user and the second user needs a resource locked by the first user. To avoid dead locks,
avoid using exclusive table lock and if using, use it in the same sequence and use Commit
frequently to release locks.
Mutating Table is a table that is currently being modified by an Insert, Update or Delete
statement.
Constraining Table is a table that a triggering statement might need to read either directly
for a SQL statement or indirectly for a declarative Referential Integrity constraints.
Pseudo Columns behaves like a column in a table but are not actually stored in the table.
E.g. Currval, Nextval, Rowid, Rownum, Level etc.
SQL*Loader is a product for moving data in external files into tables in an Oracle
database. To load data from external files into an Oracle database, two types of input
must be provided to SQL*Loader : the data itself and the control file. The control file
describes the data to be loaded. It describes the Names and format of the data files,
Specifications for loading data and the Data to be loaded (optional). Invoking the loader
sqlload username/password controlfilename <options>
PL/SQL :
Data types are NUMBER, CHAR/VARCHAR2, DATE & BOOLEAN.
Arrays are not allowed & only one identifier per line is allowed.
Attributes of PL/SQL objects are %TYPE, %ROWTYPE.
PL/SQL Block is a standard PL/SQL code segment. Block consists of three parts.
Declarative Section for variables, constants & exceptions. This section is optional.
Executable Section which is mandatory.
Exception Handlers which is optional.
PL/SQL supports only DML i.e. INSERT, UPDATE, DELETE & SELECT...INTO.
SQL Functions can be referenced within a SQL statement i.e. Numeric
(SQRT,ROUND,POWER),
Character (LENGTH,UPPER), DATE (ADD_MONTHS,MONTHS_BETWEEN) &
Group (AVG,MAX,COUNT). Most SQL functions are available outside SQL statement
except for group functions.
Code Simple Loops repeats a sequence of statements multiple times.
Syntax : LOOP
<Sequence of Statements>
END LOOP;
Code Numeric FOR Loops repeat a sequence of statements a fixed number of times.
Syntax : FOR <index> IN [[ REVERSE ]] <integer>..<integer> LOOP
<sequence of statements>
END LOOP;
<index> is implicitly of type number. Defined only within the loop & Value can be
referenced in an expression, but a new value cannot be assigned to the index within the
loop.
Code While Loops repeats a sequence of statements until a specific condition is no longer
TRUE.
Syntax : WHILE <condition> LOOP
<sequence of statements>
END LOOP;
<condition> can be any legal PL/SQL condition & statements will be repeated as long as
condition evaluates to TRUE.
Code GOTO Statements jumps to a different place in the PL/SQL block.
Syntax : GOTO label_name;
Legally use a GOTO a statement that is in the same sequence of statements as the GOTO.
In the sequence of statements that encloses the GOTO statement (outer block).
Labels can label any statement. Used as targets for GOTO statements, use labels for
blocks and loops, Label a block to allow referencing of DECLAREd objects that would
otherwise not be visible because of scoping rules, Label a block to allow a variable to be
referenced that might be hidden by a column name, Label a loop to allow an object to be
reference that would otherwise not be visible because of scoping rules & Label an EXIT
as a convenient way to specify exits from outer loops.
Cursors are associated with every SQL DML statement processed by PL/SQL. Two types
are Explicit i.e. Multiple row SELECT statements & Implicit i.e. INSERT, UPDATE,
DELETE & SELECT...INTO statements. Implicit cursor is called the SQL cursor-it stores
info concerning the processing of the last SQL statement not associated with an explicit
cursor. OPEN, FETCH & CLOSE do not apply. All cursor attributes apply.
Cursor has to be explicitly defined when a query returns multiple rows to process beyond
the first row returned by the query & to keep track of which row is currently being
processed.
Declare the cursor to associate its name with a SELECT statement.
Syntax : DECLARE
CURSOR <cursor_name>
IS <regular_select_statement>;
Open the cursor to process the SELECT statement and store the returned rows in the
cursor.
Syntax : OPEN <cursor_name>;
Fetch data from the cursor and store it in specified variables.
Syntax : FETCH <cursor_name> INTO <var1, var2...>;
Close the cursor to free up resources. Cursors must be closed before they can be
reopened.
Syntax : CLOSE <cursor_name>
Explicit Cursor Attributes are %NOTFOUND, %FOUND, %ROWCOUNT &
%ISOPEN.
Reference the current cursor row with the WHERE CURRENT OF statement. The cursor
must be declared with a FOR UPDATE OF clause.
Syntax : WHERE CURRENT OF <cursor_name>
Reference Cursors FOR Loops to specify a sequence of statements to be repeated once
for each row that is returned by the cursor with the Cursor FOR Loop.
Syntax : FOR <record_name> IN <cursor_name> LOOP
--statements to be repeated go here
END LOOP;
Cursor FOR loops (CFL) are similar to Numeric For Loops(NFL). CFL specify a set of
rows from a table using the cursor's name. NFL specify an integer range. CFL record
takes on vales of each row. NFL index takes on each value in the range. Record_name is
implicitly declared as
record_name cursor_name%ROWTYPE
When a CFL is initiated, an implicit OPEN cursor_name is initiated.
For each row that satisfies the query associated with the cursor, an implicit FETCH is
executed into the components of record_name.
When there are no more rows left to FETCH, an implicit CLOSE cursor_name is
executed and the loop is exited.
Declare cursors to use parameters
Syntax : DECLARE
CURSOR <cursor_name> [[(param_name param_type)]]
IS <regular select statement>;
Exception Handlers : In PL/SQL, errors are called exceptions. When an exception is
raised, processing jumps to the exception handlers. An exception handler is a sequence of
statements to be processed when a certain exception occurs. When an exception handler
is complete, processing of the block terminates. Two types are Predefined Internal
Exceptions which corresponds to approximately 20 common ORACLE errors & Raised
automatically by PL/SQL in response to an ORACLE error.
Eg.too_many_rows,no_data_found,invalid_cursor,value_errori.e.
arithmetic,numeric,string,conversion or constraint error occurred, zero_divide,
dup_val_on_index,cursor_already_open etc.
User-Defined Exceptions must be declared & must be RAISEd explicitly.
Only one handler per block may be active at a time & If an exception is raised in a
handler, the search for a handler for the new exception begins in the enclosing block of
the current block.
Exception-Init : Exceptions may only be handled by name not ORACLE error number.
So, name an ORACLE error so that a handler can be provided specifically for that error.
Syntax : PRAGMA EXCEPTION_INIT (<user_defined_exception_name>,
<ORACLE_error_number>);
SQLCODE & SQLERRM provides info on the exception currently being handled &
especially useful in the OTHERS handler.
SQLCODE returns the ORACLE error number of the exception, or 1 if it was a user-
defined exception.
SQLERRM returns the ORACLE error message associated with the current value of
SQLCODE & can also use any ORACLE error number as an argument.
SQLCODE & SQLERRM cannot be used within a SQL statement. If no exception is
active SQLCODE = 0 & SQLERRM = 'normal, successful completion'.
SQL*FORMS :
Form is a tool for developing and executing forms based interactive applications that can
access info from ORACLE database.
Blocks describes each section or subsection of the form and serves as the basis of default
database interaction.
Fields represents columns or data entry areas and describes how data should be displayed
and validated and how an operator should interact with the data while it is entered.
Pages is a collection of display info such as constant texts and graphics. All fields have to
be displayed on some page.
Pop-Up Pages Non-Pop-Up Pages
Appear in windows Overlay the entire screen
Created by selecting pop-up page attribute Default type of page
Can be larger or smaller than the screen Can only be the size of the screen
Can appear anywhere on the screen Must be positioned at the upper left hand corner of
the screen
Can be a section (view) of a page Must fill the entire text region
Many pages can appear on the screen at one time Only one non-pop-up page can
appear on the screen
Types of Triggers : Most key triggers are function key triggers; they have a one-to-one
relationship with specific keys.
Function Key Triggers : Fires when a particular Forms function key is pressed.
Replace or supplement default function key functionality, Perform multiple or complex
functions & Disable function keys.
Key Startup : Fires at the end of the entering the form event. Considered as key trigger
because its action is similar to an operator pressing a startup function key.
Set up form default, Send a message to the operator as soon as the form comes up on the
screen & Perform an automatic query upon entering the form.
Key Others : Associate a key-others trigger with all keys that can have key triggers
associated with them but are not currently defined by a function key triggers.
Key Fn : Attach key-Fn triggers to any one of ten key sequences that normally do not
perform any SQL*Form operations. Before attaching key triggers to these keys, run
Oracle*Terminal to map the keys to the appropriate functions.
Navigational Triggers : Fires when entering or leaving a form, block, record or field.
Restrict access to a form, Print messages, Derive a complex default value, Keep a
running total & Perform calculations.
Query Triggers : Fires when entering & executing a query, and when counting query hits.
Defined only at the block or form level. Pre-Query fires once before block is queried.
Call_Form runs an indicated form while keeping the parent form active.
Open_Form opens an indicated form to create multiple form application called form is
modal.
New_Form exits the current form and enters the indicated form.
Key-Duprec trigger copies the values of each field in the record with the next lower
sequence number to the corresponding fields in the current record. The current record
must not correspond already to a row in the database. If it does, an error occurs and calls
the Duplicate_Record packaged procedure.
Primary Key Field Attributes indicates that the field is a unique characteristics for a
record or part of unique key. To ensure that an inserted record or updated record does not
duplicate an existing record, give the critical field the primary key characteristics and
give the block the primary key characteristics.
Anonymous Block is a PL/SQL block without a name and this block can be executed
from the trigger in which it is defined. It does not require BEGIN & END keywords. It
has to be included if it has Declaration section.
Form Level Procedure are callable PL/SQL blocks. The full PL/SQL syntax, including
declarations and keywords BEGIN & END are required. They cannot contain anonymous
block. These procedures can use any command that a trigger can use. They can also take
arguments and return values, just as subroutines do in 3GL. It can be called from other
procedures & triggers. Advantages are
Reduce the amount of logic the designer needs to write for any task, Leads to more
efficient & consistent applications, Can be called by another procedure or trigger & Can
pass parameters.
User Exits is a subroutine which is written and linked into SQL forms executable files. It
is a link to pass data from forms to host language programs and receives the result. It
performs complex data manipulation, pass data to forms from OS files, manipulate long
raw data, support PL/SQL blocks and control real time devices such as printer or robot. It
returns a integer value which indicates Success, Failure or Fatal Error.
Types :
Oracle PreCompiler User Exits : Incorporates Oracle Precompiler interface. Allow to
write a subroutine using one of the following host language & embedded SQL
commands. Host language are ADA, C, COBOL, FORTRAN, PASCAL & PL/1. With
embedded SQL commands, an Oracle Precompiler user exit can access oracle databases.
Also access SQL*Forms variables & fields. Because of this feature, most of user exits is
Oracle Precompiler user exits.
Oracle Call Interface User Exits : Incorporates Oracle Call Interface. Allows to write a
subroutine that contains call to Oracle database but cannot access SQL*Forms variable &
fields.
Non-Oracle User Exits : Does not incorporate either precompiler interface or OCI. Non-
Oracle user exit might be entirely written using C. Cannot access Oracle database &
PL/SQL Variable is a local variable that is active only within the anonymous block or
form level procedure in which it has been declared.
Global Variable is a forms variable that is active in any trigger within a form and is active
through out the session. Stores a character string of upto 255 characters long. Before a
variable is active, it should be initialized thro' a trigger or it will be initialized first time
you assign a value to it. Delete any variable with ERASE package procedure. Global
variable declared in one form can be used in called form. Used to store data values that
should not be stored inside a block or you want to share between forms during form
session.
Syntax : GLOBAL.variable_name Oracle Naming Conventions.
System Variable is a SQL*Forms variable to keep track of some internal SQL*Forms
state. Able to reference the value of system variable in order to control the way an
application behaves. Value of system variable corresponds to the current form. They are
Block_Status,Record_Status,Form_Status,
Current_Block,Current_Field,Current_Form,Current_Value,Cursor_Block,Cursor_Field,
Cursor_Record,Cursor_Value,Last_Record,Last_Query,Message_Level,Record_Status,Tr
igger_Block,Trigger_Field & Trigger_Record.
Features of Oracle 7 :
Stored Procedures is commonly used procedures can be written once in PL/SQL and
stored in the database for repeated use by applications. This ensures consistent behavior
among applications and reduce development & testing time. Centralizing the application
logic and can be accessed from any Oracle tools.
Difference between Stored Procedure and Oracle Forms Procedure :
Stored Procedure Oracle Forms Procedure
Stored within the database. Stored within the Oracle Forms Appln.
Documented within the data dictionary. Documented from the Oracle Forms Appln.
Executed from any db tool or appln. Executed from an Oracle Forms appln. only.
May reference db stored procedures only. May reference Oracle Forms procedures in
addition to db stored procedures.
Made available to applns. by means of db security. Made available to Oracle forms
appln. by means of form-level security and the Copy/Reference facility.
Invoked independently of, and in addition to, Oracle Forms procedures. Invoked
independently of, and in addition to, stored procedures.
Stored Package is a group of related Stored Procedures, Functions & other package
constructs stored together as a unit in the db. Stored Package provides the db
administrator or appln. developer organizational benefits, they also offer increased
functionality and db perfomance.
QEP for Stored Procedures is generated at compile time.
Benefit from Stored Procedures & Functions : In addition to modularizing appln.
development, other benefits are
Improve Data Security and Integrity :
Control indirect access to db objects from non-privileged users with security privileges.
Ensure that related actions are performed together, or not at all, by funneling activity for
related tables thro a single path.
Improve Performance :
Avoid reparsing for multiple users by exploiting shared SQL.
Avoid PL/SQL parsing at runtime by parsing at compile time.
Reduce the number of calls to the database and decrease network traffic by bundling
commands.
Conserve Memory :
Store a single copy of code in the db to avoid multiple copies of the same code for diff.
applns.
Share sql to avoid multiple cursors for different applns.
Improve Maintenance :
Modify routines online without interfering with other users.
Modify one routine to affect multiple applications.
Modify one routine to eliminate duplicate testing.
Database Triggers is a stored procedure that is implicitly fired when an Insert, Update or
Delete statement is issued against the associated table. Complex business rules that
cannot be enforced using declarative integrity constraints can be enforced using triggers.
It is similar to procedures that are stored in the databases and implicitly fired when a table
is modified.
Guidelines :
Use triggers to guarantee that when a specific operation is performed, related actions are
performed.
Use DB triggers for centralized global operations that should be fired for triggering
statement regardless of which user or database application issued the statement.
Do not define triggers to duplicate the functionality & do not create Recursive triggers.
Triggers will be compiled when it is fired. So, limit the size of triggers. Compilation of
triggers smaller in size will have insignificant effect on system performance. If the trigger
has to be execute many lines of code, include the code in the Stored Procedure.
Mutating Error in DB triggers is when a select statement within the scope of the trigger
selects rows corresponding to the trigger table itself. It can be solved by placing the select
statement in a stored procedure and calling the stored procedure from the scope of the
trigger.
Differences between Oracle 6.0 & 7.0 :
Only not null was implemented in 6 where as in 7 all the integrity constraints are
implemented i.e. Not Null, Primary, Foreign, Check, Default & Unique constraints.
Database Triggers, Stored Procedures, Functions & Packages are available in 7.
Roles : ORACLE provides for easy & controlled privilege management thro the use
of Roles. Roles are named groups of related privileges that are granted to users or other
roles. The properties are Reduced granting of privileges, Dynamic privilege management,
Selective availability of privileges & Application awareness.
Schemas is a collection of objects i.e. tables, views etc. and schema exists for each oracle
user.
Profiles is assigned to each user that specifies limitations on several system resources
available to the user i.e. the number of concurrent sessions the user can establish, the
CPU processing time, the amount of logical I/O, the allowed amount of idle time for the
users session & the allowed amount of connect time for the users session.
Cost Based Optimizer is available. It uses statistics about tables, along with info about the
available indexes to select an execution plan for SQL statements. This allows even
inexperienced users to submit complex queries without having to worry about the
performance. If we know the better execution path, provide hints to it to allow it to select
the proper execution path.
Table Replication is a snapshot of a table.
Multi threaded architecture several user process for a single server process and the user
process can be configured.
Declarative Referential Integrity establishes precise rules for use of columns that are
common across tables. Built into db software and enforced by default.
SQL*REPORTWriter :
Features :
Application development tool for designing & executing reports. ANSI standard SQL
used to retrieve records in the report. Menu-driven, simple spreadsheet-style screens.
Default values for report format. Ability to customize report format, date & number
formats. Complex data relationships. Calculations & summaries. Text processing and
highlighting features. Reports can be viewed immediately on-line for corrections.
Generate reports interactively or in a production environment. Parameters provide run-
time flexibility. Report management facility for easy report maintenance & Integration
with Oracle application tools.
Components :
Query - retrieves data from the database. Group - used to cluster columns returned from
the query. Fields - containers for data values. Summary - calculated summary function on
a field. Text - physical areas of report. Report - dimensions, security and history of the
report. Parameters - entered at run-time to control production, data values.
Queries : Every report must contain atleast one query. Query retrieves data for the report
from database tables or views. Queries can be unrelated i.e Master/Master report. Related
queries form a hierarchy, in which child query is executed once for each record returned
by the parent. Can create relationships between queries. No limit to the number of queries
in a report. No limit to the level of relationships (nesting) in queries. i.e. Master/Detail
(parent/child) queries. Matrix queries i.e. Two parents/One child queries.
On-line report can be viewed either in Browse i.e. Page by page or Window i.e. scrolls
horizontally and vertically through a page.
Groups : A group is a set of one or more columns. Every report must contain at least one
group. Each query automatically generates one group consisting of all columns in the
query.
Break Groups : A break is a set of groups generated from one query. Can create new
groups (break groups) that group records by the distinct values of a column or set of
columns. Group settings provide format control.
Field : A field is a container for values derived from columns or calculated column values
in the SELECT statement. Computed fields created by user. System variables (page
number, number of pages, date etc.). User exits & DML statements.
Summaries : Summaries calculate subtotals, grand totals, running totals & other standard
functions on field values. All summaries are manually created. Multiple summaries may
be computed on any field, including fields derived from user exits & system variables.
Summary settings provide format control. Summaries may be referenced in queries.
Text Objects : Text objects represent the physical layout of the report. Text objects are
used to manipulate positions of fields & summaries. Customize text. Add page
numbering. Changes made on field, group & summary setting screens are reflected on all
associated text objects that have not been edited. Text object changes are not dynamically
reflected in field, group & summary settings.
Parameters : Parameters contain default values that can be modified for each report or
with each interactive run. Parameters may be placed in queries, user exits & text. The
default parameter value, width & data type applying to a report may be changed on the
parameter screen. Parameters may be selected for appearance or may be changed at run-
time on the run-time parameter form. Parameters may be entered from the command line
with the sqlrep or runrep command.
System Parameters provide production control. They are DESTYPE-Device type i.e.
Screen, File, Printer, Sysout & Mail. DESNAME-Destination of report i.e. File name,
Printer name & Oracle*Mail user id or user list. DESFORMAT-Printer format (used
when sending the report to a file, printer, stream, or Oracle*Mail). COPIES-Number of
copies to print (used when sending the report to the printer). CURRENCY-Symbols to
use for the dollar sign. THOUSANDS-Symbol to use for the comma. DECIMAL-Symbol
to use for the period.
Query Parameters can be created to specify data for the report at run-time.
Bind Parameter binds in a specific value when the query is run. To create a bind
parameter Include the parameter in the SELECT statement; precede the name with a
colon. Specify a default value on the parameter screen, or enter the value at run-time.
Lexical Parameter : Insert a SQL clause when the query is run. May be used to replace
WHERE, GROUP BY, ORDER BY, HAVING, CONNECT WITH, START WITH
clauses. To create a lexical parameter Create a new record on the parameter screen. Enter
the parameter name, data type & width. Enter the default value (SQL clause) on the
Parameter screen. Include the parameter in the SELECT statement; precede the parameter
name with &. Use the default value, or specify the value at run-time.
SQL*ReportWriter Utilities : SQLREP - Program used to design reports. GENREP -
Generates a runfile for a report that has not been executed via the Action menu. RUNREP
- Runs the reports (stored as runfiles) & creates final output. May be loaded on systems
without SQLREP to produce reports. DUMPREP - Creates an ASCII file containing
report definitions. LOADREP - Loads report definitions into an ORACLE database.
PRINTDEF - Creates printer definitions. TERMDEF - Created terminal definitions.
MOVEREP - SQL*ReportWriter V1.0 to V1.1 conversion program.
Matrix Reports : A matrix report has the following characteristics :
Matrix report is a grid containing three sets of data. Matrix Report require exactly three
queries: two parents & one child. Each query has only one group. Each group must be
identified as a matrix group. Print direction is Down for one group, Across for one group,
and Cross tab for the third (the group of the child query). Summaries are placed by
default in the group subfoots of the print group.
Oracle :
1) What are the Back ground processes in Oracle and what are they.
This is one of the most frequently asked question.There are basically 9 Processes but in a
general system we need to mention the first five background processes.They do the house
keeping activities for the Oracle and are common in any system.
The various background processes in oracle are
a) Data Base Writer(DBWR) : Data Base Writer Writes Modified blocks from Database
buffer cache to Data Files.This is required since the data is not written whenever a
transaction is commited.
b) LogWriter(LGWR) : LogWriter writes the redo log entries to disk. Redo Log data is
generated in redo log buffer of SGA. As transaction commits and log buffer fills, LGWR
writes log entries into a online redo log file.
c) System Monitor(SMON) : The System Monitor performs instance recovery at instance
startup.This is useful for recovery from system failure
d) Process Monitor(PMON) : The Process Monitor peforms process recovery when user
Process fails. Pmon Clears and Frees resources that process was using.
e) CheckPoint(CKPT) : At Specified times, all modified database buffers in SGA are
written to data files by DBWR at Checkpoints and Updating all data files and control
files of database to indicate the most recent checkpoint
f) Archieves(ARCH) : The Archiver copies online redo log files to archival storal when
they are busy.
g) Recoveror(RECO) : The Recoveror is used to resolve the distributed transaction in
network
h) Dispatcher (Dnnn) : The Dispatcher is useful in Multi Threaded Architecture
i) Lckn : We can have upto 10 lock processes for inter instance locking in parallel sql.
7) How many Integrity Rules are there and what are they
There are Three Integrity Rules. They are as follows ::
a) Entity Integrity Rule : The Entity Integrity Rule enforces that the Primary key cannot
be Null
b) Foreign Key Integrity Rule : The FKIR denotes that the relationship between the
foreign key and the primary key has to be enforced.When there is data in Child Tables the
Master tables cannot be deleted.
c) Business Integrity Rules : The Third Intigrity rule is about the complex business
processes which cannot be implemented by the above 2 rules.
19) What is the difference between candidate key, unique key and primary key
Candidate keys are the columns in the table that could be the primary keys and the
primary key is the key that has been selected to identify the rows. Unique key is also
useful for identifying the distinct rows in the table.
31) What is the Difference between a post query and a pre query
A post query will fire for every row that is fetched but the pre query will fire only once.
Reports 2.5
Oracle
1) What are the Back ground processes in Oracle and what are they.
1) This is one of the most frequently asked question.There are basically 9 Processes but
in a
general system we need to mention the first five background processes.They do the house
keeping
activities for the Oracle and are common in any system.
The various background processes in oracle are
a) Data Base Writer(DBWR) :: Data Base Writer Writes Modified blocks from Database
buffer cache to Data Files.This is required since the data is not written whenever a
transaction is commited.
b)LogWriter(LGWR) :: LogWriter writes the redo log entries to disk. Redo Log data is
generated in redo log buffer of SGA. As transaction commits and log buffer fills, LGWR
writes log entries into a online redo log file.
c) System Monitor(SMON) :: The System Monitor performs instance recovery at
instance startup.This is useful for recovery from system failure
d)Process Monitor(PMON) :: The Process Monitor peforms process recovery when user
Process fails. Pmon Clears and Frees resources that process was using.
e) CheckPoint(CKPT) :: At Specified times, all modified database buffers in SGA are
written to data files by DBWR at Checkpoints and Updating all data files and control
files of database to indicate the
most recent checkpoint
f)Archieves(ARCH) :: The Archiver copies online redo log files to archival storal when
they are busy.
g) Recoveror(RECO) :: The Recoveror is used to resolve the distributed transaction in
network
h) Dispatcher (Dnnn) :: The Dispatcher is useful in Multi Threaded Architecture
i) Lckn :: We can have upto 10 lock processes for inter instance locking in parallel sql.
2) How many types of Sql Statements are there in Oracle
2) There are basically 6 types of sql statments.They are
a) Data Defination Language(DDL) :: The DDL statments define and maintain objects
and drop objects.
b) Data Manipulation Language(DML) :: The DML statments manipulate database data.
c) Transaction Control Statements :: Manage change by DML
d) Session Control :: Used to control the properties of current session enabling and
disabling roles and changing .e.g :: Alter Statements,Set Role
e) System Control Statements :: Change Properties of Oracle Instance .e.g:: Alter System
f) Embedded Sql :: Incorporate DDL,DML and T.C.S in Programming Language.e.g::
Using the Sql Statements in languages such as 'C', Open,Fetch, execute and close
7) How many Integrity Rules are there and what are they
7) There are Three Integrity Rules. They are as follows ::
a) Entity Integrity Rule :: The Entity Integrity Rule enforces that the Primary key cannot
be Null
b) Foreign Key Integrity Rule :: The FKIR denotes that the relationship between the
foreign key and the primary key has to be enforced.When there is data in Child Tables the
Master tables cannot be deleted.
c) Business Integrity Rules :: The Third Intigrity rule is about the complex business
processes which cannot be implemented by the above 2 rules.
19) What is the difference between candidate key, unique key and primary key
19) Candidate keys are the columns in the table that could be the primary keys and the
primary key
is the key that has been selected to identify the rows. Unique key is also useful for
identifying the distinct rows in the table.
20)What is concurrency
20) Cuncurrency is allowing simultaneous access of same data by different users. Locks
useful for accesing the database are
a) Exclusive
The exclusive lock is useful for locking the row when an insert,update or delete is being
done.This lock should not be applied when we do only select from the row.
b) Share lock
We can do the table as Share_Lock as many share_locks can be put on the same resource.
31) What is the Difference between a post query and a pre query
31) A post query will fire for every row that is fetched but the pre query will fire only
once.
In extents .
* NON-ISOLATED (default)
* ISOLATED
a) on clear details
b) on populate details
* CASCADE
a) per-delete
b) on clear details
c) on populate details
Restrictions:
The statement you pass to FORMS_DDL may not contain bind variable references in the
string, but the
values of bind variables can be concatenated into the string before passing the result to
FORMS_DDL.
9 ) What are the types of triggers and how the sequence of firing in text item
9)
Triggers can be classified as Key Triggers, Mouse Triggers ,Navigational Triggers.
Key Triggers :: Key Triggers are fired as a result of Key action.e.g :: Key-next-field, Key-
up,Key-Down
Mouse Triggers :: Mouse Triggers are fired as a result of the mouse navigation.e.g.
When-mouse-button-presed,when-mouse-doubleclicked,etc
Navigational Triggers :: These Triggers are fired as a result of Navigation. E.g : Post-
Text-item,Pre-text-item.
We also have event triggers like when Vnew-form-instance and when-new-block-
instance.
We cannot call restricted procedures like go_to(my_block.first_item) in the
Navigational triggers
But can use them in the Key-next-item.
The Difference between Key-next and Post-Text is an very important question. The key-
next is fired as a result of the key action while the post text is fired as a result of the
mouse movement. Key next will not fire unless there is a key event.
The sequence of firing in a text item are as follows ::
a) pre - text
b) when new item
c) key-next
d) when validate
e) post text
* 12 a) If you have property class attached to an item and you have same trigger
written for the item .
Which will fire first?
12)Item level trigger fires , If item level trigger fires, property level trigger won't fire.
Triggers at the lowest level are always given the first preference. The item level trigger
fires first and then the block and then the Form level trigger.
13) What are record groups ? * Can record groups created at run-time?
13)A record group is an internal Oracle Forms data structure that has a column/row
framework similar to a
database table. However, unlike database tables, record groups are separate objects that
belong to the
form module in which they are defined. A record group can have an unlimited number of
columns of type
CHAR, LONG, NUMBER, or DATE provided that the total number of columns does not
exceed 64K.
Record group column names cannot exceed 30 characters.
Programmatically, record groups can be used whenever the functionality offered by a
two-dimensional
array of multiple data types is desirable.
TYPES OF RECORD GROUP:
Query Record Group A query record group is a record group that has an associated
SELECT statement.
The columns in a query record group derive their default names, data types, and lengths
from the database columns referenced in the SELECT statement. The records in a query
record group are the rows retrieved by the query associated with that record group.
Non-query Record Group A non-query record group is a group that does not have an
associated query, but whose structure and values can be modified programmatically at
runtime.
Static Record Group A static record group is not associated with a query; rather, you
define its
Structure and row values at design time, and they remain fixed at runtime.
15) Can a button have icon and label at the same time ?
15) -NO
When Mouse Navigate is set to False, Oracle Forms does not perform navigation (and the
resulting validation) to move to the item when an operator activates the item with the
mouse.
GUI
Reports 2.5
-----------------------------------------------------------
3.0 Data Base Administration
3.1 Introduction to DBA
A database instance (server) is a set of memory structures and background processes that
access a set of database files.
The memory structures that are used to store most queried data from database. This helps
us to improve database performance by decreasing the amount of I/O performed against
data file.
3. What is Schema ?
An index is a database structure used by the server to have direct access of a row in a
table.
An index is automatically created when a unique or primary key constraint clause is
specified in create table command (Ver 7.0)
5. What is clustres ?
Group of tables physically stored together because they share common columns and are
often used together is called Clusters.
The related columns of the tables are called the cluster key. The cluster key is indexed
using a cluster index and its value is stores only once for multiple tables in the cluster.
It consists of
one or more data files
one or more control files
two or more redo log files
Two processes waiting to update the rows of a table which are locked by the other
process then deadlock arises.
In a database environment this will often happen because of not issuing proper row lock
commands. Poor design of front-end application may cause this situation and the
performance of server will reduce drastically.
The System Global Area in a Oracle database is the area in memory to facilitates the
transfer of information between users. It holds the most recently requested structural
information about the database.
The structure is Database buffers, Dictionary Cache, Redo Log Buffer and Shared SQL
pool (Ver 7) area.
The data dictionary cache is stored in an area in SGA called the Shared SQL Pool. This
will allow sharing of parsed SQL statements among concurrent users.
11. What is meant by Program Global Area (PGA) ?
Data segment are the physical areas within a database block in which the data associated
with tables and clusters are stored.
13. What are the factors causing the reparsing of SQL statements in SGA ?
Monitor the ratio of the reloads takes place while executing SQL statements. If the ratio
is greater that 1 then increase the SHARED_POOL_SIZE.
Database buffers are cache in the SGA used to hold the data blocks that are read from the
data segments in the database such as tables, indexes and clusters.
DB_BLOCK_BUFFERS parameter in INIT.ORA decides the size.
Dictionary cache is information about the database objects stored in a data dictionary
table.
Number of times processes repeatedly query the dictionary table is called recursive hits.
It is due to the data dictionary cache is too small. By increasing the
SHARED_POOL_SIZE parameter we can optimize the size of Data Dictionary Cache.
Changes made to entries are written to the on-line redo log files so that they can be used
in roll forward operation during database recoveries. Before writing them into the redo
log files, they will first brought to redo log buffers in SGA and LGWR will write into
files frequently. LOG_BUFFER parameter will decide the size.
18. How will you swap objects into a different table space for an existing database ?
20. How will you force database to use particular rollback segment ?
23. Which parameter in Storage clause will reduce no of rows per block ?
PCTFREE parameter
Row size also reduces no of rows per block.
We can plan the storage for a table as how much initial extents are required, how much
can be extended next, how much % should leave free for managing row updations etc.
25. How does space allocation take place within a block ?
This is used to reserve certain amount of space in a block for expansion of rows.
To manage the database level of transactions such as modifications of the data dictionary
table that record information about the free space usage.
30. How the space utilisation takes place within rollback segments ?
It will try to fit the transaction in a cyclic fashion to all existing extents. Once it found an
extent is in use then it forced to acquire a new extent. (No of extents is based on the
OPTIMAL size).
34. List the sequence of events when a large transaction that exceeds beyond its optimal
value when an entry wraps and causes the rollback segment to expand into another
extend.
Transaction Begins
An entry is made in the RBS header for new transactions entry
Transaction acquired blocks in an extent of RBS
The entry attempts to wrap into second extent. None is available. So that the RBS must
extent.
The RBS checks to see if it is oldest inactive segment
Oldest inactive segment is eliminated
RBS extends
The Data dictionary table for space management are updated
Transaction Completes.
36. How will you estimate the space required by non-clustered tables ?
37. Is it possible to use raw devices as data file and what is the advantages over file
system files ?
Yes.
The advantages over file system files :
I/O will be improved because Oracle is bye-passing the kernal while writing into disk.
Disk Corruption will be very less.
Database's overall physical architecture is maintained in a file called control file. It will
be used to maintain internal consistency and guide recovery operations. Multiple copies
of control files are advisable.
39. How to implement the multiple control files for an existing database ?
40. What is meant by Redo Log file mirroring ? How it can be achieved ?
Shadow set of disks save as a backup in the event of disk failure. In most Operating
System if any disk failure occurs it automatically switchover to place of failed disk.
Improved performance because of most OS support volume shadowing can direct file I/O
request to use the shadow set of files instead of the main set of files. This reduces I/O
load on the main set of disks.
They allow the database to maintain read consistency between multiple transactions.
It is a measure of well the data cache buffer is handling requests for data.
Hit Ratio = (Logical Reads - Physical reads - Hit Misses) / Logical reads.
47. List the factors that can affect the accuracy of the estimations ?
The space used transaction entries and deleted records does not become free immediately
after completion due to delayed cleanout.
Trailing nulls and length bytes are not stored.
Inserts of, updates to, and deletes of rows as well as columns larger than a single data
block, can cause fragmentation and chained row pieces.
50. What are the dictionary tables used to monitor a database spaces ?
DBA_FREE_SPACE
DBA_SEGMENTS
DBA_DATA_FILES
52. What are requirements one should fulfill to connect to ORACLE as internal?
Operating system account has the operating system privileges that allow you to connect
One should be authorised to connect as internal
Database has a password for internal connections, and you know the password must use a
dedicated server
53. What are the roles and user accounts created automatically with the database ?
SYS user account - The DBA role will be assigned to this account. All of the base tables
and views for the database's dictionary are store in this schema and are manipulated only
by ORACLE.
SYSTEM user account - It has all the system privileges for the database and additional
tables and views that display administrative information and internal tables and views
used by oracle tools are created using the username.
SQL*Loader - It loads data from standard operating system files (Flat files) into
ORACLE database tables.
EXPORT(exp) and IMPOER (imp) utilities allow you to move existing data in ORACLE
format to and from ORACLE database.
55. What are the minimum parameters should exist in the parameter file (init.ora) ?
DB_NAME - Must set to a text string of not more that 8 characters and it will be stored
inside the datafiles, redo log files and control file while database creation.
DB_DOMAIN - It is string that specifies the network domain where the database is
created. The global database name is identified by setting these parameters (DB_NAME
& DB_DOMAIN)
DB_BLOCK_SIZE - The default data block size and is operating system dependent. It
cannot be changed after database creation except by re-creating the database.
Each server and background process can write an associated trace file. When an internal
error is detected by a process or user process, it dumps information about the error to its
trace. This can be used for tuning the database.
Roles are easiest way to grant and manage common privileges needed by different groups
of database users.
Creating roles and assigning privies to roles.
Assign each role to group of users. This will simplify the job of assigning privileges to
individual users.
58. What are the steps to switch a database's archiving mode between
NOARCHIEVELOG and ARCHIVELOG mode ?
60. How can we specify the Archived log file name format and destination ?
A simple snapshot is based on a query that does not contains GROUP BY clauses,
CONNECT by clauses, JOINs, Subquery or a set of operations.
A complex snapshots contain at least any one of the above.
Updating or inserting records in remote database through database triggers. It may fail if
remote database is having any problem.
Time the references to occur when master tables are not in use.
Perform the references manually immediately after locking the master tables.
We can join tables in snapshots by creating a complex snapshot that will be based on the
master tables.
COMPLETE - Tables are completely regenerated using the snapshot's query and the
master tables every time the snapshot referenced.
FAST -If simple snapshot used then a snapshot log can be used to send only the changes
to the snapshot tables.
FORCE - The default value. If possible it performs a FAST refresh;
Otherwise it will perform a COMPLETE refresh.
The data in the snapshot log is used during fast references of the table's snapshots.
We must be able to create a after row trigger on table (i.e. it should not be already
available)
After giving table previleges.
We cannot specify snapshot log name because oracle uses the name of the master table in
the name of the database objects that support its snapshot log.
The master table name should be less than or equal to 23 characters.
(The table name created will be MLOG$_tablename, and trigger name will be
TLOG$_tablename)
Database on other servers can be updated and those transactions can be grouped together
with others in a logical unit.
Database uses a two phase commit
Database on other servers can be updated and those transactions can be grouped together
with others in a logical unit is called two-phase commit. They are
The Preparation Phase : An initiating node called the global coordinator notifies all sites
involved in the transaction to be ready either commit or rollback the transaction.
The Commit Phase : If there is no problem with prepare phase, then all sites commit their
transactions. If a network or node failure occurs, then all sites rollback their transactions.
Logical Backups
Cold Backups
Hot Backups (Archive log)
Logical backup involves reading a set of database records and writing them into a file.
Export utility is used for taking backup and Import utility is used to recover from backup.
Cold backup is taking backup of all physical files after normal shutdown of database. We
need to take
All Data files
All Control files
All on-line redo log files
Then init.ora file (optional)
Taking backup of archive log files when database is open. For this the ARCHIVELOG
mode should be enabled. The following files need to be backed up :
All data files
All archive log, redo log files
On control file.
Flag to indicate whether export should compress fragmented segments into single extents.
A flag to indicate whether grants on database objects will be exported or not. Values is 'Y'
or 'N'.
Flag to indicate whether table rows should be exported. If 'N' only DDL statements for
the database objects will be created.
For incremental exports, the flag indicates whether a record will be stored in data
dictionary tables recording the export.
A flag to indicate whether statistical information about the exported objects should be
written to export dump file.
A flag to indicate whether a read consistent version of all the exported objects should be
maintained.
A flag to indicate whether import should ignore errors encounter when issuing CREATE
command.
98. What is the use of GRANT option in IMP command ?
A flag to indicate whether rows should be imported. I f this is set to 'N' then only DDL for
the database objects will be executed ?
A list of database accounts whose objects should be read from the export dump file.
A list of database accounts into which objects in the export dump file will be imported
A flag to indicate whether import should commit after each array. If 'N' then commit will
take place at table level
If filename is given then all the DDL will be created in the given file.
A flag to indicate whether the create tablespace command found in dump files from full
exports will be executed.
Name of the file to which the log of the import will be written.
112. Consider a case below : User is taking the backup in the following fashion :
Type F I I I I C I I I I C I I
Date 1 2 3 4 5 6 7 8 9 10 11 12 13
F - Full Backup
I - Incremental Backup
C - Cumulative Backup
Suppose database crash on 14th morning. How can we retrieve the database ?
113. List the steps to restore the database if data file lost. (Assume we are taking hot
backups)
Copy the lost file from the backup to the original location
Start the instance
Mount the database
Recover the database using recover database command
Open the database
114. What are the points to be taken care when we are using SQL*Loader for importing
data from flat files ?
It bypasses the normal processing of insert statements and instead writes directly to tables
data blocks.
When direct option is used index become invalid and once the load complete the new key
is merged with all old one and bring the status to valid.
Data should be presorted otherwise it needs the double the size in tablespace.
116. What are areas a DBA can monitor the database using SQLDBA command?
DBA can monitor the following areas to do fine tuning of the database :
Processes
Sessions
Tables(Locks etc)
SQL Area
Library Cache
Latch
Locks
File I/O
System I/O
Rollback Segments
Statistics (System, Sessions)
Apart from this all DBA activities can be performed through SQLDBA command.
DDE V OLE
What is DDE ?
DDE uses shared memory to exchange data and a protocol to synchronize passing of
data.
A DLL allocates a global memory block to an application and uses this to exchange data
with application.
Message based DDE applications and Dynamic Data Exchange Management Library
application.
A monitor application can only intercept messages but cannot act on it.
An embedded object is stored in the document itself while the document just stores a
reference to the linked object.
If a link object is changed independently of the document, wht happens the linked object
in the document ?
1. The reference object is automatically refreshed
2. The reference object is not refreshed
3. The user decides whether the object is to refreshed or if the older version is retained.
Answer is 2
A trigger is automatically executed when the firing event occurs while stored procedure
has to be invoked.
Oracle Forms:
ii) Query to get the employees who are getting salaries more than their managers
select a.emp_no from emp_self a,emp_self b where a.mgr =b.emp_no and a.sal > b.sal;
EMP_NO
-------
101
100
110
300
iii) Query to find the nth highest salary
select a.empn_name,a.sal from emp_self a where &n = (select count(*) from emp_self b
where a.sal < b.sal);
When n=1 , sal =20000 ->second highest salary ; n=4 , sal =10000 ->fifth highest salary ;
iv) Query to find the second highest salary in different departments.
select a.deptid,min(a. sal) from emp_self a where 1 in (select count(*) from emp_self b
where a.sal < b.sal group by b.deptid) group by a.deptid;
DEPTID MIN(A.SAL)
------- ----------
10 9000
20 20000
50 8000
v) Query to find departments with total salary >25000
DEPTID
------
20
50
4) study the fallowing pl/sql block and find the type of error ->syntax,semantic(logical)
or precedence
begin
for i in 1..5 loop
update emp
set sal = 1000 where empno =100 ;
end loop;
end;
5) Difference between (MAX,MIN) and (GREATEST ,LEAST)
The functions max and min compares different rows . Whereas greatest and least work on
a group of columns ,either actual or calculated values within a single row.
MAX(SAL) MIN(SAL)
---------- ----------
10000 8000
GREATEST(SAL) LEAST(SAL)
------------- ----------
9000 9000
10000 10000
8000 8000
6)Different kinds of constraints .
6)Where Procedures,Functions and Triggers are stored ?.
7)What are the improtant differences between Procedures,Functions and Triggers ?.
8)Can we call a Procedure from a Trigger ?.
9)what are packages ?.
9)What are the different kinds of parameters ?.
10)Can we return a OUT parameter from a procedure ?.
11)Differences between ROWNUM and ROWID .
12)How do you handle exceptions ?.
12)How many system defined exceptions are there ?.
13)How do you write user defined message for all the system defined exceptions.
14)Difference between Commit and H(?)ost .
15)Differences between delete ,truncate and drop commands .
16) How do you display messages in the backend procedure ?.
17) why cant you use create/drop while declaring a trigger ?.
18)Advantages of union over joins .
19)Definitions of commit, rollback, save point
20)Difference between truncate and delete (truncate =delete + commit)
ORACLE FORMS 4.5 NOTES
When-Event Triggers : A When-event signals a point at which you can augment Oracle
Forms default processing with additional tasks or operations.
On-Event Triggers : An On-event signals a point at which you can replace Oracle Forms
default processing.
Pre-Event Triggers : A Pre-event signals a point just prior to the occurrence of either a
When-event or an On-event.
Post-Event Triggers : A Post-event signals a point just following the occurrence of either
a When-event or an On-event.
Key Triggers : Key triggers have a one-to-one relationship with specific keys. That is, the
trigger fires when the operator presses a specific key or key-sequence.
Master-Detail Relationships :
Block Coordination
To maintain the master-detail relationship at runtime, Oracle Forms coordinates the
master and detail blocks to ensure that the records displayed in the detail block are
associated with the current record in the master block.
Any event that makes a different record in the master block the current record is a
coordination-causing event. Deleting a record or pressing [[Up]] or [[Down]] to move to
a different record are both examples of coordination-causing events. When such an event
occurs, Oracle Forms automatically does the processing necessary to coordinate the
master and detail blocks.
There are two phases of block coordination: the clear phase and the population phase.
During the clear phase, Oracle Forms navigates internally to the detail block and flushes
the obsolete detail records. During the population phase, Oracle Forms issues a SELECT
statement to repopulate the detail block with the detail records associated with the new
master record. These operations are accomplished through the execution of triggers.
The Copy Value from Item Property
The mechanism that Oracle Forms used to coordinate the population of the detail block
with the current record in the master block is the Copy Value from Item property on the
foreign key item in the detail block. The Copy Value from Item property specifies the
primary key item in the master block whose value gets copied to the foreign key item in
the detail block whenever a detail record is created or queried.
Because the value of the primary key item in the master record gets copied to the foreign
key item in the detail block, it is automatically incorporated in the WHERE clause of the
SELECT statement that Oracle Forms issues to populate the detail block.
When blocks are related through a compound join, the Copy Value from Item property is
set on two or more foreign key items in the detail block.
The Relation Object
When you create a relation, Oracle Forms generates the triggers and PL/SQL procedures
required to enforce coordination between the master and detail blocks. The actual code
that Oracle Forms generates depends on how the properties of the relation are set.
The properties that affect the functionality of a relation include Master Deletes,
Coordination, and Prevent Masterless Operation.
Master Deletes Property: The Master Deletes property allows you to specify how the
deletion of a record in the master block should affect records in the detail block. It can be
set to Non-Isolated, Isolated, or Cascading.
Non-Isolated : The default setting. Prevents the deletion of a master record if associated
detail records exist in the database.
Isolated : Allows the master record to be deleted and does not affect the associated
detail records in the database.
Cascading: Allows the master record to be deleted and automatically deletes any
associated detail records from the base table at commit time. When relations are nested to
several levels, only records in the immediate detail block are deleted. That is, deletions do
not automatically cascade to multiple levels of a relation chain.
Note: If your database is using the ORACLE7 Server cascading deletes feature, do not
use the Cascading deletes option in Oracle Forms.
Coordination Properties :
The Coordination properties Deferred and Auto-Query determine when the population
phase of block coordination should occur. Coordination of the detail block with its master
can be Immediate, Deferred with Auto-query, or Deferred with No Auto-query.
Immediate (Deferred False, Auto-Query False) The default setting. When a coordination-
causing event occurs, the detail records are fetched immediately.
Deferred with Auto-Query (Deferred True, Auto-Query True)When a coordination-
causing event occurs, Oracle Forms defers fetching the associated detail records until the
operator navigates to the detail block.
Deferred with No Auto-query (Deferred True, Auto-Query False) When a coordination-
causing event occurs, Oracle Forms does not automatically fetch the detail records. To
fetch the detail records, the operator must navigate to the detail block and explicitly
execute a query.
Choosing the Appropriate Coordination
Deferred coordination can more accurately be thought of as "deferred population." That
is, when a coordination-causing event occurs in the master block, the population phase of
coordination is postponed, but the records in the detail block are cleared immediately.
This functionality prevents a detail block from displaying records that are inconsistent
with the current record in the master block.
As a general rule, choose immediate coordination (Deferred False, Auto-Query False)
when the detail block is visible to the operator, and when it is assumed that the operator
will always want to see the detail records associated with the current master record.
Deferred coordination with Auto-query is preferable when the detail block is not
immediately visible; for example, when the operator must navigate to the detail block in a
different window to be able to view detail records.
Deferred coordination is also useful in situations where the operator may not need to
view the detail records at all. In this case, deferring coordination can prevent an
unnecessary database query.
Deferred coordination with No Auto-query is useful when you want operators to be able
to go into Enter Query mode and specify additional query criteria in the detail block
before population occurs. Also, Deferred coordination with No Auto-query allows
operators to navigate through detail records without forcing coordination, and its
attendant processing, to occur until it is actually required.
Setting the Properties of Foreign Key Items in the Detail Block
When you create a relation, Oracle Forms sets the Copy Value from Item property on the
foreign key items in the detail block automatically. The Copy Value from Item property
specifies the name of the corresponding primary key item in the format
master_block.item_name. At runtime, the value stored in the primary key item in the
master block is copied to the foreign key item in the detail block whenever a detail record
is created or queried.
When you create the relation in the New Block window, Oracle Forms also alters the
properties of the foreign key item(s) in the detail block by doing the following:
o setting the Canvas property to NULL to make the item a NULL-canvas item.
o setting the following properties to False:
o Displayed
o Enabled
o Navigable
o Query Allowed
o Update Allowed
o sequencing items in the Navigator such that the foreign key items are last in the block's
navigation sequence
Also, if the relation was created in the New Block window, Oracle Forms does not create
a boilerplate text label for the foreign key items.
When you create a relation in the Object Navigator, rather than in the New Block
window, you might want to set these same properties yourself.
The purpose of these settings is to hide the foreign key item(s) from the operator, since
the same information is likely to be displayed in the primary key item(s) in the detail
block. These settings are most appropriate when operators can view both the master and
detail blocks at the same time. If operators cannot see the master block when viewing
detail records, you may want to undo these settings so that foreign key item(s) are visible
to the operator. If you do so, make sure that the item Update Allowed property is set to
False, so that operators cannot edit the foreign key value and thus disrupt master-detail
coordination.
Deleting a Relation
You can delete a relation by selecting it in the Object Navigator and choosing Navigator-
>Delete. The following table shows what happens when you delete a relation or an object
that is part of a relation:
If you delete... This is the result...
------------------------------------------------------------------------------------------------------
A relation. Oracle Forms deletes all of the master-detail
triggers that were attached to the relation's
master block and clears the Copy Value from
Item property of the foreign key item(s) in the
detail block.
The master or detail block Oracle Forms deletes the relation and all of the
in a relation.master-detail triggers. Oracle Forms does not
delete the master-detail procedures.
Any master-detail trigger Oracle Forms does not prevent you from
or procedure. (Not deleting a master-detail trigger or procedure.
recommended). Doing so, however, disrupts master-detail
block coordination.
Master-Detail Triggers
This section describes the triggers that Oracle Forms creates when you define a master-
detail relationship. The example trigger text shown with each trigger description shows
the basic structure of the trigger. The actual trigger text that you will see in your own
forms will be application-specific, and may look somewhat different.
Oracle Forms also creates user-named procedures that are called by master-detail triggers.
Oracle Forms generates comments in the default trigger and procedure code. Comments
are denoted by the standard PL/SQL double-hyphen ('- -').
On-Clear-Details Trigger The On-Clear-Details trigger is required for all master-detail
relations. It fires during the clear phase of coordination, and clears all of the detail
records in the detail block. This trigger calls the CLEAR_ALL_MASTER_DETAILS
procedure, as shown in the following example trigger text:
-- Begin default relation program section
--
Clear_All_Master_Details;
--
-- End default relation program section
--
On-Check-Delete-Master Trigger Oracle Forms creates the On-Check-Delete-Master
trigger when the Master Deletes property is set to Non-Isolated. It fires when there is an
attempt to delete a master record. The trigger queries the database to see if detail records
exist for the master record. If no details exist, the trigger deletes the master record. If
detail records are found, the trigger displays the message "Cannot delete master record
when matching detail records exist." as shown in the following example trigger text:
-- Begin default relation declare section
--
Declare
Dummy_Define char(1);
--
-- Begin B detail declare section
--
cursor B_cur is
select null from MASDET
where PARENT = :A.ID;
--
-- End B detail declare section
--
--
-- End default relation declare section
--
--
-- Begin default relation program section
--
Begin
--
-- Begin B detail program section
--
Open B_cur;
Fetch B_cur into Dummy_Define;
if ( B_cur%found ) then
Message('Cannot delete master record when matching
detail records exist.');
Close B_cur;
raise Form_Trigger_Failure;
end if;
Close B_cur;
--
-- End B detail program section
--
End;
--
-- End default relation program section
PROCEDURE Check_Package_Failure IS
BEGIN
IF (NOT Form_Success) THEN
RAISE Form_Trigger_Failure;
END IF;
END;
Triggers for Complex Master-Detail Relations
When you create a complex master-detail relationship, Oracle Forms adds or edits the
existing master-detail triggers to support the relationship you have defined. The following
examples illustrate how Oracle Forms adds or edits triggers as required.
Example 1: Master with Independent Details Consider a single relation A_B, with Master
Deletes set to Non-Isolated and Coordination set to Immediate (default settings). Oracle
Forms creates the following triggers on the master block to manage the relation:
o On-Clear-Details o On-Check-Delete-Master
o On-Populate-Details
If you then create a second relation A_C (having the same master block but a different
detail block), you have created a master-with-independent-details relationship; that is,
one master block with two detail blocks.
To manage this relationship, Oracle Forms does not create any additional triggers.
Instead, Oracle Forms adds a section to each existing trigger to facilitate clearing and
populating the second detail block. The generated comments in these triggers delimit the
sections that manage each detail block. For example, the comments in the On-Populate-
Details trigger clearly show where each detail block section begins and ends:
Example 2: Master with Dependent Details In this example, the simple relation A_B is
extended by adding a second relation B_C to create a master with dependent details
relationship.
To manage the second relation B_C, Oracle Forms removes the form-level On-Clear-
Details trigger, and creates two additional triggers that enforce coordination with the new
detail block. The additional triggers are attached to Block B, the master for the second
relation (B_C).
Remember, however, that if you later change the properties of the relation, Oracle Forms
may need to delete or edit the default triggers. For example, changing a relation's Master
Deletes property from Cascading to Isolated causes Oracle Forms to remove the now
unnecessary Pre-Delete trigger.
Consider the following points when you edit master-detail triggers:
o Do not alter or delete the comments that Oracle Forms generates. These comments tell
Oracle Forms where to insert or delete trigger text when changes are necessary.
o If you add code to a trigger, insert it before the "Begin default relation program section"
comment or after the "End default relation program section" comment.
o Oracle Forms does not delete a master-detail trigger that you have modified, provided
that you place your code outside the default relation program section. (Oracle Forms
removes the relation program section, but does not delete the trigger.)
Oracle Forms provides a number of triggers and built-in subprograms that are useful for
such tasks, some of which are listed here. For complete information on these triggers and
routines, refer to the Oracle Forms Reference Manual, Vol. 1.
Triggers:
o On-Clear-Details o On-Populate-Details
o On-Check-Delete-Master o When-New-Record-Instance
o When-New-Block-Instance
Built-in subprograms:
o GET_BLOCK_PROPERTY o SET_BLOCK_PROPERTY
o GET_FORM_PROPERTY o GET_RELATION_PROPERTY
o SET_RELATION_PROPERTY
o Use GET_FORM_PROPERTY to get the name of the first and last block in the form
(FIRST_BLOCK, LAST_BLOCK).
DECLARE
master_block VARCHAR2;
BEGIN
master_block := Get_Relation_Property('my_relation',
MASTER_BLOCK);
END;
Set_Relation_Property('my_relation', MASTER_DELETES,
DEFERRED_COORDINATION);
Canvas-Views
Canvas-views are the background objects on which you place the interface items (text
items, check boxes, radio groups, etc.) and boilerplate objects (boxes, lines, images, etc.)
that operators interact with as they run your form. Each canvas-view is displayed in a
window.
Content Canvas-Views Most canvas-views are content canvas-views. A content canvas-
view is the "base" view that occupies the entire content pane of the window in which it is
displayed. You must define at least one content canvas-view for each window you create.
More than one content canvas-view can be assigned to the same window at design time,
but at runtime, only one of them at a time is displayed in the window.
Stacked Canvas-Views A stacked canvas-view is displayed in a window on top of, or
"stacked" on the content canvas-view assigned to that same window. Stacked canvas-
views obscure some part of the underlying content canvas-view, and are often shown and
hidden programmatically. More than one stacked canvas-view can be displayed in a
window at the same time.
Horizontal/Vertical Toolbar Canvas-Views Toolbar canvas-views are used to create
toolbars for individual windows. Horizontal toolbars are displayed at the top of a
window, just under its menu bar. Vertical toolbars are displayed along the left side of a
window.
Windows
MDI applications display a default parent window, called the application window. All
other windows in the application are either document windows or dialog windows.
Document windows are always displayed within the MDI application window frame. If
the operator resizes the application window so that it is smaller than a document window,
the document window is clipped. Operators can maximize a document window so that it
occupies the entire content area of the application window.
Dialog windows are free-floating, and the operator can move them outside the application
window if they are defined as Movable. If the operator resizes the application window to
make it smaller than a dialog window, the dialog window is not clipped.
A window can be either modeless or modal.
Modeless windows can remain displayed until they are dismissed by the operator or
hidden programmatically. You can set the Remove on Exit property for a modeless
window to specify whether it should remain displayed when the operator navigates to
another window.
Modal windows are usually used as dialogs, are often displayed with a platform-specific
border unique to modal windows. On some platforms, modal windows are "always-on-
top" windows that cannot be layered behind modeless windows.
In addition to platform-specific restrictions, modal windows have the following
characteristics:
The Remove on Exit property does not apply to modal windows. By default, Oracle
Forms prevents operators from navigating out of modal windows with the mouse, but
does allow them to navigate to another window with keyboard commands. When such
navigation occurs, Oracle Forms always closes the modal window, unless the target
window is itself a modal window.
Modal windows cannot have scroll bars, and setting the Scroll Bar properties for a modal
window has no effect.
Show_lov : the lov need not be attached to the text item.
List_values : the lov should be attached to the text item.
lovs are based on record groups.
Changing a column in the record group does not update lov columns automatically
Record Groups :
The following built-in subprograms are available for creating and manipulating record
groups programmatically:
Creating and deleting groups:
o CREATE_GROUP (function) o CREATE_GROUP_FROM_QUERY (function)
o DELETE_GROUP (procedure)
Modifying a group's structure:
o ADD_GROUP_COLUMN (function) o ADD_GROUP_ROW (procedure)
o DELETE_GROUP_ROW (procedure)
Populating groups:
o POPULATE_GROUP (function)
o POPULATE_GROUP_WITH_QUERY (function)
o SET_GROUP_CHAR_CELL (procedure)
o SET_GROUP_DATE_CELL (procedure)
o SET_GROUP_NUMBER_CELL (procedure)
Getting cell values:
o GET_GROUP_CHAR_CELL (function)
o GET_GROUP_DATE_CELL (function)
o GET_GROUP_NUMBER_CELL (function)
Processing rows:
o GET_GROUP_ROW_COUNT (function)
o GET_GROUP_SELECTION_COUNT (function)
o GET_GROUP_SELECTION (function)
o RESET_GROUP_SELECTION (procedure)
o SET_GROUP_SELECTION (procedure)
o UNSET_GROUP_SELECTION (procedure)
Object ID functions:
o FIND_GROUP (function)
o FIND_COLUMN (function)
Populate Group with query : can be used to modify record group at run time but columns
cannot be altered ( created during design time).
To populate a list item during run time using record group, the record group must contain
two columns of char type
Oracle Forms Datatypes
The following table shows the FIND_ function and return type for each object:
Object Function Return Type
Alert FIND_ALERTALERT
Block FIND_BLOCK BLOCK
CanvasFIND_CANVAS CANVAS
Record Group Column FIND_COLUMN GROUPCOLUMN
Editor FIND_EDITOR EDITOR
Form FIND_FORM FORMMODULE
Record Group FIND_GROUP RECORDGROUP
Item FIND_ITEM ITEM
List of Values FIND_LOV LOV
Menu Item FIND_MENU_ITEM MENUITEM
Parameter List GET_PARAMETER_LIST PARAMLIST
Relation FIND_RELATION RELATION
Timer FIND_TIMERTIMER
View FIND_VIEW VIEWPORT
Using object id improves performance, makes code generic and easier to maintain.
Each time you reference an object by name in a PL/SQL statement, Oracle Forms does
the necessary processing to look up the object's ID internally.
Default_value built in procedure assigns the value to the indicated variable only if it is
null.
Consider the following factors when deciding whether to use a global or NULL-canvas
item as a variable:
o Items can be defined as CHAR, NUMBER, or DATE data types; global variables store
only character strings, and using conversion functions like TO_DATE and TO_NUMBER
requires additional processing.
o Items can be dimensioned by setting their Maximum Length property; global variables
are always 255 bytes.
o Global variables are visible across multiple modules during a runtime session; NULL-
canvas items are not.
o The CLEAR_FORM operation sets the value of a NULL-canvas item in the current
form to NULL; the value of a global variable is not affected by CLEAR_FORM.
o Both items and global variables can be referenced in the default WHERE clause for a
base table block and record group SQL statements.
Subprograms and functions :
Defined in a form module can be called only in that module
Defined in a library can be called from anywhere.
PL/SQL Packages:
A package is a PL/SQL construct that groups logically related types, objects, procedures,
and functions. Packages usually have two parts, a specification and a body, although
sometimes the body is unnecessary.
The first time a package is called (by any user on the instance) the entire package is
loaded into the Oracle7 SGA to make subsequent invocation of any procedures or
functions it contains very fast.
LIBRARIES
A library is a collection of subprograms, including user-named procedures, functions, and
packages. Libraries provide a convenient means of storing client-side program units and
sharing them among multiple applications. A library can be attached to any form, menu,
or library module. Then, you can call library program units from triggers, menu item
commands, and user-named routines you write in the modules to which you have
attached the library. The same library can be attached to multiple forms and menus.
Conversely, a single form or menu can have more than one attached library.
Libraries can also be attached to other libraries. When a library attaches another library,
program units in the first library can reference program units in the attached library.
Libraries support dynamic loading --that is, a library's program units are loaded into an
application only when needed. This can significantly reduce the runtime memory
requirements of an application.
File formats : .pll - source and compiled (pcode) source can be removed using
STRIP_SOURCE. .pld - only source
libraries cannot refer - form variables, system variables, global variables, form
parameters
Instead use name_in, copy for referencing
Unlike PL/SQL menu items, a user-defined trigger defined in a form module can refer
directly to the values of form items. If you want to write a user-named routine or
anonymous block that uses direct references, you can place it in a user-named trigger and
then call that trigger from a PL/SQLmenu item command with the
EXECUTE_TRIGGER built-in
Menus :
Background Menu : only one per menu module. it is assigned the name BGM.
Features :
* There is a logical key associated with the first 10 menu items on the background
menu. Operators can press a background menu key to execute the command assigned to a
background menu item, without having to select the item on the BGM menu.
* At any time, operators who have been granted background menu privileges can
display the items on the background menu in a separate "show-keys" window by pressing
[[Show BGM]]. Similarly, the background menu can be displayed programmatically by
executing the SHOW_BACKGROUND_MENU routine.
PECS : Performance event collection services
FORMS 4.5 ADVANCED TECHNIQUES MANUAL
Exceptions :
When a built - in failes, no exception is raised, subsequent statements are executed. So
the outcome of the built-ins is to be tested;
User named triggers :
When an unhandled exception is raised in a user-named trigger, the user-named trigger
fails, but the exception does not propagate to the calling trigger. Rather, Oracle Forms
treats the failure as an error in the built-in procedure EXECUTE_TRIGGER, and sets the
return values of the built-in error functions accordingly. Thus, the outcome of a user-
named trigger can be trapped in the same way as a call to any other built-in subprogram;
that is, by evaluating the built-in error functions:
Error Handling for Stored Procedures
There are three primary methods for trapping ORACLE errors that are returned from the
kernel during the processing of your PL/SQL code:
o checking DBMS_ERROR_TEXT and DBMS_ERROR_CODE built-in subprograms
within a form-level ON-ERROR trigger
o creating appropriate user-defined exceptions
o evaluating the SQLCODE and SQLERRM functions in a WHEN OTHERS exception
handler
User defined exceptions :
exception_init : associate an oracle error number with an exception name of our choice.
Multiple form applications
There are three ways that one form can programmatically invoke another form:
o Execute the OPEN_FORM procedure to open an independent form.
o Execute the NEW_FORM procedure to replace the current form with a different form.
o Execute the CALL_FORM procedure to call a modal form.
When one form invokes another form by executing OPEN_FORM, the first form remains
displayed, and operators can navigate between the forms as desired. An opened form can
share the same database session as the form from which it was invoked, or it can create a
separate session of its own. For most GUI applications, using OPEN_FORM is the
preferred way to implement multiple-form functionality.
When one form invokes another form by executing NEW_FORM, Oracle Forms exits the
first form and releases its memory before loading the new form. Calling NEW_FORM
completely replaces the first form with the second. If there are changes pending in the
first form, the operator will be prompted to save them before the new form is loaded.
When one form invokes another form by executing CALL_FORM, the called form is
modal with respect to the calling form. That is, any windows that belong to the calling
form are disabled, and operators cannot navigate to them until they first exit the called
form.
Multiple-Form Applications and the Root Window
Only one root window can be displayed even in multiple form applns. So root windows
are to be avoided when more than one form is to be displayed at the same time.
If form a has a root window defined and invokes form b which also has root window,
form b is displayed on the root window of a thus hiding form a.
Opening forms in different database sessions :
To open a form without creating a new session:
Open_Form('stocks'); -- default; NO_SESSION is implicit
Open_Form('stocks',ACTIVATE,NO_SESSION) -- explicit; for clarity
To open a form in its own, independent session, call OPEN_FORM with the SESSION
parameter, as shown here:
Open_Form('stocks',ACTIVATE,SESSION);
When COMMIT is initiated, processing is done for those forms that share the same
session.
Opening multiple instances of the same form :
To navigate use form id.
Post Vs Commit :
Posting consists of writing updates, deletions, and insertions in the form to the database,
but not committing these transactions to the database. Oracle Forms does all of the
default validation and commit processing, but does not issue the COMMIT statement to
finalize these transactions. If posted the status of the records need not be maintained in
the form.
Commit finalizes these transactions
Post only mode :
When a calling form has pending updates or deletes that have not been explicitly posted,
Oracle Forms runs the called form in post-only mode.
Commiting from child form :
update records in form A, post , call form B, make changes and commit.
Commiting from parent form :
update records in form A, call form B, post return to A in no-rollback mode and commit.
Calling Other Products from Oracle Forms
You can invoke other products from Oracle Forms with the RUN_PRODUCT built-in
procedure. The syntax for RUN_PRODUCT is shown here:
RUN_PRODUCT(product, document, commmode, execmode, location,
list, display);
For example, to invoke Oracle Reports, you could make the following call:
Run_Product(REPORTS,'stats',ASYNCHRONOUS,BATCH,FILESYSTEM);
By default, when you invoke Oracle Reports or Oracle Graphics with RUN_PRODUCT,
the called product logs on to ORACLE using the current form operator's USERID.
Oracle Forms uses the parameters you pass to RUN_PRODUCT to construct a valid
command line invocation of the called product. RUN_PRODUCT takes the following
parameters:
Product A numeric constant that specifies the Oracle tool to be invoked: FORMS,
REPORTS, GRAPHICS, or BOOK.
Commmode Specifies the communication mode to be used when running the called
product. Valid numeric constants for this parameter are SYNCHRONOUS and
ASYNCHRONOUS.
o SYNCHRONOUS specifies that control returns to Oracle Forms only after the called
product has been exited. The operator cannot work in the form while the called product is
running. Synchronous is required when passing a record group to a called product as a
DATA_PARAMETER; for example, when invoking Oracle Graphics to return an Oracle
Graphics display that will appear in a form chart item.
o ASYNCHRONOUS specifies that control returns to the calling application
immediately, even if the called application has not completed its display. Do not use
ASYNCHRONOUS when passing a record group to a called product as a
DATA_PARAMETER; for example, when invoking Oracle Graphics to return an Oracle
Graphics display that will appear in a form chart item.
Execmode Specifies the execution mode to be used when running the called product,
either BATCH or RUNTIME. When you run Oracle Reports and Oracle Graphics,
execmode can be either BATCH or RUNTIME. When you run Oracle Forms, always set
execmode to RUNTIME.
Location Specifies the location of the document or module you want the called product to
execute, either the file system or the database.
List Specifies the name or ID of a parameter list to be passed to the called product.
Display Specifies the name of the Oracle Forms chart item that will contain the display
generated by Oracle Graphics.
Chart item : Does not store database values. contains objects generated by oracle graphics
OLE :Object Linking and Embedding (OLE) provides you with the capability to integrate
objects from many MS Windows applications into a single compound document. In
Oracle Forms, embedded objects become part of the form module, and linked objects are
references from a form module to a linked source file. Embedded objects are activated by
In-place/ External activations. Linked objects - External activation
An OLE server application creates objects that are embedded or linked in OLE
containers; OLE containers store and display OLE objects. Oracle Forms is an OLE
container application, and MS Word is an example of an OLE server application.OLE
server applications can create many object classes. During the installation of an OLE
server application, the object classes that an OLE server can create are installed in a
registration database. When you install MS Windows applications that support OLE, a
registration database is created on your computer, if it does not already exist. The
registration database contains the object classes that are valid for embedding and linking
into a form module. For instance, MS Word classes include MS Word 6.0 Document, MS
Word 6.0 Picture, and MS WordArt 2.0.
OLE objects are documents created from OLE server applications such as MS Word.
Another example of an OLE object is a spreadsheet created in MS Excel. OLE objects are
linked or embedded into compound documents created by OLE container applications
such as Oracle Forms.
Embedded Objects
An embedded object, such as a spreadsheet or chart, is created by an MS Windows OLE
server application and is embedded in an Oracle Forms form module. An embedded
object is stored as part of a form module or as an item in the database.
You can modify the content of an embedded object within Oracle Forms if the OLE
server application that created the OLE object is accessible by your computer. Editing an
embedded object is performed with in-place activation or external activation.
An example of object embedding is to insert an MS Excel spreadsheet in an OLE
container of a form module. The MS Excel spreadsheet is stored as part of the form
module or as an item in the database; there is no separate source file containing the Excel
spreadsheet.
Linked Objects
A linked object, such as a word processor document, is created by an MS Windows OLE
server application. A linked object is stored in a separate source file created from an OLE
server application. An image representation of the linked object and information about
the location of the linked object's source file is stored in a form module or as item in the
database. The content of the linked object is not stored as part of a form module or in the
database; it is retained in a separate file known as the linked source file.
An example of object linking is to link an MS Word document in a form module. An
image of the MS Word document appears in the OLE container of the form module and
the location of the MS Word file is stored as part of the form module or as an item in the
database.
In-Place Activation : When container surrounds the object ( oracle forms surrounding the
spreadsheet) Some of the forms menu is replaced by the objects menu. to deactivate click
outside the window
External Activation : is started in a separate window. does not replace forms menu/toolbar
to deactivate explicit quit is required.
An OLE container in Oracle Forms is a type of custom item. A custom item in Oracle
Forms can be an OLE Container, VBX Control, or User Area. In an OLE container, you
can link or embed OLE objects. OLE objects can be used as base table items or contol
items.
VBX Controls : VBX controls provide a simple method of building and enhancing user
interfaces. The controls can be used to obtain user input and display program output.
VBX Controls in Oracle Forms :
A VBX control in Oracle Forms is a type of custom item. A custom item in Oracle Forms
can be an OLE Container, VBX Control, or User Area. Like other Oracle Forms item
types, VBX controls serve as a way to represent and manipulate data that displays on a
form. VBX controls can be used as base table items or control items.
VBX Control as an Oracle Forms Item :
You can interchange a VBX control with other Oracle Forms items without affecting your
intended use for the item. A text item in Oracle Forms displays data from the database on
a form. A VBX control can accomplish the same task. For example, a text item displaying
the number 10 can be depicted by a VBX control that is a knob. Both items also reflect
changes in the data from the database. For instance, when the number 10 changes to the
number 5, the number 5 appears in the text item on the form and the knob control
redirects its position to represent the number 5.
PL/SQL Interface to Foreign Functions :
Foreign functions can be accessed through a user exit interface or through a PL/SQL
interface. In most instances, creating user exit interface requires relinking Oracle Forms
Runtime. Creating a PL/SQL interface to foreign functions requires the use of the
ORA_FFI built-in package (Oracle Foreign Function Interface). The ORA_FFI package
provides a public interface for calling foreign functions from PL/SQL. There are many
benefits for accessing foreign functions through a PL/SQL interface:
o Additional code in the foreign function source code is not required.
o Tools for compiling and linking the foreign function are not necessary.
o Conflicts with shared libraries such as dynamic link libraries (DLLs)are reduced or
eliminated.
o Relinking Oracle Forms Runform is not required.
Using a PL/SQL interface provides a much looser bind than that of a user exit interface,
because accessing foreign functions through a user exit interface depends on a single
dynamic link library and usually requires the relinking of Oracle Forms Runform.
ORA_FFI Package :
To access a foreign function through a PL/SQL interface, you need to know the foreign
function's prototype and function's location. Relinking Oracle Forms and creating
dynamic link libraries are unnecessary when using a PL/SQL interface to access foreign
functions.
Types of Foreign Functions :
o Oracle Precompiler foreign functions
o OCI (ORACLE Call Interface) foreign functions
o non-ORACLE foreign functions
You can also write foreign functions that combine both the ORACLE Precompiler
interface and the OCI.
Oracle Precompiler foreign functions :
With embedded SQL commands, an Oracle Precompiler foreign function can access
Oracle databases as well as Oracle Forms variables and items. Although it is possible to
access Oracle Forms variables and items, you cannot call Oracle Forms built-in
subprograms from a foreign function. You can access Oracle Forms variables and items
because you can use a set of Oracle precompiler statements that provide this capability.
OCI (ORACLE Call Interface) Foreign Functions :
An OCI foreign function incorporates the Oracle Call Interface. This interface allows you
to write a subprogram that contains calls to Oracle databases. A foreign function that
incorporates only the OCI (and not the Oracle Precompiler interface) cannot access
Oracle Forms variables and items.
Non-Oracle Foreign Functions :
A non-Oracle foreign function does not incorporate either the Oracle Precompiler
interface or the OCI. For example, a non-Oracle foreign function might be written
entirely in the C language. A non-Oracle foreign function cannot access Oracle databases
or Oracle Forms variables and items.
Oracle Questions
h What is SQL*Plus and where does it come from?
h How does one use the SQL*Plus utility?
h What commands can be executed from SQL*Plus?
h What are the basic SQL*Plus commands?
h What is AFIEDT.BUF?
h How does one restore session state in SQL*Plus?
h What is the difference between @ and @@?
h What is the difference between & and &&?
h What is the difference between ! and HOST?
h What is the difference between ? and HELP?
h How does one enable the SQL*Plus HELP facility?
h How can one disable SQL*Plus prompting?
h How can one trap errors in SQL*Plus?
h How does one trace SQL statement execution?
h How can one prevent SQL*Plus connection warning messages?
h How can uses be prevented from executing devious commands?
h How can one disable SQL*Plus formatting?
h Can one send operating system parameters to SQL*Plus?
h Can one copy tables with LONG columns from one database to another?
h Where can one get more info about SQL*Plus?
What is SQL*Plus and where does it come from?
SQL*Plus is a command line SQL and PL/SQL language interface and reporting tool that
ships with the Oracle Database Client and Server. It can be used interactively or driven
from scripts. SQL*Plus is frequently used by DBAs and Developers to interact with the
Oracle database.
SQL*Plus's predecessor was called UFI (User Friendly Interface). UFI was included in
the first releases of Oracle, its interface was extremely primitive and anything but user
friendly.
How does one use the SQL*Plus utility?
Start using SQL*Plus by executing the "sqlplus" command-line utility. Valid options are:
userid/password@db -- Connection details
/nolog -- Do not login to Oracle. You will need to do it yourself.
-s or -silent -- start sqlplus in silent mode. Not recommended for beginners!
@myscript -- Start executing script called "myscript"
Look at this simple example:
sqlplus /nolog
SQL> connect scott/tiger
SQL> select * from tab;
SQL> disconnect
SQL> exit
What commands can be executed from SQL*Plus?
One can enter three kinds of commands from the SQL*Plus command prompt:
1. SQL*Plus commands - SQL*Plus commands are used to set options for SQL*Plus,
format reports, edit files, edit the command buffer, and so on. SQL*Plus commands do
not interact with the database. These commands do not have to be terminated with a
semicolon (;), as is the case with SQL commands. The rest of this page is dedicated to
SQL*Plus commands, eg.
SHOW USER
2. SQL commands - for more information see the Oracle SQL FAQ. Eg:
SELECT * FROM TAB;
3. PL/SQL blocks - for more information see the Oracle PLSQL FAQ. Eg:
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/
What are the basic SQL*Plus commands?
The following SQL*Plus commands are available:
ACCEPT Get input from the user
DEFINE Declare a variable (short: DEF)
DESCRIBE Lists the attributes of tables and other objects (short: DESC)
EDIT Places you in an editor so you can edit a SQL command (short: ED)
EXIT or QUIT Disconnect from the database and terminate SQL*Plus
GET Retrieves a SQL file and places it into the SQL buffer
HOST Issue an operating system command (short: !)
LIST Displays the last command executed/ command in the SQL buffer (short: L)
PROMPT Display a text string on the screen. Eg prompt Hello World!!!
RUN List and Run the command stored in the SQL buffer (short: /)
SAVE Saves command in the SQL buffer to a file. Eg "save x" will create a script file
called x.sql
SET Modify the SQL*Plus environment eg. SET PAGESIZE 23
SHOW Show environment settings (short: SHO). Eg SHOW ALL, SHO PAGESIZE etc.
SPOOL Send output to a file. Eg "spool x" will save STDOUT to a file called x.lst
START Run a SQL script file (short: @)
How does one restore session state in SQL*Plus?
Look at the following example (Oracle8):
SQL> STORE SET filename REPLACE
SQL> (do whatever you like)
SQL> @filename
What is AFIEDT.BUF?
AFIEDT.BUF is the SQL*Plus default edit save file. When you issue the command "ed"
or "edit" without arguments, the last SQL or PL/SQL command will be saved to a file
called AFIEDT.BUF and opened in the default editor.
In the prehistoric days when SQL*Plus was called UFI, the file name was "ufiedt.buf",
short for UFI editing buffer. When new features were added to UFI, it was the initially
named Advanced UFI and the filename was changed to "aufiedt.buf" and then to
"afiedt.buf". They presumably needed to keep the name short for compatibility with some
of the odd operating systems that Oracle supported in those days.
The name "Advanced UFI" was never used officially, as the name was changed to
SQL*Plus before this version was released.
You can overwrite the default edit save file name like this:
SET EDITFILE "afiedt.buf"
What is the difference between @ and @@?
The @ (at symbol) is equivalent to the START command and is used to run SQL*Plus
command scripts.
A single @ symbol runs the script in your current directory, or one specified with a full or
relative path, or one that is found in you SQLPATH or ORACLE_PATH.
@@ will start a sqlplus script that is in the same directory as the script that called it
(relative to the directory of the current script). This is normally used for nested command
files.
select info
from system.help
where upper(topic)=upper('&1')
/
How can one disable SQL*Plus prompting?
If you run a script that contains "&" symbols SQL*Plus thinks that you want to prompt
the user for a value. To turn this off:
SET ESCAPE ON
SET ESCAPE ""
SELECT 'You & me' FROM DUAL;
or
SET DEFINE ?
SELECT 'You & me' FROM DUAL;
Note: You can disable substitution variable prompting altogether by issuing the SET
DEFINE OFF commmand.
D
-
X
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'DUAL'
Statistics
----------------------------------------------------------
0 recursive calls
2 db block gets
1 consistent gets
0 physical reads
0 redo size
181 bytes sent via SQL*Net to client
256 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
How can one prevent SQL*Plus connection warning messages?
When I go to SQl*Plus, I get the following errors:
Can one copy tables with LONG columns from one database to another?
About the fastest way of copying data between databases and schemas are by using the
SQL*Plus COPY statement. Look at this example:
COPY FROM SCOTT/TIGER@LOCAL_DB TO SCOTT/TIGER@REMOTE_DB -
CREATE IMAGE_TABLE USING -
SELECT IMAGE_NO, IMAGE -
FROM IMAGES;
Interview questions:
1.query for self join.
2.deletion of duplicate rows.
3.post query trigger
4.pre query trigger
5.mastere Vdetail relation
6.report triggers
7.report parameters.
8.format triggers in report.
9.order of triggering of when new item instance.