PREFACE
“Knowledge is precious but wisdom comes through experience.” A famous method to explain but I try my best to give presentation and make short report on it. Philosopher once quoted these words to make people understand the importance of practical knowledge and how to represent this in front of the other people and the very important way is how to explain to them so that they could understand easily.
Theory in any subject is important but that subject knowledge is important if should be understood by the other people in a very simple way by you.
An Engineering student cannot be perfect engineer or professional without the practical, theoretical knowledge if he /she is not be able to represent that knowledge to you in a very simple way so that you can easily understood. I got the opportunity to make a presentation on the Oracle 9i.
CONTENTS
S.NO. | CONTENTS | PAGE NO. |
1. | About the Organization | 6 |
2. | Introduction
| 7 |
3. | What is SQL
| 9 |
4. | SQL*Plus
| 10 |
5. | DATABASE OBJECTS | 14 |
6. | PL/SQL | 32 |
7. | PL/SQL (Simple and Compound Symbols)
| 41
|
8. | REFERENCE | 42 |
About the Organization
- BEACON is one of the leading institutes in Rajasthan.
- Offers training in courses via: Java, Oracle, .NET etc.
- It has given many trained professionals with Microsoft Certification, Sun Certifications and Oracle Certifications.
- It provides excellent faculties, updated softwares and competitive environment.
Introduction
Oracle is most widely database used in the world. It runs virtually every kind of computer. It functions virtually identically on all the machines, so when we learn it on one, we can use it on any other. This fact makes knowledgeable oracle user and developers very much in demand, and makes oracle knowledge and skills very portable.
Oracle can easily be used for simple operations such as entering multiple data and running standard reports. But an approach would ignore its great power; it would be like be buying a high performance racing car, and then pulling it around with a horse.
Oracle is an Object-relational database. A relational database is an extremely simple way of thinking and managing the data used in business. It is nothing more than a collection of tables of data. We all encounter table every day: weather reports, stocks charts, sports scores. These all tables, with column headings and rows of information simply presented. Even so the relational approach can be sophisticated and powerful enough for even the most complex of business. An object relational database supports all of the the features of a relational database while also supporting object-oriented concepts and features.
Database:-
A collection of information organized in such a way Data computer program can quickly selected desired field data. Database is an electronic file system. The software which is managing this database is called RDBMS.
ORACLE DATABASE:-
- Oracle is the world’s most popular DBMS
- It is a powerful and robust DBMS that runs on many different operating systems
- Oracle DBMS engine: Personal Oracle and Enterprise Oracle
- Example of Oracle products
- SQL*Plus: a utility for processing SQL and creating components like stored procedures and triggers
- PL/SQL is a programming language that adds programming constructs to the SQL language
- Oracle Developer (Forms & Reports Builder)
- Oracle Designer
Creating an Oracle Database:-
- Install Oracle 9i Client to use an already created database
- Install Oracle 9i Personal Edition to create your own databases
- Three ways to create an Oracle database
- Via the Oracle Database Configuration Assistant
- Via the Oracle-supplied database creation procedures
- Via the SQL CREATE DATABASE command
What is SQL?
- SQL stands for Structured Query Language. It is a standard and programming language.
- SQL lets you access and manipulate databases
- SQL is an ANSI (American National Standards Institute) standard.
- American National Standard Institute is primary organization for fostering of technology standard. Long established computer standard includes the American code for information interchange (ANSI).
- Some common RDBMS are that is used SQL, ORACLE.CYBASE, and SQL SERVER.
SQL SELECT STATEMENT:-
- Projection:- Used to choose the column in a table that we
want to return by Query.
- Selection:-Used to choose the row in a table that we want to
return by Query.
- Joining:-Used to bring together data that stored in different
table.
What Can SQL do?
- SQL can execute queries against a database
- SQL can retrieve data from a database
- SQL can insert records in a database
- SQL can update records in a database
- SQL can delete records from a database
- SQL can create new databases
- SQL can create new tables in a database
- SQL can create stored procedures in a database
- SQL can create views in a database
- SQL can set permissions on tables, procedures, and views
SQL*Plus:-
- Oracle SQL*Plus or the Oracle Enterprise Manager Console may be used to manage an Oracle database
- SQL*Plus is a text editor available in all Oracle
- Except inside quotation marks of strings, Oracle commands are case-insensitive
- The semicolon (;) terminates a SQL statement
- The right-leaning slash (/) executes SQL statement stored in Oracle buffer
- SQL*Plus can be used to
- Enter SQL statements
- Submit SQL files created by text editors, e.g., notepad, to Oracle


Oracle Data Types

DATABASE OBJECTS:-
- TABLE
- VIEW
- SEQUENCE
- INDEX
- SYNONYM
Creating Tables:-
- It is a basic unit of storage composed of rows and column.
- Some of the SQL CREATE TABLE statements need to be modified for Oracle
- Oracle does not support a CASCADE UPDATE constraint
- Int data type is interpreted by Oracle as Number(38)
- Varchar data type is interpreted as VarChar2
- Money or currency is defined in Oracle using the Numeric data type
- DESCRIBE or DESC command is used to view table status
A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.
Below is an example of a table called "EMP":
The table above contains three records (one for each person) and five columns (P_Id, LastName, FirstName, Address, and City).
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | DEPTNO
|
7369 | SMITH | CLERK | 7902 | 17-DEC-80 | 8000
| 20 |
7499 | ALLEN | MANAGER | 7698 | 20-FEB-81 | 16000 | 30
|
7521 | WARD | SALESMAN | 7698 | 22-FEB-81 | 12500 | 30
|
SQL Statemnt
SELECT |
| Data retrieval |
INSERT UPDATE DELETE MERGE |
|
Data manipulating language(DML)
|
CREATE ALTER DROP RENAME TRUNCATE |
|
Data definition language(DDL)
|
COMMIT ROLLBACK SAVEPOINT |
| Transaction control |
GRANT REVOKE
|
| Data control language(DCL)
|
|
|
|
Statement
| Description |
|
SELECT | Retrieves data from database |
|
INSERT UPDATE DELETE MERGE | Enter new rows, changes existing rows and removes unwanted rows from tables in the database, respectively.
|
|
CREATE ALTER DROP RENAME TRUNCATE | Set up changes and removes data structures from the tables.
|
|
COMMIT ROLLBACK SAVEPOINT
| Manages the changes made by DML statements. Changes to the data can be grouped together into logical transactions.
|
|
GRANT REVOKE | Gives or remove access rights to both the Oracle database and the structure with in it. |
|
|
|
|
SELECT Statement
The result of a SELECT query is a result set that includes the rows and columns that satisfy your query.
SELECT - specifies the columns or fields to be included in the result set
FROM - identifies the tables or views from which the data will be retrieved
WHERE - the predicate(s) that determine which rows will be retrieved
ORDER BY - determines the sequence of the rows
SELECT Statement Syntax
SELECT {ALL|DISTINCT}
columns {AS newname}
FROM table
{WHERE conditions}
{GROUP BY fields}
{HAVING conditions}
ORDER BY column integer {ASC|DESC}
DESCRIBE the table
Disc pbowman. employee;
OUTPUT
Name Null? Type
EMPLOYEE_ID NOT NULL NUMBER(4)
LAST_NAME VARCHAR2(15)
FIRST_NAME VARCHAR2(15)
MIDDLE_INITIAL VARCHAR2(1)
JOB_ID NUMBER(3)
MANAGER_ID NUMBER(4)
HIRE_DATE DATE
SALARY NUMBER(7,2)
COMMISSION NUMBER(7,2)
DEPARTMENT_ID NUMBER(2)
Inserting:-
INSERT INTO employees (employee_id, last_name, email, hire_date, job_id, salary, commission_pct)
VALUES (207, 'Gregory', 'pgregory@oracle.com', sysdate, 'PU_CLERK', 1.2E3, NULL);
- The following statement has the same effect as the preceding example, but uses a subquery in the DML_table_expression_clause:
INSERT INTO (SELECT employee_id, last_name, email, hire_date, job_id, salary, commission_pct FROM employees)
VALUES (207, 'Gregory', 'pgregory@oracle.com', sysdate, 'PU_CLERK', 1.2E3, NULL);
Coding Predicates in a SELECT
The Predicates are found in the WHERE clause of the SELECT statement
Used to identify which rows we want Basic predicates compare only 2 values
The result is either True or False. If the value of either operand is null or the result of the subselect is empty, the result of the predicate is unknown.
- Compound Predicate-All of the predicate forms can be combined using the compound logical operators
Example- AND, OR, and NOT
WHERE {NOT} predicate AND|OR
{NOT} predicate …
The result is either TRUE, FALSE, or Unknown about a given row or group of rows (grouping predicates) If you don’t use parentheses, these operators are processed in this order: NOT, AND, OR.
- IN Predicate:-Tests if the value equals another value in a provided set of values.
WHERE field {NOT} IN(field1, field2, field3)
Equivalent to = ANY
Field can be a value, set or sub query
- BETWEEN Predicate:-Tests if the value of a field falls (inclusively) between two other values
WHERE field {NOT} BETWEEN field AND field
Logically Comparable to using >= and <=
- NULL Predicate:-A “NULL” value is the relational database representation of ‘no value exists’
WHERE field IS {NOT} NULL
Due to the complexity of null handling, usage of Nulls has been discouraged in FSU/AIS database table columns
- LIKE Predicate:-Powerful for character string comparisons
If a pattern does not contain the “%” character, the condition can be TRUE only if both operands have the same length
WHERE field {NOT} LIKE value
Wildcard characters:-
1. % - string of zero or more characters ‘ABC%’
2._ - underscore - any single character ‘A_C’
Examples:-
WHERE ename LIKE ‘MA%’
WHERE ename LIKE ‘SMITH_’
WHERE ename LIKE ‘S_I%’
Oracle SQL Functions:-
- Number Functions:- Number functions accept numeric input and return numeric values:
Example- ABS(n), ROUND(n[,m]), TRUNC(n[,m])
- Character Functions: - Character functions accept character input and return either character or numeric values. This first group of functions accepts character input and returns character values. The second group of functions accepts character input and returns numeric values.
Example:-
CONCAT(char1,char2),INITCAP(char),LOWER(char), LTRIM(char[,set]), LPAD (char, n [, char2])
- Group Functions:- Default is to include all the candidate rows, but using DISTINCT causes the group functions to use only the distinct values of the argument expression.
Example- AVG ([DISTINCT | ALL] n), COUNT (* | [DISTINCT | ALL] expr ),MAX([DISTINCT | ALL] expr),MIN ([ DISTINCT | ALL] expr)
,STDDEV([DISTINCT | ALL] n) ,SUM([DISTINCT | ALL] n),
VARIANCE ([DISTINCT | ALL] n)
- Date Functions and formats:- Date functions operate on values of the DATE data type. All date functions return a value of DATE datatype, except the MONTHS_BETWEEN function, which returns a number.
Example-TRUNC (d [,fmt]),SYSDATE,ROUND (d[,fmt]),NEXT_DAY(d,char)
NEW_TIME (d, a, b), MONTHS_BETWEEN (d, e)
- Conversion Functions:- Conversion functions convert a value from one data type to another. Generally, the form of the function names follows the convention data type TO data type the first data type is the input data type; the last data type is the output data type.
Example-The SYSDATE function returns the current date and time from Oracle. If you want to only manipulate the CURRENT DATE, and you are not selecting other columns from a table, you may issue a SELECT statement using the Oracle one row table:
SELECT SYSDATE FROM DUAL;
Group Function:-
Occurs any time detail information is used only for the purpose of deriving summary information
Used to cluster your result into sets, or “groups” of rows that have equal values in the same columns
Use GROUP BY and HAVING
SYNTAX- SELECT fields FROM tables
WHERE conditions
GROUP BY fields
HAVING conditions
ORDER BY fields
GROUP BY is used to summarize the columns selected. HAVING optionally follows the GROUP BY and can be used to place a condition on the GROUP
The HAVING condition can reference:
- One of the columns
- A column function applied to the rows of the groups
- A sub query which only returns one row
Functions Commonly Used With Group By
- COUNT:– count no. of rows where expression evaluates to something.
- MAX :– gives max. value of expression ignoring null values.
- MIN:- gives min. value of expression ignoring null values.
- STDDEV:- gives standard deviation of expression ignoring null values.
- VARIANCE :- gives variance of expression ignoring null values.
- SUM:- gives sum of value of expression ignoring null values.
Example:-
SELECT State ,Count (*) as Total
FROM pbowman.CUSTOMER
GROUP BY State;
Result:- ST TOTAL
CA 8
MA 6
MN 1
NY 9
Joining Tables:-
- Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join.
- Tables in a database can be related to each other with keys.
- A primary key is a column OUTER JOIN return all rows from one table which is called the inner table.
- An OUTER JOIN also retrieves matching rows from a second table, which is called the outer table.
- The query designer specifies which tables are the inner and outer tables.
- Syntax to create an outer join.
- Inner_table.join_field = outer_table.join_field(+)
- The outer join marker (+) signals the DBMS to insert a NULL value for the fields in the outer table that do not have matching rows in the inner table.
- with a unique value for each row.
- The purpose is to bind data together, across tables, without repeating all of the data in every table.
- The INNER JOIN returns all rows from both tables where there is a match.
- If there are rows in Employees that do not have matches in Orders, those rows will not be listed.
- There are variants of the join operation that rely on NULL values, these are called outer joins and they are supported in SQL.
- Consider the join of two tables employees and orders
- Tuples of employees that do not match a row in orders on some join condition would not appear in the result
- The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders).
- If there are rows in Employees that do not have matches in Orders, those rows also will be listed.
SELECT Employees.Name, Orders.Product
FROM Employees LEFT JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID
- The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees).
- If there had been any rows in Orders that did not have matches in Employees, those rows also would have been listed.
SELECT Employees.Name, Orders.Product
FROM Employees RIGHT JOIN Orders ON
Employees.Employee_ID=Orders.Employee_ID
Example:-
SELECT emp.name, emp.id, payroll.rate FROM emp, payroll
WHERE emp.id=payroll.id;
SELECT emp.name, emp.id, payroll.rat
FROM emp INNER JOIN payroll
ON emp.id=payroll.id
Table Aliases:-
SELECT workers.name, workers.id, payroll.rate
FROM workers, payroll
WHERE workers.id=payroll.id;
SELECT w.name, w.id, p.rate FROM workers w, payroll p WHERE w.id=p.id;
Error handling:-
- Prevents database locking
- Ensures that errors are presented to the user in a sensible format
- Makes code robust
- Essential when using PL/SQL as formal programming language or interfacing with Oracle applications.
GRANT:-
- Use the GRANT statement to grant: System privileges to users and roles
- Roles to users and roles. Both privileges and roles are either local, global, or external
- To grant the CREATE SESSION system privilege to the sample user hr, allowing hr to log on to Oracle Database, issue the following statement:
GRANT CREATE SESSION TO hr;
- To grant the dw_manager role with the ADMIN OPTION to the sample user sh, issue the following statement:
GRANT dw_manager TO sh WITH ADMIN OPTION;
REVOKE:-
- Use the REVOKE statement to: Revoke system privileges from users and roles
- Revoke roles from users and roles
- Revoke object privileges for a particular object from users and roles
REVOKE UPDATE ON hr.employees FROM oe;
Restrictions On Column Modifications:-
- A column may be dropped at any time and all data will be lost
- A column may be added at any time as long as it is a NULL column
- To add a NOT NULL column
- Add a NULL column
- Fill the new column in every row with data
- Change its structure to NOT NULL
- ALTER TABLE T1 MODIFY C1 NOT NULL;
DROP and ALTER Statements:-
- Drop statements may be used to remove structures from the database
- Any data in the MYTABLE table will be lost
- DROP SEQUENCE MySequence;
- ALTER statement may be used to drop (add) a column
- ALTER TABLE MYTABLE DROP COLUMN MyColumn;
- ALTER TABLE MYTABLE ADD C1 NUMBER(4);
TO_DATE Function:-
Oracle requires dates in a particular format
- TO_DATE function may be used to identify the format
- TO_DATE(‘11/12/2002’,’MM/DD/YYYY’)
- 11/12/2002 is the date value
- MM/DD/YYYY is the pattern to be used when interpreting the date
- TO_DATE function can be used with the INSERT and UPDATE statement to enter data
- INSERT INTO T1 VALUES (100, TO_DATE (‘01/05/02’, ‘DD/MM/YY’);
VIEW:-
- It logically represents subset from one or more tables.
- SQL-92 CREATE VIEW command can be used to create views in SQL*Plus
- Oracle allows the ORDER BY clause in view definitions
- Only Oracle 9i supports the JOIN…ON syntax
- Example:-
SELECT ename, job, deptno
FROM emp
Where deptno=20
- SELECT * FROM V1
- DROP VIEW V1
Sequences:-
- A sequence is an object that generates a sequential series of unique numbers
- It is the best way to work with surrogate keys in Oracle
- Two sequence methods
- NextVal provides the next value in a sequence
- CurrVal provides the current value in a sequence
- Using sequences does not guarantee valid surrogate key values because it is possible to have missing, duplicate, or wrong sequence value in the table
Example:-
Create SEQUENCE SEQUENCENAME
Increment By N
Start with N
Max value n/No max value
Min value n/No min value
DROP SEQUENCE SEQUENCENAME
Creating Indexes:-
- Enforce uniqueness on columns
- Facilitate sorting
- Enable fast retrieval by column values
- Good candidates for indexes are columns that are frequently used with equal conditions in WHERE clause or in a join
- Example:
- CREATE INDEX CustNameIdx ON CUSTOMER(Name);
- CREATE UNIQUE INDEX WorkUniqueIndex ON WORK(Title, Copy, ArtistID);
SYNONYM:-
- To refer to a table owned by another user we need to prefix the table name with the name of the user who create it followed by a period.
SYNTAX-
CREATE PUBLIC SYNONYM SYNONYMNAME
FOR USERNAME.TABLENAME
EXAMPLE-
CREATE PUBLIC SYNONYM LOC
FOR SMITH.LOCATION
DROP SYNONYM SYNONYMNAME
Enterprise Manager Console:-
- The Oracle Enterprise Manager Console provides graphical facilities for managing an Oracle database
- The utility can be used to manage
- Database structures such as tables and views
- User accounts, passwords, roles, and privileges
- The Manager Console includes a SQL scratchpad for executing SQL statements
Application Logic:-
- Oracle database application can be processed using
- Programming language to invoke Oracle DBMS commands
- Stored procedures
- Start command to invoke database commands stored in .sql files
- Triggers
PL/SQL:-
- PL/SQL stands for "Procedural Language extensions to SQL." Interpreted language
- Commands are not case sensitive except for character strings
- ; semicolon marks the end of each line
- Contains reserved words
- Contains built-in functions
- Instructions to Oracle identifying the information you wish to select, insert, delete or update
- SQL*Plus is Oracle's version of the SQL standard
- Notes on SQL are on Blackboard
BENIFITS OF PL/SQL:-
1. Easy Maintenance
2. Procedural extension allowing for modularity, variable declaration, 3. loops and logical constructs.
4. Allows for advanced error handling
5. Communicates natively with other oracle database objects.
6. Managed centrally within the Oracle database
7. All have procedural facilities
8. SQL is not functionally complete
9. So top up functionality by embedding SQL in a procedural language
10. PL/SQL techniques are specific to Oracle, Lacks full facilities of a programming language
11.but procedures and functions can be ported to other systems
Advantages of using PL/SQL to access Oracle:-
- PL/SQL is managed centrally within the database
- Code is managed by the DBA and execution privileges are managed in the same was as with other objects
- PL/SQL objects are first-class Oracle DB objects
- Easy to read
- With modularity features and error handling
Using PL/SQL as a programming language:-
- Permits all operations of standard programming languages e.g.
- Conditions IF-THEN-ELSE-END IF;
- Jumps GOTO
- Provides loops for controlling iteration
- LOOP-EXIT; WHEN-END LOOP; FOR-END LOOP; WHILE-END LOOP
- Allows extraction of data into variables and its subsequent manipulation
BODY OF PL/SQL:-
A PL/SQL block has the following three parts:
- Declaration Part
- Executable Part
- Exception Part
Only the Executable part is mandatory; the other two are optional
Example:-
[DECLARE
----- declarations]
BEGIN
----- statements
[EXCEPTION
----- handlers]
END;
- Used to describe variables of both SQL and PL/SQL data types and to assign initial values
- Contains both SQL commands and PL/SQL control flow constructs like IF-THEN-ELSE, FOR-LOOP, WHILE-LOOP, etc.
- Handles error conditions during execution. Errors could be user defined errors or database errors.
Modules in PL/SQL:-
There are 4 types of modules in PL/SQL
- Procedures – series of statements may or may not return a value
- Function – series of statements must return a single value
- Triggers – series of PL/SQL statements (actions) executing after an event has triggered a condition (ECA)
- Packages – collection of procedures and function that has 2 parts:
Procedures:-
- A Procedure is a type of subprogram that perform a action and does not return a value.
- Promotes reusability and maintainbility.
- Modes:
- IN: procedure must be called with a value for the parameter. Value cannot be changed
- OUT: procedure must be called with a variable for the parameter. Changes to the parameter are seen by the user (i.e., call by reference)
- IN OUT: value can be sent, and changes to the parameter are seen by the user
Example:-
Create or replace query_emp(p_id IN
emp.empno%TYPE,p_name OUT emp.ename%TYPE)
BEGAIN SELECT ename,sal,deptno INTO p_name,p_sal,p_deptno from emp
Where empno=p_id;
END;
ISQL*PLUS-Execute query_emp(1046,:name);
PRINT NAME
FUNCTION:-
Almost exactly like creating a procedure, but you
supply a return type
Syntax:-
CREATE [OR REPLACE] FUNCTION function_name
[(parameter1 [mode1] datatype1,parameter2 [mode2] datatype2, . . .)]
RETURN datatype
IS|AS
PL/SQL Block;
Creating a function:-
create or replace function squareFunc(num in number)
return number
is
BEGIN
return num*num;
End;
Using thefunction:-
BEGIN
dbms_output.put_line(squareFunc(3.5));
END;
PACKAGE:-
- Functions, Procedures, Variables can be put together in a package
- There are also many predefined Oracle packages
- In a package, you can allow some of the members to be "public" and some to be "private“
- We can create Package in two part:-
-Package Specification
-Package Body
Triggers:-
- Triggers are special procedures which we want activated when someone has performed some action on the DB.
- For example, we might define a trigger that is executed when someone attempts to insert a row into a table, and the trigger checks that the inserted data is valid.
- Example-
- Create [or Replace] TRIGGER Triggername
- [Before /After /Instead of]
- [DML Event]
- [WHEN Condition]
- Triggers are special procedures which we want activated when someone has performed some action on the DB.
- For example, we might define a trigger that is executed when someone attempts to insert a row into a table, and the trigger checks that the inserted data is valid.
- Example-
- Create [or Replace] TRIGGER Triggername
- [Before /After /Instead of]
- [DML Event]
- [WHEN Condition]
Cursor overview:-
- Very powerful in PL/SQL modules
- Allows more than one set of data to be retrieved and accessed at the same time in loops
- Sets are created by executing SQL statements embedded in the PL/SQL code
- Cursor attributes - %notfound, %rowcount, %found & %isopen
Trapping Exceptions:-
- Here we define the actions that should happen when an exception is thrown.
- Example Exceptions:
- NO_DATA_FOUND
- TOO_MANY_ROWS
- ZERO_DIVIDE
- When handling an exception, consider performing a rollback
Example:-
DECLARE
num_row number_table%ROWTYPE;
BEGIN
select *
into num_row
from number_table;
dbms_output.put_line(1/num_row.num);
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('No data!');
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line('Too many!');
WHEN OTHERS THEN
dbms_output.put_line(‘Error’);
end;
Records in PL/SQL
A PL/SQL record is a data structure composed of multiple pieces of information called fields. To use a record, you must first define it and declare a variable of this type. There are three types of records: table-based, cursor-based, and programmer-defined.
Declaring Records
You define and declare records either in the declaration section of a PL/SQL block or globally, via a package specification.
You do not have to explicitly define table-based or cursor-based records, as they are implicitly defined with the same structure as a table or a cursor. Variables of these types are declared via the %ROWTYPE attribute. The record's fields correspond to the table's columns or the columns in the SELECT list. For example:
DECLARE
-- Declare table-based record for company table.
comp_rec company%ROWTYPE
CURSOR comp_summary_cur IS
SELECT C.company_id,SUM(S.gross_sales) gross
FROM company C, sales S
WHERE C.company_id = S.company_id;
-- Declare a cursor-based record.
comp_summary_rec comp_summary_cur%ROWTYPE;
Programmer-defined records must be explicitly defined with the TYPE statement in the PL/SQL declaration section or in a package specification. Variables of this type can then be declared as shown here:
DECLARE
TYPE name_rectype IS RECORD(
prefix VARCHAR2(15)
,first_name VARCHAR2(30)
,middle_name VARCHAR2(30)
,sur_name VARCHAR2(30)
,suffix VARCHAR2(10) );
TYPE employee_rectype IS RECORD (
emp_id NUMBER(10) NOT NULL
,mgr_id NUMBER(10)
,dept_no dept.deptno%TYPE
,title VARCHAR2(20)
,name empname_rectype
,hire_date DATE := SYSDATE
,fresh_out BOOLEAN );
-- Declare a variable of this type.
new_emp_rec employee_rectype;
BEGIN
PL/SQL (Simple and Compound Symbols):-
Symbol Description
- ; Semicolon: statement terminator
- % Percent sign: attribute indicator (cursor attributes like %ISOPEN and indirect declaration attributes like % ROWTYPE).Also used as multibyte wildcard symbol, as in SQL.
- _ Single underscore: single-byte wildcard symbol, as in SQL
- : Colon: host variable indicator, such as :block.item in Oracle Forms
- ** Double asterisk: exponentiation operator
- < > and != "Not equals"
- || Double vertical bar: concatenation operator
- << and >> Label delimiters
- <= and >= Relational operators
- := Assignment operator
- => Association operator for positional notation
- -- Double dash: single-line comment indicator
- /* and */ Beginning and ending multiline comment block delimiters
REFERENCE:-