Number types in pl/sql, PL-SQL Programming

Assignment Help:

Number Types

The Number types permit you to store the numeric data (real numbers, integers, and floating-point numbers), show quantities, and do computations.

BINARY_INTEGER

You use the BINARY_INTEGER datatype to store the signed integers. Its magnitude ranges from -2147483647 to 2147483647. Like PLS_INTEGER values, BINARY_INTEGER values need less storage than NUMBER values. Though, most BINARY_INTEGER operations are slower than the PLS_INTEGER operations.

BINARY_INTEGER Subtypes

A base type is the datatype from which a subtype is derived. A subtype links a base type with a constraint and so defines a subset of the values. For your convenience, the PL/SQL predefines the following BINARY_INTEGER subtypes as shown below:

NATURAL

NATURALN

POSITIVE

POSITIVEN

SIGNTYPE

The subtypes NATURAL & POSITIVE restrict an integer variable to non-negative or positive values, respectively. The NATURALN and POSITIVEN prevent the assigning of nulls to an integer variable. The SIGNTYPE restrict an integer variable to the values -1, 0, and 1, which is useful in the programming tri-state logic.

NUMBER

You use the NUMBER datatype to store a fixed-point or floating-point numbers of virtually any sizes. Its magnitude range is 1E-130 to 10E125. If the value of an expression falls exterior to this range, you get a numeric overflow or underflow error. You can specify the precision that is the total number of digits, and the scale, which is the number of digits to the right of the decimal point. The syntax is as shown below:

NUMBER[(precision,scale)]

To declare a fixed-point numbers, for which you must specify the scale, use the form as shown:

NUMBER(precision,scale)

To declare a floating-point numbers, for which you cannot identify the precision or scale as the decimal point can "float" to any position, use the form as shown:

NUMBER

To declare the integers, that have no decimal point, use the form sown below:

NUMBER(precision) -- same as NUMBER(precision,0)

You cannot use the constants or variables to specify the precision and scale; you should use the integer literals. The highest precision of a NUMBER value is 38 decimal digits. If you do not specify the precision, it default to 38 or the highest supported by your system, either is less.

NUMBER Subtypes

You can use the NUMBER subtypes for compatibility with ANSI/ISO and IBM types or when you want a more expressive name:

DEC

DECIMAL

DOUBLE PRECISION

FLOAT

INTEGER

INT

NUMERIC

REAL

SMALLINT

Use the subtypes DEC, DECIMAL, & NUMERIC to declare the fixed-point numbers with a greatest precision of 38 decimal digits.

Use the subtypes DOUBLE PRECISION & FLOAT to declare the floating-point numbers with a greatest precision of 126 binary digits, which is roughly equal to 38 decimal digits. Or, use the subtype REAL to declare a floating-point numbers with a greatest precision of 63 binary digits, which is roughly equal to 18 decimal digits.

Use the subtypes INTEGER, INT, & SMALLINT to declare integers with a greatest precision of 38 decimal digits.

PLS_INTEGER

You use the PLS_INTEGER datatype to store the signed integers. Its magnitude ranges from

2147483647 to 2147483647. The PLS_INTEGER values need less storage than NUMBER values. The PLS_INTEGER operations also use the machine arithmetic; therefore they are faster than NUMBER & BINARY_INTEGER operations that use library arithmetic. For superior performance, use PLS_INTEGER for all computations that fall within its magnitude range.

Though PLS_INTEGER and BINARY_INTEGER have the same magnitude range, they are not fully compatible. If a PLS_INTEGER computations overflows, an exception is raised. However, if  a BINARY_INTEGER calculation overflows, no exception is raised if the result is assigned to a NUMBER variable.Number Types

The Number types permit you to store the numeric data (real numbers, integers, and floating-point numbers), show quantities, and do computations.

BINARY_INTEGER

You use the BINARY_INTEGER datatype to store the signed integers. Its magnitude ranges from -2147483647 to 2147483647. Like PLS_INTEGER values, BINARY_INTEGER values need less storage than NUMBER values. Though, most BINARY_INTEGER operations are slower than the PLS_INTEGER operations.

BINARY_INTEGER Subtypes

A base type is the datatype from which a subtype is derived. A subtype links a base type with a constraint and so defines a subset of the values. For your convenience, the PL/SQL predefines the following BINARY_INTEGER subtypes as shown below:

NATURAL

NATURALN

POSITIVE

POSITIVEN

SIGNTYPE

The subtypes NATURAL & POSITIVE restrict an integer variable to non-negative or positive values, respectively. The NATURALN and POSITIVEN prevent the assigning of nulls to an integer variable. The SIGNTYPE restrict an integer variable to the values -1, 0, and 1, which is useful in the programming tri-state logic.

NUMBER

