PL/SQL – Constants and Literals ”; Previous Next In this chapter, we will discuss constants and literals in PL/SQL. A constant holds a value that once declared, does not change in the program. A constant declaration specifies its name, data type, and value, and allocates storage for it. The declaration can also impose the NOT NULL constraint. Declaring a Constant A constant is declared using the CONSTANT keyword. It requires an initial value and does not allow that value to be changed. For example − PI CONSTANT NUMBER := 3.141592654; DECLARE — constant declaration pi constant number := 3.141592654; — other declarations radius number(5,2); dia number(5,2); circumference number(7, 2); area number (10, 2); BEGIN — processing radius := 9.5; dia := radius * 2; circumference := 2.0 * pi * radius; area := pi * radius * radius; — output dbms_output.put_line(”Radius: ” || radius); dbms_output.put_line(”Diameter: ” || dia); dbms_output.put_line(”Circumference: ” || circumference); dbms_output.put_line(”Area: ” || area); END; / When the above code is executed at the SQL prompt, it produces the following result − Radius: 9.5 Diameter: 19 Circumference: 59.69 Area: 283.53 Pl/SQL procedure successfully completed. The PL/SQL Literals A literal is an explicit numeric, character, string, or Boolean value not represented by an identifier. For example, TRUE, 786, NULL, ”tutorialspoint” are all literals of type Boolean, number, or string. PL/SQL, literals are case-sensitive. PL/SQL supports the following kinds of literals − Numeric Literals Character Literals String Literals BOOLEAN Literals Date and Time Literals The following table provides examples from all these categories of literal values. S.No Literal Type & Example 1 Numeric Literals 050 78 -14 0 +32767 6.6667 0.0 -12.0 3.14159 +7800.00 6E5 1.0E-8 3.14159e0 -1E38 -9.5e-3 2 Character Literals ”A” ”%” ”9” ” ” ”z” ”(” 3 String Literals ”Hello, world!” ”Tutorials Point” ”19-NOV-12” 4 BOOLEAN Literals TRUE, FALSE, and NULL. 5 Date and Time Literals DATE ”1978-12-25”; TIMESTAMP ”2012-10-29 12:01:01”; To embed single quotes within a string literal, place two single quotes next to each other as shown in the following program − DECLARE message varchar2(30):= ”That””s tutorialspoint.com!”; BEGIN dbms_output.put_line(message); END; / When the above code is executed at the SQL prompt, it produces the following result − That”s tutorialspoint.com! PL/SQL procedure successfully completed. Print Page Previous Next Advertisements ”;
Category: plsql
PL/SQL – Procedures
PL/SQL – Procedures ”; Previous Next In this chapter, we will discuss Procedures in PL/SQL. A subprogram is a program unit/module that performs a particular task. These subprograms are combined to form larger programs. This is basically called the ”Modular design”. A subprogram can be invoked by another subprogram or program which is called the calling program. A subprogram can be created − At the schema level Inside a package Inside a PL/SQL block At the schema level, subprogram is a standalone subprogram. It is created with the CREATE PROCEDURE or the CREATE FUNCTION statement. It is stored in the database and can be deleted with the DROP PROCEDURE or DROP FUNCTION statement. A subprogram created inside a package is a packaged subprogram. It is stored in the database and can be deleted only when the package is deleted with the DROP PACKAGE statement. We will discuss packages in the chapter ”PL/SQL – Packages”. PL/SQL subprograms are named PL/SQL blocks that can be invoked with a set of parameters. PL/SQL provides two kinds of subprograms − Functions − These subprograms return a single value; mainly used to compute and return a value. Procedures − These subprograms do not return a value directly; mainly used to perform an action. This chapter is going to cover important aspects of a PL/SQL procedure. We will discuss PL/SQL function in the next chapter. Parts of a PL/SQL Subprogram Each PL/SQL subprogram has a name, and may also have a parameter list. Like anonymous PL/SQL blocks, the named blocks will also have the following three parts − S.No Parts & Description 1 Declarative Part It is an optional part. However, the declarative part for a subprogram does not start with the DECLARE keyword. It contains declarations of types, cursors, constants, variables, exceptions, and nested subprograms. These items are local to the subprogram and cease to exist when the subprogram completes execution. 2 Executable Part This is a mandatory part and contains statements that perform the designated action. 3 Exception-handling This is again an optional part. It contains the code that handles run-time errors. Creating a Procedure A procedure is created with the CREATE OR REPLACE PROCEDURE statement. The simplified syntax for the CREATE OR REPLACE PROCEDURE statement is as follows − CREATE [OR REPLACE] PROCEDURE procedure_name [(parameter_name [IN | OUT | IN OUT] type [, …])] {IS | AS} BEGIN < procedure_body > END procedure_name; Where, procedure-name specifies the name of the procedure. [OR REPLACE] option allows the modification of an existing procedure. The optional parameter list contains name, mode and types of the parameters. IN represents the value that will be passed from outside and OUT represents the parameter that will be used to return a value outside of the procedure. procedure-body contains the executable part. The AS keyword is used instead of the IS keyword for creating a standalone procedure. Example The following example creates a simple procedure that displays the string ”Hello World!” on the screen when executed. CREATE OR REPLACE PROCEDURE greetings AS BEGIN dbms_output.put_line(”Hello World!”); END; / When the above code is executed using the SQL prompt, it will produce the following result − Procedure created. Executing a Standalone Procedure A standalone procedure can be called in two ways − Using the EXECUTE keyword Calling the name of the procedure from a PL/SQL block The above procedure named ”greetings” can be called with the EXECUTE keyword as − EXECUTE greetings; The above call will display − Hello World PL/SQL procedure successfully completed. The procedure can also be called from another PL/SQL block − BEGIN greetings; END; / The above call will display − Hello World PL/SQL procedure successfully completed. Deleting a Standalone Procedure A standalone procedure is deleted with the DROP PROCEDURE statement. Syntax for deleting a procedure is − DROP PROCEDURE procedure-name; You can drop the greetings procedure by using the following statement − DROP PROCEDURE greetings; Parameter Modes in PL/SQL Subprograms The following table lists out the parameter modes in PL/SQL subprograms − S.No Parameter Mode & Description 1 IN An IN parameter lets you pass a value to the subprogram. It is a read-only parameter. Inside the subprogram, an IN parameter acts like a constant. It cannot be assigned a value. You can pass a constant, literal, initialized variable, or expression as an IN parameter. You can also initialize it to a default value; however, in that case, it is omitted from the subprogram call. It is the default mode of parameter passing. Parameters are passed by reference. 2 OUT An OUT parameter returns a value to the calling program. Inside the subprogram, an OUT parameter acts like a variable. You can change its value and reference the value after assigning it. The actual parameter must be variable and it is passed by value. 3 IN OUT An IN OUT parameter passes an initial value to a subprogram and returns an updated value to the caller. It can be assigned a value and the value can be read. The actual parameter corresponding to an IN OUT formal parameter must be a variable, not a constant or an expression. Formal parameter must be assigned a value. Actual parameter is passed by value. IN & OUT Mode Example 1 This program finds the minimum of two values. Here, the procedure takes two numbers using the IN mode and returns their minimum using the OUT parameters. DECLARE a number; b number; c number; PROCEDURE findMin(x IN number, y IN number, z OUT number) IS BEGIN IF x < y THEN z:= x; ELSE z:= y; END IF; END; BEGIN a:= 23; b:= 45; findMin(a, b, c); dbms_output.put_line(” Minimum of (23, 45) : ” || c); END; / When the above code is executed at the SQL prompt, it produces the following result − Minimum of (23, 45) : 23 PL/SQL procedure successfully completed. IN & OUT Mode Example 2 This procedure computes the square of value of a passed value. This example shows how we can
PL/SQL – Overview
PL/SQL – Overview ”; Previous Next The PL/SQL programming language was developed by Oracle Corporation in the late 1980s as procedural extension language for SQL and the Oracle relational database. Following are certain notable facts about PL/SQL − PL/SQL is a completely portable, high-performance transaction-processing language. PL/SQL provides a built-in, interpreted and OS independent programming environment. PL/SQL can also directly be called from the command-line SQL*Plus interface. Direct call can also be made from external programming language calls to database. PL/SQL”s general syntax is based on that of ADA and Pascal programming language. Apart from Oracle, PL/SQL is available in TimesTen in-memory database and IBM DB2. Features of PL/SQL PL/SQL has the following features − PL/SQL is tightly integrated with SQL. It offers extensive error checking. It offers numerous data types. It offers a variety of programming structures. It supports structured programming through functions and procedures. It supports object-oriented programming. It supports the development of web applications and server pages. Advantages of PL/SQL PL/SQL has the following advantages − SQL is the standard database language and PL/SQL is strongly integrated with SQL. PL/SQL supports both static and dynamic SQL. Static SQL supports DML operations and transaction control from PL/SQL block. In Dynamic SQL, SQL allows embedding DDL statements in PL/SQL blocks. PL/SQL allows sending an entire block of statements to the database at one time. This reduces network traffic and provides high performance for the applications. PL/SQL gives high productivity to programmers as it can query, transform, and update data in a database. PL/SQL saves time on design and debugging by strong features, such as exception handling, encapsulation, data hiding, and object-oriented data types. Applications written in PL/SQL are fully portable. PL/SQL provides high security level. PL/SQL provides access to predefined SQL packages. PL/SQL provides support for Object-Oriented Programming. PL/SQL provides support for developing Web Applications and Server Pages. Print Page Previous Next Advertisements ”;
PL/SQL – Conditions
PL/SQL – Conditions ”; Previous Next In this chapter, we will discuss conditions in PL/SQL. Decision-making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false. Following is the general form of a typical conditional (i.e., decision making) structure found in most of the programming languages − PL/SQL programming language provides following types of decision-making statements. Click the following links to check their detail. S.No Statement & Description 1 IF – THEN statement The IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and END IF. If the condition is true, the statements get executed and if the condition is false or NULL then the IF statement does nothing. 2 IF-THEN-ELSE statement IF statement adds the keyword ELSE followed by an alternative sequence of statement. If the condition is false or NULL, then only the alternative sequence of statements get executed. It ensures that either of the sequence of statements is executed. 3 IF-THEN-ELSIF statement It allows you to choose between several alternatives. 4 Case statement Like the IF statement, the CASE statement selects one sequence of statements to execute. However, to select the sequence, the CASE statement uses a selector rather than multiple Boolean expressions. A selector is an expression whose value is used to select one of several alternatives. 5 Searched CASE statement The searched CASE statement has no selector, and it”s WHEN clauses contain search conditions that yield Boolean values. 6 nested IF-THEN-ELSE You can use one IF-THEN or IF-THEN-ELSIF statement inside another IF-THEN or IF-THEN-ELSIF statement(s). Print Page Previous Next Advertisements ”;
PL/SQL – Loops
PL/SQL – Loops ”; Previous Next In this chapter, we will discuss Loops in PL/SQL. There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages − PL/SQL provides the following types of loop to handle the looping requirements. Click the following links to check their detail. S.No Loop Type & Description 1 PL/SQL Basic LOOP In this loop structure, sequence of statements is enclosed between the LOOP and the END LOOP statements. At each iteration, the sequence of statements is executed and then control resumes at the top of the loop. 2 PL/SQL WHILE LOOP Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. 3 PL/SQL FOR LOOP Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. 4 Nested loops in PL/SQL You can use one or more loop inside any another basic loop, while, or for loop. Labeling a PL/SQL Loop PL/SQL loops can be labeled. The label should be enclosed by double angle brackets (<< and >>) and appear at the beginning of the LOOP statement. The label name can also appear at the end of the LOOP statement. You may use the label in the EXIT statement to exit from the loop. The following program illustrates the concept − DECLARE i number(1); j number(1); BEGIN << outer_loop >> FOR i IN 1..3 LOOP << inner_loop >> FOR j IN 1..3 LOOP dbms_output.put_line(”i is: ”|| i || ” and j is: ” || j); END loop inner_loop; END loop outer_loop; END; / When the above code is executed at the SQL prompt, it produces the following result − i is: 1 and j is: 1 i is: 1 and j is: 2 i is: 1 and j is: 3 i is: 2 and j is: 1 i is: 2 and j is: 2 i is: 2 and j is: 3 i is: 3 and j is: 1 i is: 3 and j is: 2 i is: 3 and j is: 3 PL/SQL procedure successfully completed. The Loop Control Statements Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. PL/SQL supports the following control statements. Labeling loops also help in taking the control outside a loop. Click the following links to check their details. S.No Control Statement & Description 1 EXIT statement The Exit statement completes the loop and control passes to the statement immediately after the END LOOP. 2 CONTINUE statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. 3 GOTO statement Transfers control to the labeled statement. Though it is not advised to use the GOTO statement in your program. Print Page Previous Next Advertisements ”;
PL/SQL – Environment
PL/SQL – Environment Setup ”; Previous Next In this chapter, we will discuss the Environment Setup of PL/SQL. PL/SQL is not a standalone programming language; it is a tool within the Oracle programming environment. SQL* Plus is an interactive tool that allows you to type SQL and PL/SQL statements at the command prompt. These commands are then sent to the database for processing. Once the statements are processed, the results are sent back and displayed on screen. To run PL/SQL programs, you should have the Oracle RDBMS Server installed in your machine. This will take care of the execution of the SQL commands. The most recent version of Oracle RDBMS is 11g. You can download a trial version of Oracle 11g from the following link − Download Oracle 11g Express Edition You will have to download either the 32-bit or the 64-bit version of the installation as per your operating system. Usually there are two files. We have downloaded the 64-bit version. You will also use similar steps on your operating system, does not matter if it is Linux or Solaris. win64_11gR2_database_1of2.zip win64_11gR2_database_2of2.zip After downloading the above two files, you will need to unzip them in a single directory database and under that you will find the following sub-directories − Step 1 Let us now launch the Oracle Database Installer using the setup file. Following is the first screen. You can provide your email ID and check the checkbox as shown in the following screenshot. Click the Next button. Step 2 You will be directed to the following screen; uncheck the checkbox and click the Continue button to proceed. Step 3 Just select the first option Create and Configure Database using the radio button and click the Next button to proceed. Step 4 We assume you are installing Oracle for the basic purpose of learning and that you are installing it on your PC or Laptop. Thus, select the Desktop Class option and click the Next button to proceed. Step 5 Provide a location, where you will install the Oracle Server. Just modify the Oracle Base and the other locations will set automatically. You will also have to provide a password; this will be used by the system DBA. Once you provide the required information, click the Next button to proceed. Step 6 Again, click the Next button to proceed. Step 7 Click the Finish button to proceed; this will start the actual server installation. Step 8 This will take a few moments, until Oracle starts performing the required configuration. Step 9 Here, Oracle installation will copy the required configuration files. This should take a moment − Step 10 Once the database files are copied, you will have the following dialogue box. Just click the OK button and come out. Step 11 Upon installation, you will have the following final window. Final Step It is now time to verify your installation. At the command prompt, use the following command if you are using Windows − sqlplus “/ as sysdba” You should have the SQL prompt where you will write your PL/SQL commands and scripts − Text Editor Running large programs from the command prompt may land you in inadvertently losing some of the work. It is always recommended to use the command files. To use the command files − Type your code in a text editor, like Notepad, Notepad+, or EditPlus, etc. Save the file with the .sql extension in the home directory. Launch the SQL*Plus command prompt from the directory where you created your PL/SQL file. Type @file_name at the SQL*Plus command prompt to execute your program. If you are not using a file to execute the PL/SQL scripts, then simply copy your PL/SQL code and right-click on the black window that displays the SQL prompt; use the paste option to paste the complete code at the command prompt. Finally, just press Enter to execute the code, if it is not already executed. Print Page Previous Next Advertisements ”;
PL/SQL – Operators
PL/SQL – Operators ”; Previous Next In this chapter, we will discuss operators in PL/SQL. An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulation. PL/SQL language is rich in built-in operators and provides the following types of operators − Arithmetic operators Relational operators Comparison operators Logical operators String operators Here, we will understand the arithmetic, relational, comparison and logical operators one by one. The String operators will be discussed in a later chapter − PL/SQL – Strings. Arithmetic Operators Following table shows all the arithmetic operators supported by PL/SQL. Let us assume variable A holds 10 and variable B holds 5, then − Show Examples Operator Description Example + Adds two operands A + B will give 15 – Subtracts second operand from the first A – B will give 5 * Multiplies both operands A * B will give 50 / Divides numerator by de-numerator A / B will give 2 ** Exponentiation operator, raises one operand to the power of other A ** B will give 100000 Relational Operators Relational operators compare two expressions or values and return a Boolean result. Following table shows all the relational operators supported by PL/SQL. Let us assume variable A holds 10 and variable B holds 20, then − Show Examples Operator Description Example = Checks if the values of two operands are equal or not, if yes then condition becomes true. (A = B) is not true. != <> ~= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true Comparison Operators Comparison operators are used for comparing one expression to another. The result is always either TRUE, FALSE or NULL. Show Examples Operator Description Example LIKE The LIKE operator compares a character, string, or CLOB value to a pattern and returns TRUE if the value matches the pattern and FALSE if it does not. If ”Zara Ali” like ”Z% A_i” returns a Boolean true, whereas, ”Nuha Ali” like ”Z% A_i” returns a Boolean false. BETWEEN The BETWEEN operator tests whether a value lies in a specified range. x BETWEEN a AND b means that x >= a and x <= b. If x = 10 then, x between 5 and 20 returns true, x between 5 and 10 returns true, but x between 11 and 20 returns false. IN The IN operator tests set membership. x IN (set) means that x is equal to any member of set. If x = ”m” then, x in (”a”, ”b”, ”c”) returns Boolean false but x in (”m”, ”n”, ”o”) returns Boolean true. IS NULL The IS NULL operator returns the BOOLEAN value TRUE if its operand is NULL or FALSE if it is not NULL. Comparisons involving NULL values always yield NULL. If x = ”m”, then ”x is null” returns Boolean false. Logical Operators Following table shows the Logical operators supported by PL/SQL. All these operators work on Boolean operands and produce Boolean results. Let us assume variable A holds true and variable B holds false, then − Show Examples Operator Description Examples and Called the logical AND operator. If both the operands are true then condition becomes true. (A and B) is false. or Called the logical OR Operator. If any of the two operands is true then condition becomes true. (A or B) is true. not Called the logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true then Logical NOT operator will make it false. not (A and B) is true. PL/SQL Operator Precedence Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator. For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7. Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first. The precedence of operators goes as follows: =, <, >, <=, >=, <>, !=, ~=, ^=, IS NULL, LIKE, BETWEEN, IN. Show Examples Operator Operation ** exponentiation +, – identity, negation *, / multiplication, division +, -, || addition, subtraction, concatenation comparison NOT logical negation AND conjunction OR inclusion Print Page Previous Next Advertisements ”;
PL/SQL – Data Types
PL/SQL – Data Types ”; Previous Next In this chapter, we will discuss the Data Types in PL/SQL. The PL/SQL variables, constants and parameters must have a valid data type, which specifies a storage format, constraints, and a valid range of values. We will focus on the SCALAR and the LOB data types in this chapter. The other two data types will be covered in other chapters. S.No Category & Description 1 Scalar Single values with no internal components, such as a NUMBER, DATE, or BOOLEAN. 2 Large Object (LOB) Pointers to large objects that are stored separately from other data items, such as text, graphic images, video clips, and sound waveforms. 3 Composite Data items that have internal components that can be accessed individually. For example, collections and records. 4 Reference Pointers to other data items. PL/SQL Scalar Data Types and Subtypes PL/SQL Scalar Data Types and Subtypes come under the following categories − S.No Date Type & Description 1 Numeric Numeric values on which arithmetic operations are performed. 2 Character Alphanumeric values that represent single characters or strings of characters. 3 Boolean Logical values on which logical operations are performed. 4 Datetime Dates and times. PL/SQL provides subtypes of data types. For example, the data type NUMBER has a subtype called INTEGER. You can use the subtypes in your PL/SQL program to make the data types compatible with data types in other programs while embedding the PL/SQL code in another program, such as a Java program. PL/SQL Numeric Data Types and Subtypes Following table lists out the PL/SQL pre-defined numeric data types and their sub-types − S.No Data Type & Description 1 PLS_INTEGER Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits 2 BINARY_INTEGER Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits 3 BINARY_FLOAT Single-precision IEEE 754-format floating-point number 4 BINARY_DOUBLE Double-precision IEEE 754-format floating-point number 5 NUMBER(prec, scale) Fixed-point or floating-point number with absolute value in range 1E-130 to (but not including) 1.0E126. A NUMBER variable can also represent 0 6 DEC(prec, scale) ANSI specific fixed-point type with maximum precision of 38 decimal digits 7 DECIMAL(prec, scale) IBM specific fixed-point type with maximum precision of 38 decimal digits 8 NUMERIC(pre, secale) Floating type with maximum precision of 38 decimal digits 9 DOUBLE PRECISION ANSI specific floating-point type with maximum precision of 126 binary digits (approximately 38 decimal digits) 10 FLOAT ANSI and IBM specific floating-point type with maximum precision of 126 binary digits (approximately 38 decimal digits) 11 INT ANSI specific integer type with maximum precision of 38 decimal digits 12 INTEGER ANSI and IBM specific integer type with maximum precision of 38 decimal digits 13 SMALLINT ANSI and IBM specific integer type with maximum precision of 38 decimal digits 14 REAL Floating-point type with maximum precision of 63 binary digits (approximately 18 decimal digits) Following is a valid declaration − DECLARE num1 INTEGER; num2 REAL; num3 DOUBLE PRECISION; BEGIN null; END; / When the above code is compiled and executed, it produces the following result − PL/SQL procedure successfully completed PL/SQL Character Data Types and Subtypes Following is the detail of PL/SQL pre-defined character data types and their sub-types − S.No Data Type & Description 1 CHAR Fixed-length character string with maximum size of 32,767 bytes 2 VARCHAR2 Variable-length character string with maximum size of 32,767 bytes 3 RAW Variable-length binary or byte string with maximum size of 32,767 bytes, not interpreted by PL/SQL 4 NCHAR Fixed-length national character string with maximum size of 32,767 bytes 5 NVARCHAR2 Variable-length national character string with maximum size of 32,767 bytes 6 LONG Variable-length character string with maximum size of 32,760 bytes 7 LONG RAW Variable-length binary or byte string with maximum size of 32,760 bytes, not interpreted by PL/SQL 8 ROWID Physical row identifier, the address of a row in an ordinary table 9 UROWID Universal row identifier (physical, logical, or foreign row identifier) PL/SQL Boolean Data Types The BOOLEAN data type stores logical values that are used in logical operations. The logical values are the Boolean values TRUE and FALSE and the value NULL. However, SQL has no data type equivalent to BOOLEAN. Therefore, Boolean values cannot be used in − SQL statements Built-in SQL functions (such as TO_CHAR) PL/SQL functions invoked from SQL statements PL/SQL Datetime and Interval Types The DATE datatype is used to store fixed-length datetimes, which include the time of day in seconds since midnight. Valid dates range from January 1, 4712 BC to December 31, 9999 AD. The default date format is set by the Oracle initialization parameter NLS_DATE_FORMAT. For example, the default might be ”DD-MON-YY”, which includes a two-digit number for the day of the month, an abbreviation of the month name, and the last two digits of the year. For example, 01-OCT-12. Each DATE includes the century, year, month, day, hour, minute, and second. The following table shows the valid values for each field − Field Name Valid Datetime Values Valid Interval Values YEAR -4712 to 9999 (excluding year 0) Any nonzero integer MONTH 01 to 12 0 to 11 DAY 01 to 31 (limited by the values of MONTH and YEAR, according to the rules of the calendar for the locale) Any nonzero integer HOUR 00 to 23 0 to 23 MINUTE 00 to 59 0 to 59 SECOND 00 to 59.9(n), where 9(n) is the precision of time fractional seconds 0 to 59.9(n), where 9(n) is the precision of interval fractional seconds TIMEZONE_HOUR -12 to 14 (range accommodates daylight savings time changes) Not applicable TIMEZONE_MINUTE 00 to 59 Not applicable TIMEZONE_REGION Found in the dynamic performance view V$TIMEZONE_NAMES Not applicable TIMEZONE_ABBR Found in the dynamic performance view V$TIMEZONE_NAMES Not applicable PL/SQL Large Object (LOB) Data Types Large Object (LOB) data types refer to large data items such as text, graphic images, video clips, and sound waveforms. LOB data types allow efficient, random, piecewise access to this data. Following are the predefined PL/SQL LOB data types − Data Type Description