Tuesday, May 7, 2013

Oracle Data type

A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer. Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.

Few of the oracle data types can be found in the below link

Benefits of BINARY_FLOAT and BINARY_DOUBLE
BINARY_FLOAT and BINARY_DOUBLE are intended to complement the existing NUMBER type. BINARY_FLOAT and BINARY_DOUBLE offer the following benefits over NUMBER:
  • Smaller storage required BINARY_FLOAT and BINARY_DOUBLE require 5 and 9 bytes of storage space, whereas NUMBER might use up to 22 bytes.
  • Greater range of numbers represented BINARY_FLOAT and BINARY_DOUBLE support numbers much larger and smaller than can be stored in a NUMBER.
  • Faster performance of operations Operations involving BINARY_FLOAT and BINARY_DOUBLE are typically performed faster than NUMBER operations. This is because BINARY_FLOAT and BINARY_DOUBLE operations are typically performed in the hardware, whereas NUMBERs must first be converted using software before operations can be performed.
  • Closed operations Arithmetic operations involving BINARY_FLOAT and BINARY_DOUBLE are closed, which means that either a number or a special value is returned.
  • For example, if you divide a BINARY_FLOAT by another BINARY_FLOAT, a BINARY_FLOAT is returned.
  • Transparent rounding BINARY_FLOAT and BINARY_DOUBLE use binary (base 2) to represent a number, whereas NUMBER uses decimal (base 10). The base used to represent a number affects how rounding occurs for that number. For example, a decimal floatingpoint number is rounded to the nearest decimal place, but a binary floating-point number is rounded to the nearest binary place.
special value data types can also be used :-
Special Value                                                                    Description
BINARY_FLOAT_NAN                                 Not a number (NaN) for the BINARY_FLOAT type
BINARY_FLOAT_INFINITY                        Infinity (INF) for the BINARY_FLOAT type
BINARY_DOUBLE_NAN                             Not a number (NaN) for the BINARY_DOUBLE type
BINARY_DOUBLE_INFINITY                    Infinity (INF) for the BINARY_DOUBLE type



CREATE PROCEDURE pr_price (
p_product_id IN products.product_id%TYPE, --  the variable is of the type as the column product is in the table productp_factor IN NUMBER
) AS
product_count INTEGER;

BEGIN
-- count the number of products with the
-- supplied product_id (will be 1 if the product exists)
SELECT COUNT(*)
INTO product_count
FROM products
WHERE product_id = p_product_id;
-- if the product exists (i.e. product_count = 1) then
-- update that product's price
IF product_count = 1 THEN
UPDATE products
SET price = price * p_factor
WHERE product_id = p_product_id;
COMMIT;
END IF;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END pr_price;
/
SQL and SQLPLUS
SQL ( (Structured Query Language) is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS).
Originally based upon relational algebra and tuple relational calculus, SQL consists of a data definition language and a data manipulation language. The scope of SQL includes data insert, query, update and delete, schema creation and modification, and data access control. Although SQL is often described as, and to a great extent is, a declarative language (4GL), it also includes procedural elements.
“S-Q-L” is the correct way to pronounce SQL according to the
American National Standards Institute. However, the single word
“sequel” is frequently used instead.
SQL is based on the groundbreaking work of Dr. E.F. Codd, with the first implementation of SQL being developed by IBM in the mid-1970s. IBM was conducting a research project known as System R, and SQL was born from that project. Later, in 1979, a company then known as Relational Software Inc. (known today as Oracle Corporation) released the first commercial version of SQL. SQL is now fully standardized and recognized by the American National Standards Institute. SQL uses a simple syntax that is easy to learn and use. You’ll see some simple examples of its use in this chapter. There are five types of SQL statements, outlined in the following list:-
Query statements retrieve rows stored in database tables. You write a query using the SQL 
SELECT statement.
Data Manipulation Language (DML) statements modify the contents of tables. There are three DML statements:
  • INSERT adds rows to a table.
  • UPDATE changes rows.
  • DELETE removes rows.
Data Definition Language (DDL) statements define the data structures, such as tables, that make up a database. There are five basic types of DDL statements:
  • CREATE creates a database structure. For example, CREATE TABLE is used to create
  • a table; another example is CREATE USER, which is used to create a database user.
  • ALTER modifies a database structure. For example, ALTER TABLE is used to modify
  • a table.
  • DROP removes a database structure. For example, DROP TABLE is used to remove a
  • table.
  • RENAME changes the name of a table.
  • TRUNCATE deletes all the rows from a table.
Transaction Control (TC) statements either permanently record any changes made to rows, or undo those changes. There are three TC statements:
  • COMMIT permanently records changes made to rows.
  • ROLLBACK undoes changes made to rows.
  • SAVEPOINT sets a “save point” to which you can roll back changes.
Data Control Language (DCL) statements change the permissions on database structures.There are two DCL statements:
  • GRANT gives another user access to your database structures.
  • REVOKE prevents another user from accessing your database structures.
SQLPLUS:-
Oracle has a tool called SQL*Plus that allows us to enter SQL statements using the keyboard or to run a script containing SQL statements. SQL*Plus enables you to conduct a “conversation” with the database; you enter SQL statements and view the results returned by the database.The Oracle Database 11g version of SQL*Plus is slightly nicer than the Windows-only version. In the 11g version, you can scroll through
previous commands you’ve run by pressing the UP and DOWN ARROW keys on the keyboard.
RDBMS

A relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd. Most popular commercial and open source databases currently in use are based on the relational database model.
A short definition of an RDBMS may be a DBMS in which data is stored in the form of tables and the relationship among the data is also stored in the form of tables.


Oracle database
A relational database management system (DBMS) from Oracle, which runs on more than 80 platforms. Introduced in the late 1970s, Oracle was the first database product to run on a variety of platforms from micro to mainframe. The Oracle database is Oracle's flagship product, and version 11g was introduced in 2007.

Oracle 11g features include built-in testing for changes, the capability of viewing tables back in time, superior compression of all types of data and enhanced disaster recovery functions.

The "i" ,"g"and "c" Versions
Starting in 1999 with Version 8i, Oracle added the "i" to the version name to reflect support for the Internet with its built-in Java Virtual Machine (JVM). Oracle 9i added more support for XML in 2001. In 2003, Oracle 10g was introduced with emphasis on the "g" for grid computing, which enables clusters of low-cost, industry standard servers to be treated as a single unit.Further development lead to 11g in 2007 which slowly got developed to 12c.12c features Multi-Tenancy, CDB vs. PDB (CDB is an acronym for “Container Database” and PDB is an acronym for “Pluggable Database”),Split Data Dictionary,Faster Provisioning, Database Administration & Granularity Control Patching & Upgrades are some of its features.

Java Built In
With a JVM (Java interpreter) built into the DBMS, triggers and stored procedures can be written and executed in Java rather than Oracle's PL/SQL programming language. It enables Internet developers to write applications and database procedures in the same language. In addition, the JVM can also execute Enterprise JavaBeans (EJBs), turning the DBMS into an application server.
Advantages of DBMS



Improved data sharing: A database is designed as a shared resource. Authorized users are granted permission to use the database, and each user is provided one or more user views.  DBMS provides better access to data and better-managed data.

 Improved data security: When number of users increases to access the data, the risk of data security increases. But, DBMS provides a framework for better enforcement of data privacy and security policies. A database can be accessed only by proper authentication usually by verifying login and password.

  Better data integration: DBMS integrates the many different users' views into a single data repository. This gives clear picture of the organization's operations. It becomes much easier to see how actions in one segment of the company affect other segments.

 Minimized data inconsistency: Data inconsistency exists when different versions of the same data appear in different places. In a DBMS, by eliminating this data redundancy, we can improve data consistency. For example, if a customer address is stored only once, updating that becomes simple.

Improved data access: The DBMS makes it possible to produce quick answers to any queries.  A query is a request or a question put to the DBMS for data manipula­tion or retrieval. Without any programming experience, one can retrieve and display data very easily. The language used to write queries is called Structured Query Language (SQL). For example, records from EMP table can be displayed using the query “SELECT * FROM EMP”

 Improved decision making: Now a day business success depends on decision making which is based on quality information generated by databases. In DBMS, better-managed data and improved data access make it possible to generate quality information, on which better decisions are based.

 Program-Data Independence: The separation of data description (metadata) from the application programs that use the data is called data independence.  With the database approach, data descriptions are stored in a central location called the repository.  This allows an organization’s data to change without changing the application programs that process the data.

Disadvantages of a DBMS

Danger of a Overkill: For small and simple applications for single users a database system is often not advisable.

Complexity: A database system creates additional complexity and requirements. The supply and operation of a database management system with several users and databases is quite costly and demanding.

Qualified Personnel: The professional operation of a database system requires appropriately trained staff. Without a qualified database administrator nothing will work for long.

Costs: Through the use of a database system new costs are generated for the system itselfs but also for additional hardware and the more complex handling of the system.

Lower Efficiency: A database system is a multi-use software which is often less efficient than specialised software which is produced and optimised exactly for one problem.

 
A database is an organized collection of data. The data is typically organized to model relevant aspects of reality (for example, the availability of rooms in hotels), in a way that supports processes requiring this information (for example, finding a hotel with vacancies).
Wherever there is a system management of the same is required.This requirement gave rise to database management system.
A collection of programs that enables you to store, modify, and extract information from a database. There are many different types of DBMSs, ranging from small systems that run on personal computers to huge systems that run on mainframes. The following are examples of database applications:
  • computerized library systems
    • automated teller machines
  • flight reservation systems
    • computerized parts inventory systems
    From a technical standpoint, DBMSs can differ widely. The terms relational, network, flat, and hierarchical all refer to the way a DBMS organizes information internally. The internal organization can affect how quickly and flexibly you can extract information.
    Requests for information from a database are made in the form of a query, which is a stylized question. For example, the query
    select * from employee where emp_name ='&emp';
     this will return from the employee table the row which has emp_name as the one entered during run time.
    The set of rules for constructing queries is known as a query language. Different DBMSs support different query languages, although there is a semi-standardized query language called SQL (structured query language). Sophisticated languages for managing database systems are called fourth-generation languages, or 4GLs for short.
    The information from a database can be presented in a variety of formats. Most DBMSs include a report writer program that enables you to output data in the form of a report. Many DBMSs also include a graphics component that enables you to output information in the form of graphs and charts.