You use the NUMBER datatype to store a fixed-point or floating-point numbers of virtually any sizes. Its magnitude range is 1E-130 to 10E125. If the value of an expression falls exterior to this range, you get a numeric overflow or underflow error. You can specify the precision that is the total number of digits, and the scale, which is the number of digits to the right of the decimal point. The syntax is as shown below:

NUMBER[(precision,scale)]

To declare a fixed-point numbers, for which you must specify the scale, use the form as shown:

NUMBER(precision,scale)

To declare a floating-point numbers, for which you cannot identify the precision or scale as the decimal point can "float" to any position, use the form as shown:

NUMBER

To declare the integers, that have no decimal point, use the form sown below:

NUMBER(precision) -- same as NUMBER(precision,0)

You cannot use the constants or variables to specify the precision and scale; you should use the integer literals. The highest precision of a NUMBER value is 38 decimal digits. If you do not specify the precision, it default to 38 or the highest supported by your system, either is less.

NUMBER Subtypes

You can use the NUMBER subtypes for compatibility with ANSI/ISO and IBM types or when you want a more expressive name:

DEC

DECIMAL

DOUBLE PRECISION

FLOAT

INTEGER

INT

NUMERIC

REAL

SMALLINT

Use the subtypes DEC, DECIMAL, & NUMERIC to declare the fixed-point numbers with a greatest precision of 38 decimal digits.

Use the subtypes DOUBLE PRECISION & FLOAT to declare the floating-point numbers with a greatest precision of 126 binary digits, which is roughly equal to 38 decimal digits. Or, use the subtype REAL to declare a floating-point numbers with a greatest precision of 63 binary digits, which is roughly equal to 18 decimal digits.

Use the subtypes INTEGER, INT, & SMALLINT to declare integers with a greatest precision of 38 decimal digits.

PLS_INTEGER

You use the PLS_INTEGER datatype to store the signed integers. Its magnitude ranges from

2147483647 to 2147483647. The PLS_INTEGER values need less storage than NUMBER values. The PLS_INTEGER operations also use the machine arithmetic; therefore they are faster than NUMBER & BINARY_INTEGER operations that use library arithmetic. For superior performance, use PLS_INTEGER for all computations that fall within its magnitude range.

Though PLS_INTEGER and BINARY_INTEGER have the same magnitude range, they are not fully compatible. If a PLS_INTEGER computations overflows, an exception is raised. However, if  a BINARY_INTEGER calculation overflows, no exception is raised if the result is assigned to a NUMBER variable.


Related Discussions:- Number types in pl/sql

I need sql - wp sql expert, I need SQL , WP SQL Expert Project Descripti...

I need SQL , WP SQL Expert Project Description: Expert required to modify WP SQL query. Skills required are MySQL, SQL, PHP, Wordpress

Operators on tables and rows, Operators on Tables and Rows Row Extrac...

Operators on Tables and Rows Row Extraction TUPLE FROM r, SQL has row subqueries. These are just like scalar subqueries except that they may specify more than one column.

Logical connectives - sql, Logical Connectives - SQL SQL's extended t...

Logical Connectives - SQL SQL's extended truth tables in which the symbol, for unknown, appears along with the usual T and F. Negation (NOT, ¬) Conjunction (

Implement a new discount for return shoppers, Brewbean's is implementing a ...

Brewbean's is implementing a new discount for return shoppers - every fifth completed order receives a 10% discount. The count of orders for a shopper is placed in a packaged varia

Effects of null, Effects of NULL The numeric variable X, perhaps of ty...

Effects of NULL The numeric variable X, perhaps of type INTEGER, might be assigned NULL. In that case the result of evaluating X + 1 is NULL, and so SET Y = X + 1 assigns NULL

Homework, What are the rates for help in writing PL/SQL procedures and func...

What are the rates for help in writing PL/SQL procedures and functions?

Enforce security in the database system, Question: (a) In the context o...

Question: (a) In the context of database security explain how the following database features help to enforce security in the database system: (i) Authorisation (ii) Access

Declaring records, Declaring Records Whenever you define a RECORD type...

Declaring Records Whenever you define a RECORD type, you may declare records of that type, as the illustration shows: DECLARE TYPE StockItem IS RECORD ( item_no INTEG

Cartesian product, Using a Join on 2 tables, select all columns and all row...

Using a Join on 2 tables, select all columns and all rows from the tables without the use of a Cartesian product. Query: SELECT * FROM EMPLOYEE1 JOIN CONTRACT ON EMPLOYEE

Example of check constraints - sql, Example of Check Constraints Examp...

Example of Check Constraints Example: Workaround for when subqueries not permitted in CHECK constraints CREATE FUNCTION NO_MORE_THAN_20000_ENROLMENTS ( ) RETURNS BOOLEAN

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd