Está en la página 1de 19

QUESTION PAPER IIND SEMESTER [VB & ORACLE]

Q Q Q Q List and describe various types of boxes used in VB with suitable program segments. Explain the following: i) Crystal Reports ii) Frames iii) Active X controls What is SQL form? How is it created used and useful? Explain in detail with an example. Differentiate the following: i) SQL and PL/SQL. ii) Searching and matching functions in Oracle. iii) Table and view in Oracle List various types of Reports available in Oracle and explain two of them with example. Describe the following with reference to SQL menu: i) Menu Styles ii) Creating Oracle Menu iii) Granting Role Access iv) Executing Applications. What are Triggers? How these are created, used and useful? Also explain their different types in detail with program segments. Write short notes on the following: i) SQL Loader ii) Stored Procedures ii) Buttons in VB. a) What are the different types of variables used in VB? Explain the process of declaring these Variables. [7] b) Create a project, which contains a form, a text box and a label. Write code, using the Select Code statement that accepts a character into the text box and determines whether the character is a vowel. [8] a) What is the difference between static array and dynamic array? [4] b) Create a project with two forms and a single command button on each. Declare a variable on Form 1. When the command button on Form 1 is clicked, display the value of this variable but if the command button of Form 2 is used to try to display the value, it does not work. Then modify the variables declaration so that its value can displayed when the command button of From 2 is clicked. [8] c) What is picture box and image controls? [3] a) What is RecordSet and its properties? [5] b) Write a short note on Crystal Reports. [5] c) Role of Option Buttons? and how they are created? [5] Write short note on any three of the following: [15] i) Data constraints ii) D0-Loop statement iii) Triggers iv) Debugging Windows v) Procedures and functions. Differentiate between [15] i) SQL and PL/SQL ii) Network and Relation Models iii) Active X Controls iv) User Defined Form and Multiple Record Forms. a) What is the process of authorization of SQL * Menu? How Oracle menus are created? [5] b) Why should you try to keep my Forms as small as possible? [3] c) How can you make my Forms more portable? [3] d) What are the oracle utilities for import and export? [4] a) Explain by creating a data table the data manipulation functions such as modify, insert, delete and update. [8] b) Detail the process of SQL *From constructions. [4] c) Features of stored procedures? [3] a) What are database triggers? Explain the process of creating a trigger and dropping a trigger by taking an example. [7] b) What are the basic features of PL/SQL? c) Enumerate the different comparison operators in SQL. Data types available in VB. How can you declare the variables and constants? Explain the meaning of the following key words: [15] Dim, private, public, static

Q Q

Q Q Q

Q Q

Q Q

Q Q

Q Q Q Q Q Q Q

Q Q Q Q

Q Q

Q Q Q Q Q

Short notes on the following [15] a) On Error statement b) Do-Loop statement c) Select case statement What do you understand by class module? How can you create a class module and define its properties? [15] Differentiate between the following: [15] a) Implicit and Explicit Censors b) SQL DDL and SQL DML c) SQL & PL/SQL What are import and export utilities? What are the prompts received from Oracle when exp. and imp. are invoked with no parameters? [15] Short notes on the following: [15] a) Selective dump report b) Grant and revoke statement of SQL c) init cap and substr functions Control Structures available in PL/SQL? Explain with examples. [15] a) What is SQL* Form &master-detail form? Explain the procedures of creating them. b) Enumerate the different comparison operators and their purpose in SQL. a) Different types of loops in PL/SQL? b) What are the data types supported by PL/SQL? a) What are the comparison operators available in SQL Plus. b) Explain the use of following functions in SQL Pluse: Ceil, Floor, Substr, Initcap Write short notes on the following: Master-detail report, data constraints, Exceptions in PL/SQL What do you understand by SQL* Loader? Discuss the use of different parameters with it. Differentiate between i) Implicit and Explicit cursor ii) Before and After Trigger. iii) Import and Export Utility What are control statements available in VB. With example. a) Write the different VB Procedure to navigate and update a database file. b) Discuss the scope of variable in VB. a) What do you understand by an object oriented database? What are the focus areas of Oracle 8i? b) Discuss the important features of SQL* report writer. a) Tell the class of control and the purpose of each of these object names: lbl Address, cmd Exit, txtName, opt text Blue. b) What is Focus? How can you control which object has the focus? c) What is the purpose of keyboard access keys? How can you define them. a)Data Types in VB? Order of precedence of operations. b) Explain how to include an existing form in a new project. a) Exceptions? Explain the following exceptions in PL?SQL: 1) Value-error 2) Too-many-rows b) What is SQL* Loader? Discuss the use of following parameters: discard, skip, silent Differentiate between following i) implicit and explicit cursors ii) import and export utilities. Short notes on the following. i) Implicit and explicit cursors ii) import and ex a) What is database triggers? Distinguish between before and after triggers with example. b) What is an Active X Control? a)What do you understand by an RDBMS? What features are to be there in it. b) What steps are needed in VB to add/delete a record from a database? a) What do you understand by master-detail report? b) What is DDL? Explain any three commands.

CHAPTER 1 [INTRODUCTION TO ORACLE] 2

Overview of RDBMS Data: Facts and figures Information: Processed Data System: Group of associated activities or function with the following attributes: i) A common goal ii) Identifiable objectives iii) Set of procedures including Input, Output, and Feedback. iv) An environment in which the system exists. v) Mutually dependent subsystem. Flow of information: Lower [Clerks] -> Middle [Control] -> Top [Senior] Database: Collection of related items grouped together under a single heading. Components of Database: i) Records: Collection of fields. ii) Fields: is an item, which distinguishes one record from anther. iii) Key fields: is a field that is unique to particular record. iv) Entity: A person, place, thing or event about which information must be kept. v) Attributes: Piece of information describing a particular entity. Database Models: i) Object-based logical models: are used in describing data at the logical & view levels. Some of popular Object-based logical models are a. Entity Relationship Model b. Object-Oriented Model c. The semantic data Model d. Functional Data Model ii) Record-based logical models: are used for both to specify overall logical structure of the database and to provide a higher-level description of the implementation. Some of the Recordbased models are a. Hierarchical Models: data storage is in the form of child parent relationship. The origin of data tree is root. Data rooted at different level among a particular branch is called node. Last node in a tree is called node. Last node in a tree is called a leaf. b. Network Models: is represented by collection of records, and relationships among data are represented by links, which can be viewed as pointers. The main idea behind the network database system model is to bring about Many-to-Many relationship. The relationship between different data items is called sets. c. Relational Model: Dr. E.F. Codd introduces the relational model in 1970. The model allows data to be represented in a simple row-column format. Classification of DBMS users i) Naive users: unsophisticated users, who interact with the system by invoking one of the application programs written previously. They are not aware of the presence of data base system. ii) Online users: Who may communicate with the database directly. They are aware of presence of database system. They may also use DML to manipulate the data. iii) Application programmer: are computer professionals who interact with the system through DML calls. iv) Database Administrator [DBA]: A person or group of persons under the supervision of a high level administrator exerts centralized control of the database; this person is referred to as Data Base Administrator. DBMS Languages i) Data Definition Language (DDL): used to define the conceptual scheme and give some detail how to implement the scheme in the physical devices used to store the data. This definition 3

includes all the entity sets, attributes, relationship among sets, constraints. The definition can be defined as the metadata (Data about data). ii) Data Manipulation Language (DML): is used to manipulate data in the database. It involves retrieval of data, insertion, deletion and modification of data. Retrieval of data is called a query. The subset of DML used to pose a query is known as a query language. Structure of DBMS i) DDL Compiler: It converts the data definition statements into a set of tables. This data is used by other components of the DBMS. ii) Data Manager: Central software component of DBMS, referred to as Database Control system. Its function is to convert operations in the users queries to a physical file system. It is responsible for interacting with the file system, and also entrusted with the backup and recovery operations. iii) File Manager: Its responsibility is for the structure of the files and managing the file space. Also responsible for locating the block containing the required record, requesting the block from disk manager, & transmitting the required record to the data manager. It can be implemented using the interface provided by the operating system or it can include a file subsystem written especially for the DBMS. iv) Disk Manager: Is a part of operating system of the host computer and all physical input and output operations are performed by it. It transfers the block requested by the file manager. v) Query Processor: The query processor is used to interpret the inline users query and convert it into series of operations to send to data manager for execution. vi) Telecommunication System: On line users of a computer system, whether remote or local, communicate with it by sending and receiving message over communication line. These messages are routed via an independent software system called a telecommunication system or a communication control program. It is not a part of DBMS but DBMS works closely with the system. vii) Data Files: Data Files contains the data portion of end user. viii) Data Dictionary: Information pertaining to the structure and usage of data contained in the database, the metadata is maintained in a data dictionary. It is also called system catalog. Each database user can consult the data dictionary to learn what each piece of data and the various synonyms of the data fields mean. Advantages and Disadvantages of DBMS i) Advantages a. Reduction in Redundancies b. Shared Data c. Integrity d. Security e. Conflict resolutions ii) Disadvantages a. Problem associated with centralization b. Cost of software/hardware and migration c. Complexity of backup and recovery. Relational Data Base Management System [RDBMS] Relational database model is the current database standard. It is so sophisticated that the user/designer need only be concerned with logical view of the database and how data structure is managed by the RDBMS. Therefore relational database management system becomes much simpler then the hierarchical or network design. A relational table stores a collection of related entities. In relational model data is organized in rows and columns. Each row of a relation represents and entity instance and is referred to as TUPLE. Each column of a relation is referred to as and attribute. Entity: is a thing or object in the real world that is distinguishable form all other objects. For example each person in an enterprise is an entity. 4

Relationship: is defined as an association among entities. The three types of relationships recognized among various data stored in the database are: i) One to One STUDENT 1 ii) Many to One STUDENT 1 STUDENT 2 STUDENT 3 iii) Many to many VENDOR 1 VENDOR 2 CODDs Twelve Rules of RDBMS: Rule Zero: A relational system must be able to manage database entirely through its relational capabilities. Rule One: All information in a relational database is represented explicitly at the logical level and in exactly one way by values in tables. Rule Two: Each and every datum in a relational database is guaranteed to be logically accessible by resorting to a combination of table name, primary key value and column name. Rule Three: Null values are supported for representing missing information and inapplicable information in a systematic way independent of data type. Rule Four: The database description is represented at the logical level in the same way as ordinary data so that authorized users can apply the same relational language to its interrogation as they apply to the regular data. Rule Five: A relational system may support several languages and various modes terminal use. However, there must be at least one language whose statements can express all of the following: Data Definition, View Definition, Data Manipulation, Integrity constraint, Authorization, Transaction Boundaries. Rule Six: All rules that are theoretically updateable are also updateable by the system. Rule Seven: The capability of handling a base relation or a derived relation as a single operand applies not only to the retrieval of the data but also to the insertion, updation, and deletion. Rule Eight: Application programs and terminal activities remain logically unimpaired whenever any changes are made in either storage representation or access methods. Rule Nine: Application programs and terminal activities remain logically unimpaired when informationpreserving changes of any kind that theoretically permit unimpairment are made to the base tables. Rule Ten: Integrity constraints specific to a particular relational database must be definable in the relational data sub language and storable in the catalogue, not in the application programs. Rule Eleven: The data manipulation data sub language of a Relational DBML must enable application programs and enquires to remain logically the same whether data is physically centralized or distributed. Rule Twelve: If a Relational system has a low level language, that low level cannot be used to subvert or bypass the integrity rules and constraints expressed in the higher-level relational languages. Introduction To Oracle 5 ITEM 1 ITEM 2 Register Course Assigned Rollno 1

Oracle is an object relational database management system(ORDBMS). It offers capabilities of both relational and object oriented database system. In general, object can be defined as reusable software codes, which are location independent and perform a specific task on any application environment with little or no change to the code. Oracle products are based on concept of Client/Server Technology. This concept involves segregating the application between two systems. One performs all activities related to the database (Server) and the other perform activities that help user to interact with the application(Client). Modules of Oracle SQL* Plus: This is a structured query language supported by Oracle. Through it we can store, retrieve, edit, enter and run SQL commands and PL/SQL blocks. We can perform calculations, list column definition for any table and can format query result in the form of a Report. PL/SQL: It is an extension of SQL. It can contain any number of SQL statements integrated with flow of control statements. It combines the data manipulating power of SQL with data processing power of procedural language. SQL Vs PL/SQL: SQL is a structural language common to all relational databases. SQL is a database language used for storing and retrieving data from the database. Most RDBMS provide extensions to SQL to make it easier for application developers. SQL* Plus is an oracle specified program which accepts SQL commands and PL/SQL blocks and executes them. SQL* Plus enables manipulation of SQL commands and PL/SQL blocks. Oracle Forms: This tools allows you to create a data entry screen along with suitable menu objects. Oracle Report Writer: Allows programmers to prepare innovative reports using data from the Oracle structure like tables, views etc. Oracle Graphics: Allows programmers to prepare graphs using data from Oracle structure like tables, views etc. SQL * Plus Data Types: char, varchar2, long Number Date Raw Long Raw LOB CLOB BLOB BFILE -

For binary data Large Object for sound clips, video files etc. Character Object Long Binary Object File pointers to LOB

SQL Language Basics: Types of SQL Declarations: SQL commands are divided into two categories, DDL & DML. DDL commands: Create Table Alter Table Truncate Table Drop Table Data Constraints: When Oracle developer is developing tables and indexes he must understand the concept of data integrity, which is implemented through constraints and triggers. Data integrity can be defined as rules created by developer or DBA. For example: Table DEPT Table EMP

DEPTNO 20 30 35

DNAME RESEARCH SALES ACOUNT

LOC DELHI MUMBAI DELHI

EMPNO 777 333 888

ENAME ABC XYZ RTY

SAL 100 0 200 0 300 0

COMM 500 600

DEPTNO 20 20 30

When these tables were created, the following integrity rules were stipulated. The DEPTNO column of DEPT can no contain duplicate values. The ENAME of the EMP table cannot be left blank. Other columns may have null values. The DEPTNO column of the EMP table can contain only those department Numbers that correspond to the DEPTNO column of DEPT table. An integrity constraint is a mechanism used by Oracle to prevent invalid data entry into the table. Types of integrity constraints: i) Domain integrity constraints ii) Entity Integrity Constraints iii) Referential Integrity Constraints. Domain Integrity Constraint: These constraints set a range and any violations prevent the user from performing the manipulation. i) not null constraint: By default the tables can contain null values. The enforcement of not null constraint ensures that the table contains values. Ex: create table vendor_master(vencode varchar2(5), venname varchar2(25) constraint nn1 not null,vendadd varchar2(25) not null); ii) check constraint: Check constraint can be defined to allow only a particular range of values. Ex: create table itemfile(item code varchar2(5), category varchar2(20), max_level number(5) constraint max check(max_level)); Entity Integrity Constraint: i) Unique constraint: It means that each value in a particular column is unique. ex: alter table itemfile add constraint un_item unique(itemdesc); ii) Primary key constraint: It specifies that each row of a table must be identified by a unique value. Not only it prevents duplication but also does not allow null values. Ex: create table order_master(ordernovarchar2(5), odate date, constraint ord_prime primary key(orderno)); Referential Integrity Constraints: It determines that the value of group of fields corresponds to the key fields of other tables. It enforces relationship between tables. It designates column or combination of columns as a foreign key. The foreign key establishes a relationship with a specified primary or unique key in another tables, called the reference key. The table, containing the foreign key is called the child table and table containing the referenced key is called the parent table. Reference Description Restrict Disables the updating or deletion of specified data Set to Null When specified data is updated or deleted all the associated data is adjusted to Null. Set to default When specified data is updated or deleted all the associated data is adjusted to the default value. Cascade When specified data is updated all dependent data is updated too, if a row that is referenced is deleted, all dependent rows will also be deleted. No action Disable the updating and deletion of specified data. This is default operation in Oracle. Foreign Key: A column or combination of columns included in the definition of integrity, which would refer to a reference key. 7

Referenced key: It is a unique or a primary key, which is defined on a column belonging to the parent table. Child Table: This table depends upon the values present in the referenced key of the parent table, which is referenced by a foreign table. Parent Table: This table determines whether insertion or updation of the data can be done in the child table. Ex: create table order_detail(orderno varchar2(5) constraint fk_rod reference order_master(orderno), itemcode varchar2(5) constraint fk_item reference itemfile(itemcode)); Operators: The operators act on the operands. There are two classes of operators unary operator which act on only one operand, and binary operators, which act on two or more operands. Precedence of Operators: When one or more than one type of operators present in an expression, they are evaluated according to the following precedence order: Unary operator Division and multiplication Addition and subtraction Comparison operators NOT Operator AND Operator OR Operator Types of Operators: Arithmetic Operators: +, -, *, / Ex: select itemdesc, max_level qty_hand, avble_limit from itemfile; Comparison Operator: <, >, <=, >=, =, != Ex: select itemdesc, re_level from itemfile where qty_hand < max_level/2 Logical Operator: AND, OR, NOT Ex: select * from order_master where odate>10-may-88 and del_date<26-may-88; Set Operators: Union Returns the row selected by any query. Intersect Returns the rows selected by both queries. Minus Returns the rows selected by the first but not the second query. SQL Commands: Create: To create table Syntax: Create table <table name>(column definition 1, column definition 2,......); Example: create table vendor_master(vencode varchar2(5), venname varchar2(20),venaddress varchar2(20)); Modify: Syntax: Example: To modify the structure of the table alter table <table name> modify(column definition); alter table <table name> add (column definition); alter table <table name> drop (column definition); alter table vendor_master modify (venname varchar2(25)); alter table vendor_master add(telno number(6)); alter table vendor_master drop column telno; alter table vendor_master set unused(telno); To truncate the table [ to delete all the records] truncate table <table name>; truncate table vendor_master; To view the tables structure desc <table name> desc vendor_master 8

Truncate: Syntax: Example: Desc: Syntax: Example:

Drop: Syntax: Example: Insert: Syntax: Example:

To drop the table drop table <table name> drop table vendor_master;

To add rows in a table insert into table <table name> values (a list of data values); insert into vendor_master values(v001,govind,122343); insert into vendor_master values(&vencode,&venname,&telno); To skip a few fields in a record the necessary ones have to explicitly specified in the insert statement. Example: insert into vendor_master ( vencode,telno) values (v013,895688); Delete: Syntax: Example: Update: Syntax: Example: Select: Syntax: Example: To delete a row from any table delete from <table name> where conditions; delete from order_master where orderno=v006; To reflect changes in a row. update <table name> set field = value,....where condition; update vendor_master set telno=248965 where vencode=v002;

To request the information from any table. select column_name,....... from table_name; select * from vendor_master; select vencode, venname, telno from vendor_master; Select command with where clause select * from order_master where vencode = v004 order by del_date; Order by clause for ordering of multiple columns. select * from itemfile order by p_category, itemcode desc; /* desc for descending order*\ Searching SELECT * from product_master where selling_price BETWEEN 5000 AND 10000 SELECT * from product_master where selling_price NOT BETWEEN 5000 AND 10000 Pattern Matching Like: For pattern matching For character data types: % matches any string, _ matches single character Example: select name from client_master where name LIKE an%; select name from client_master where name LIKE _n% OR LIKE _a%; Oracle Functions Single Row Functions: A single row function or a scalar function returns only one value for every row required in the table. single row function can appear in a select command and also be included in a where clause. These function can be broadly classified as: Date Numeric Character Conversion Miscellaneous Date Functions: Add_months: It returns a date after adding a specified date with the specified number of months. 9

Syntax: Example: Last_day: Syntax: Example:

add_months(d,n), where d is the date and n represents the number of months. select del_date, add_months(del_date,2) from order_master; It returns the date corresponding to the last day of the month. last_day(d) select sysdate, last_day(del_date) from order_master where odate> 01-des-88;

Months_between: To find the number of months between two dates. Syntax: Months_between(d1,d2) Example: select months_between(del_date,odate) form order_master; Next_day: To find the immediately next specified day after a specified date. Syntax: next_day(d,day); Example: select next_day(sysdate,'Tuesday) from dual; Note: dual is a system table. Greatest: Syntax: Example: Returns the latest date present in the argument. greatest(d1,d2,...); Select del_date, sysdate, greatest(del_date, sysdate) from order_master where orderno=o001; Example Select initcap (hello) from dual; Select lower (FUN) from dual; Select upper (fun) from dual; Select ltrim (xyzadams,xyz) from dual; Select rtrim (xyzadams,ams) from dual; Select translate (jack,j,b) from dual; Select replace (jack and jue,j,bl) from dual; Select substr (abcdefg,3,2) from dual; Output Hello fun FUN adams xyzad back black and blue cd

Character Functions: Function Initcap(char) Lower(char) Upper(char) Ltrim (char, set) Rtrim(char, set) Translate(char, from, to) Replace(char, searchstring,[rep, string])

Substr( char,m,n) Other character functions: select venname from vendor_master where soundex(venname)=soundex(sumesh); select chr(67) from dual; select lpad (function,5,*) from dual; select rpad (function,5,*) from dual; select trim(leading 9 from 99999879790) from dual; select trim(trailing 9 from 99999879799) from dual; select length (rajesh) from dual; Concatenation (||) operator: select (The address of || venname || is || venadd) from vendor_master; Numeric Functions: Function Abs Ceil(n) Cos(n) Exp(n)

Example Select abs(-18) from dual; Select ceil(44.778) from dual; Select cos (180) from dual; Select exp (4) from dual; 10

Output 18 45 -.5984601 54.59815

Floor(n) Power(m,n) Mod(m,n) Round(m,n) Trunc(m,n) Sqrt(n)

Select floor (100.2) from dual Select power (4,2) from dual; Select mod(10,3) from dual; Select round(100.256,2) from dual; Select trunc(100.256,2) from dual; Select sqrt(4) from dual;

100 16 1 100.26 100.25 2

Conversion Functions: To_char() Converts date to a value of varchar2 type in a form specified by the format fmt. Syntax: to_char(d, [fmt]) Example: select to_char (sysdate,ddth of fmmonth yyyy) from dual; To_date() Syntax: Example: Converts char or varchar2 datatype to date datatype. to_date(char,[fmt]) select to_date(;January 27 1999,month-dd-yyyy) from dual;

To_number() Converts char data type to number datatype Syntax: to_number(char) Example: select to_number(100) from dual; Miscellaneous functions: Uid Returns the integer value corresponding to the user currently logged in Example: select uid from dual; User Returns the logins user name, in varchar2 data type. Example: select user from dual; Nvl Is used where we want to consider Null values as zeros. The syntax of the function is: nvl(expression1, expresion2) if expression1 is Null, nvl will return expression2 if expression1 is Not Null then it will return expression1 Example: select itemrate, nvl(itemrate,0) from itemfile where itemcode = i201; Vsize Returns the number of bytes in the expression. Example: select vsize (hello) from dual; Group functions:
DISTINCT All AVG MIN MAX COUNT SUM

Group By Having

select avg(sal) from emp; select min(sal) from emp; select max(sal) from emp; select count(sal) from emp; select sum(sal) from emp; select sal, max(comm) from emp group by sal; select sal, max(comm) from emp group by sal having 5000 not in sal;

11

CHAPTER 2 [SQL * FOMS] Basic Concepts Oracle Forms is part of Developer/2000, a comprehensive set of application development tools that supports the complete application development life cycle. Oracle forms components: Forms Designer: The designer is an application development environment where you work with three types of Oracle Forms modules- forms, menus and libraries. The designer includes a set of visual tools that allow you to create objects, set their properties, and write code for your applications. Forms Generator: The generator component is used to generate application files to create executable run files for runtime deployment. Generating a form module compiles all of its code objects and creates an .FMX run file. Runform: The runform component is the runtime engine that form operators use to run a finished Oracle Forms application. Oracle Forms Modules Forms Menus Libraries Forms are collection of objects and code, including windows, text items, checkboxes, buttons, triggers, and procedures. Menus are collection of menu objects (main menu, pull-down menu, menu items) and menu command code. Libraries are collection of PL/SQL procedures, functions and packages that can be called from other modules.

Objects and properties: When you build application with Oracle Forms, much of your development work involvers creating objects and setting their properties. You can set properties to control not just the look of the objects you create, but also their functionality. This approach facilitates rapid development, and reduces the need to write code to perform standard operations such as Querying, inserting, updating, and deleting records Defining queries Coordinating maser and detail records Controlling navigation Displaying objects Block and items: When you create the interface for your application, you work with two types of Oracle Forms objects blocks and items. Items are the interface objects that display information to users and allow them to interact with your application. Oracle Forms supports a variety of interface items, including buttons, checkboxes, radio groups, list items, text items, etc. Every item belongs to a block. A block is a logical container for items. A block can relate directly to a database table or view. Blocks are logical grouping only. The items in a block can be arranged in any order on a form, and can even be displayed in different windows. Triggers: The primary method of adding code to a form is through triggers. A trigger is a block of PL/SQL code that you attach to a specific object, and that executes in response to a specific event. For example to create a command button you would drew the button on a form, and then attach a When-Button-Pressed trigger that executes the desired command code. As its name suggests, the When-Button-Pressed trigger executes, or fires, whenever the button is pressed. Starting the Oracle Forms Designer; To Start the oracle form designer. 1. Double-click on the Designer icon. or enter the following command at the system prompt: f45des [module][userid/password][parameters] 12

2.

If you do not specify a module to be opened at startup, oracle forms opens a new form module for you automatically. You can enter the special parameters module and userid using either positional or keyword notation. Example: f45des accounts scott/tiger module_access=database f45des module=accounts module-access=database userid=scott/tiger Form construction The Object Navigator: The object navigator provides a hierarchical display of the objects in all open modules. Objects are grouped under the appropriate node. For example, all of the windows defined in a form module appear under the Windows node. The top-level nodes in the Navigator include Forms, Menus, Libraries, Built-in packages, and database objects. Figure at page 254 You can perform the following operations in the Object Navigator: Expand and collapse entries to locate objects quickly Select objects Create and delete objects Copy and move objects within and between modules Switch between views to display the objects you want to work with locate objects quickly by searching with Fast Search quickly display the code associated with objects such as triggers and program units. The Layout Editor: The layout editor is a graphical design facility for creating and arranging interface items in a form. In the layout editor, you work on a single canvas-view. Canvas-views are displayed in windows at runtime. To invoke the layout editor: 1. In the navigator, double-click the object icon for the canvas-view you want to edit. Or In the Navigator, choose layout editor form the popup menu. Or Choose Tools->layout Editor, then indicate the canvas-view you want to work on 2. If there is more than one canvas defined in the form, Oracle Forms display a list of values form, which you can select the canvas-view you want to edit. 3. If there is only one canvas-view in the form, Oracle Forms display it in the Layout Editor automatically. 4. If there are no canvas-view in the form, oracle forms creates a default canvas-view. The Menu Editor: The menu editor is a graphical design facility for laying our custom menus. To build a custom menu, you need to open a menu module and then define the required menu objects and set their properties. To invoke the Menu Editor: 1. In the Object Navigator, double-click the menu modules object icon or the icon for an individual menu in the module. Or 2. Choose Tools->Menu Editor Or 3. In the Object Navigator, select a menu object, then choose layout editor form the popup menu. The PL/SQL Editor: The PL/SQL Editor is where you enter and compile code objects. Code objects n Oracle forms include event triggers, subprograms, menu item commands, menu startup code, and packages. 13

To invoke the PL/SQL Editor: 1. Choose Tools->PL/SQL Editor from the menu Or 2. In the Navigator, double-click the object icon for any code object. Or 3. I the Object Navigator, Menu Editor, or Layout Editor, select an object that can have code associated with it and choose PL/SQL Editor form the popup menu. Cursor Management: Oracle allocates an area of memory known as context area for the processing of SQL statements. The context area contains information necessary to complete the processing. A cursor is a handle or pointer to the context area. Through a cursor, PL/SQL program can control the context area and what happens to it as the statement is processed. There are three types of cursors Static cursor Dynamic cursor REF cursor Declaring a Cursor The DECLARE command is used to declare a cursor Syntax: DECLARE CURSOR cursor_name [(parameter [, parameter]...)] [RETURN return_type] IS SELECT command Example DECLARE CURSOR prim01 IS SELECT empno, ename, job, sal FROM emp where deptno=30; There is no limit to number of cursors you can create, except for the memory that is allocated to each of them. Static cursor definitions are those whose select statements are known at compile time. These are further classified into: Explicit Cursor Implicit cursor An explicit cursor in one, where the cursor name is explicitly assigned to the select statement. An implicit cursor in the one, which is used for all SQL statements. Processing a explicit cursor involves four steps. Processing on an implicit cursor is taken care by the PL/SQL itself. The declaration of the cursor is done in the declaration command section.

14

CHAPTER 3 [PL/SQL BLOCKS IN SQL* FORMS] Introduction to PL/SQL PL/SQL stands for Procedural Language/SQL. PL/SQL is an extension of the SQL language. We can say it is the superset of the SQL specialized for use in the Oracle database. Advantages of PL/SQL: Supports the declaration and manipulation of object types and collections Allow the calling of external functions and procedures. A stored procedure is a PL/SQL program that can be enabled by an application, a trigger, or an Oracle tool. The basic difference between a procedure and a function that a procedure can not return a value but a function can. Contains new libraries of built-in packages. A package is a file that group functions, cursors, stored procedures, and variables in one place. Triggers Cursors. Architecture of PL/SQL: The PL/SQL engine executes the PL/SQL Blocks. The PL/SQL engine executes only the procedural statements and sends the SQL statements to the SQL statement executor in the Oracle Server. Figure: Page 353 PL/SQL Block [DECLARE .....................Declarations] BEGIN ............Statements [EXCEPTION ..............Handlers] END; Data Types: PL/SQL data types can be classified into scalar and composite data type. Scalar Data Types includes all SQL data types. char, varchar2, long, long raw, date, Boolean, binary_integer(for signed integer), number Composite Data Types is a data type that contains one or more scalar variables. There are three types of composite data type are records, tables and arrays. Attributes: Attributes allow s to refer to data types and objects from the database. Following are the types of attributes. %type is used when declaring variables that refer to the database columns. For example declare vcode vendor_master.vencode %type; %rowtype represents a row in a table. Sections of PL/SQL Block Declaration section: The declaration section begins a PL/SQL block. The declaration section starts with the keyword declare, followed by a list of variables and cursor definitions. All procedural statements are included between the BEGIN and END statements. Errors that occur during the execution are dealt in the exception handling part. This part is optional. Executable Commands Section: In this section, you manipulate the variables and cursors declared in the Declaration section of your PL/SQL block. This section starts with the keyword begin. This section may contain SQL commands, logical control commands, and assignment commands, as well as other commands. 15

Example declare pi constant number (9,4):= 3.1415 radius integer(5); area number(14,2); begin radius := 3; area := pi* power(radius,area); insert into AREAS values (radius,area); end; Control Structure: The flow of control statements can be classified under the following categories. Conditional control Iterative control Sequential control Conditional Control: Syntax if condition then sequence of statements end if; Example if sal<2000 then Update emp set sal=sal*1.2; elseif sal<3000 then update emp set sal=sal*1.3; else update emp set sal=sal*1.4; end if Iterative control Simple loop While loop For loop Examples: Simple Loop declare a number := 100 begin loop a:= a+25; exit when a = 250; end loop; end; 16 While Loop declare i number :=0; j number := 0; begin while i<= 100 loop j:= j+1; i: i+2; end loop; end;

Error Handling in PL/SQL [Exception Handling] There are two types of exception: Predefined Exception User Defined Exception When user-defined or system-related exceptions are encountered, the control of the PL/SQL block shifts to the Exception Handling section. In this section, the developer can use commands to handle an error that occurs during the execution of the PL/SQL program. Within the Exception Handling section, the when clause is used to evaluate which exception is to be raised that is, executed. This section always begins with the keyword exception, and it precedes the end command that terminates the Executable command section. declare <declaration section> begin <executable commands> exception <exception handling> end; Predefined Exception: an exception is raised implicitly in when a PL/SQL program violates Oracle rule. The following are the predefined exceptions supported by PL/SQL. Predefined Exception Explanations No_data_found Cursor_already_open Dup_val_on_index Storage_error Program_error Zero_divide Invalid_cursor Login_denied Invalid_number Too_may_rows This exception is raised when select statement returns no rows. This exception is raised when we try to open a cursor which is already open This exception is raised when we insert duplicate values in a column, which is defined as unique index. This exception is raised if PL?SQL runs out of memory or if the memory is corrupted. This exception is raised if PL/SQL has an internal problem This exception is raised when we try to divide a number by zero This exception is raised when we violate cursor operation. for example when we try to close a cursor when it is not open. This exception is raised when we try to enter Oracle using invalid username/password This exception is raised if the conversion of character string to a number fails because the string does not represent a valid number This exception is raised when the select into statement returns more than one row

User Defined Exception: A user defined is an error that is defined by the programs. The error that it signifies need not necessarily be an Oracle error. pre-defined exceptions correspond to common SQL errors. User-defined exceptions can be declared in the declaration command section of the PL/SQL block. They have a type and can be declared as follows: Variable name exception;

17

CHAPTER [REPORT WRITER] Selective Dump Report: SQL Plus is usually thought of as a kind of interactive report writer. It uses SQL to get information from the Oracle database and lets you crate polished, well-formatted reports by giving you easy control over titles, column headings, subtotals and totals, reformatting of numbers and text, and much more. It can also be used to change the database by using insert, update, delete commands in SQL. You can write SQL PLUS reports while working interactively with SQLPLUS- that is you can type commands about page headings, column titles, formatting, breaks, totals, and so on, and then execute a SQL query, and SQLPLUS will immediately produce the report formatted to your specification Master/Detail Report: A simple master/detail report contains two groups of data: master group and detail group. Fro each master record fetched, only the related detail records are fetched. Control-Break Report: A break report suppresses duplicate data values, like the company name and stock symbol in the tabular report, so its more readable. One good way to create break reports is to create a tabular report and then convert it to a break report. Chapter [Utilities]

Import/Export Utilities: Export, import are complementary utilities which allow you to write data in an ORACLE-binary format from the database into operating system files and to read data back form those operating system files. Export, import are used for the following tasks. Upgrading to new releases of Oracle Backing up Oracle database. Moving data between Oracle databases. Store Oracle data in operating system files independent of any database Store definition of database with or without data. Store inactive or temporary data. Back up only tables whose data has changed since the last export, using either an incremental or a cumulative export. Restore a database by importing from incremental or cumulative exports. Move data from an older to a newer version of Oracle or vice versa Move data between Oracle databases Import Utility The basic concept behind import is very simple. Import inserts the data objects extracted from one Oracle database by the Export utility into another Oracle database. The data extracted by export facility is stored in export dump file. This dump file can only be read by import. Table Objects: Order of import : Table objects are imported as they are read form the export file. The export file contains objects in the following order: 1. Table definitions 2. Table data 3. Table indexes 4. Integrity constraints, triggers, and bitmap indexes First, new tables are created. Then, data is imported and indexes are built. Then triggers are imported, integrity constraints are enabled on the new tables, and any bitmap indexes are built. Import modes: The import mode provides three modes. All users have three choices of import mode. A user with the IMP_FULL_DATABASE role has three choices: Table: This mode allows you to import specified tables in your schema, rather than all your tables. User: This mode allows you to import all objects that belong to you. 18

Full Database: Only users with the IMP_FULL_DATABASE role can import in this mode, which imports a full database export, dump file. Export Utility Export means extracting object definition and table data from an Oracle database and store them in an Oracle-binary format export file that is located typically on tape or on disk. Export files can be used to transfer data between database that are on machines not connected via a network or as backups in addition to normal backup procedures. When Export is run against an Oracle database, objects, such as tables, are extracted followed by their related objects, like indexes, comments, and grants, if any, then written to the Export file figure. Because export files are saved in Oracle-binary format, export files cannot be read by utilities other than import. Similarly, import can read files written by export, but cannot read files in other formats. Access privileges: To use export you must have the CREATE SESSION privilege on an Oracle database. To export tables owned by another user, you must have the EP_FULL_DATABASE role enabled. This role is granted to all DBAs. SQL* Loader SQL * Loader is a utility that imports/loads data from external files to the Oracle database. The program accepts several formats of titles, and allows the filtering of records that will be loaded. SQL* Loader requires two primary files: The data file, which contain the information to be loaded, and the control file, which contains the information on the format of the data, the records and fields within the file, the order in which they are to be loaded. You can also combine the control file information into the data file itself. During the execution, the SQL* Loader produces a log file with the operation log. If there are records with problems in the input files, a file with the rejected records is produced. Bad File: The bad file will contain the records that were rejected by SQL * Loader or by Oracle. Normally this occurs when the records format is invalid, or when non-unique values in the primary columns are found.

19

También podría gustarte