{"id":22056,"date":"2013-05-13T10:27:16","date_gmt":"2013-05-13T04:57:16","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=22056"},"modified":"2024-04-12T14:16:42","modified_gmt":"2024-04-12T08:46:42","slug":"lexical-elements-and-basic-data-types","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/","title":{"rendered":"Lexical elements and basic data types"},"content":{"rendered":"<h1>Lexical elements and basic data types<\/h1>\n<p><a class=\"vsc\" href=\"http:\/\/www.vskills.in\/certification\/Certified-PL-SQL-Developer\"><span class=\"vsc-cn\" style=\"text-align: center;\"><span style=\"color: red;\">Certify and Increase Opportunity.<\/span><br \/>\n<span style=\"color: green;\">Be <\/span><br \/>\nGovt. Certified PL SQL Developer<br \/>\n<\/span><\/a><\/p>\n<p><strong><span style=\"text-decoration: underline;\">PL\/SQL LEXICAL ELEMENTS<\/span><br \/>\n<\/strong><\/p>\n<p>A lexical element refers to a character or groupings of characters that may legally appear in a source file. Basic lexical elements are<\/p>\n<ul>\n<li>Tokens<\/li>\n<li>Source program character set<\/li>\n<li>Comments<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><strong>PL\/SQL DATATYPES<\/strong><\/span><\/p>\n<p>Every constant, variable, and parameter has a datatype (or type), which specifies a storage format, constraints, and valid range of values. PL\/SQL provides a variety of predefined datatypes. For instance, you can choose from integer, floating point, character, Boolean, date, collection, reference, and LOB types. In addition, PL\/SQL lets you define your own subtypes. This chapter covers the basic types used frequently in PL\/SQL programs. Later chapters cover the more specialized types.<\/p>\n<p>The datatypes are:<\/p>\n<ul>\n<li>Predefined Datatypes<\/li>\n<li>User-Defined Subtypes<\/li>\n<li>Datatype Conversion<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Predefined Datatypes<\/span><\/p>\n<p>A scalar type has no internal components. A composite type has internal components that can be manipulated individually. A reference type holds values, called pointers, that designate other program items. A LOB type holds values, called lob locators, that specify the location of large objects (graphic images for example) stored out-of-line.<\/p>\n<p>A lexical element refers to or groupings of characters that may legally appear in file. Basic lexical elements are<\/p>\n<ul>\n<li>Tokens<\/li>\n<li>Source program character set<\/li>\n<li>Comments<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><strong>PL\/SQL DATATYPES<\/strong><\/span><\/p>\n<p>Every constant, variable, and parameter has (or type), which specifies format, constraints, and valid range of values. PL\/SQL provides of predefined datatypes. For instance, you can choose from integer, floating point, character, Boolean, date, collection, reference, and LOB types. In addition, PL\/SQL lets you define your own subtypes. This chapter covers the basic types used frequently in PL\/SQL programs. Later chapters cover the more specialized types.<\/p>\n<p>The datatypes are:<\/p>\n<ul>\n<li>Predefined Datatypes<\/li>\n<li>User-Defined Subtypes<\/li>\n<li>Datatype Conversion<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Predefined Datatypes<\/span><\/p>\n<p>A scalar type has no internal components. A composite type has internal components that can be manipulated individually. A reference type holds values, called pointers, that designate other program items. A LOB type holds values, called lob locators, that specify the location of large objects (graphic images for example) stored out-of-line.<\/p>\n<p>&nbsp;<\/p>\n<p>A lexical element refers to or groupings of characters that may legally appear in file. Basic lexical elements are<\/p>\n<ul>\n<li>Tokens<\/li>\n<li>Source program character set<\/li>\n<li>Comments<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><strong>PL\/SQL DATATYPES<\/strong><\/span><\/p>\n<p>Every constant, variable, and parameter has (or type), which specifies format, constraints, and valid range of values. PL\/SQL provides of predefined datatypes. For instance, you can choose from integer, floating point, character, Boolean, date, collection, reference, and LOB types. In addition, PL\/SQL lets you define your own subtypes. This chapter covers the basic types used frequently in PL\/SQL programs. Later chapters cover the more specialized types.<\/p>\n<p>The datatypes are:<\/p>\n<ul>\n<li>Predefined Datatypes<\/li>\n<li>User-Defined Subtypes<\/li>\n<li>Datatype Conversion<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\">Predefined Datatypes<\/span><\/p>\n<p>A scalar type has no internal components. A composite type has internal components that can be manipulated individually. A reference type holds values, called pointers, that designate other program items. A LOB type holds values, called lob locators, that specify the location of large objects (graphic images for example) stored out-of-line.<\/p>\n<p>&nbsp;<\/p>\n<h3>Number Types<\/h3>\n<p>Number types let you store numeric data (integers, real numbers, and floating-point numbers), represent quantities, and do calculations.<\/p>\n<h4>BINARY_INTEGER<\/h4>\n<p>You use the <code>BINARY_INTEGER<\/code> datatype to store signed integers. Its magnitude range is -2**31 .. 2**31. Like <code>PLS_INTEGER<\/code> values, <code>BINARY_INTEGER<\/code> values require less storage than <code>NUMBER<\/code> values. However, most <code>BINARY_INTEGER<\/code> operations are slower than <code>PLS_INTEGER<\/code> operations.<\/p>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">BINARY_INTEGER Subtypes<\/span><\/h5>\n<p>A <em>base type<\/em> is the datatype from which is derived. A <em>subtype<\/em> associates type with and so defines of values. For your convenience, PL\/SQL predefines the following <code>BINARY_INTEGER<\/code> subtypes:<\/p>\n<dl>\n<dd><code>NATURAL<\/code><\/dd>\n<dd><code>NATURALN<\/code><\/dd>\n<dd><code>POSITIVE<\/code><\/dd>\n<dd><code>POSITIVEN<\/code><\/dd>\n<dd><code>SIGNTYPE<\/code><\/p>\n<pre><\/pre>\n<p>&nbsp;<\/dd>\n<\/dl>\n<p>The subtypes <code>NATURAL<\/code> and <code>POSITIVE<\/code> let you restrict an integer variable to non-negative or positive values, respectively. <code>NATURALN<\/code> and <code>POSITIVEN<\/code> prevent the assigning of nulls to an integer variable. <code>SIGNTYPE<\/code> lets you restrict an integer variable to the values -1, 0, and 1, which is useful in programming tri-state logic.<\/p>\n<h4>NUMBER<\/h4>\n<p>You use the <code>NUMBER<\/code> datatype to store fixed-point or floating-point numbers. Its magnitude range is 1E-130 .. 10E125. If the value of an expression falls outside this range, you get &gt;numeric overflow or underflow error. You can specify <em>precision<\/em>, which is the total number of digits, and <em>scale<\/em>, which is the number of digits to the right of the decimal point. The syntax follows:<\/p>\n<pre>NUMBER[(precision,scale)]<\/pre>\n<p>To declare fixed-point numbers, for which you must specify <em>scale<\/em>, use the following form:<\/p>\n<pre>NUMBER(precision,scale)<\/pre>\n<p>To declare floating-point numbers, for which you cannot specify <em>precision<\/em> or <em>scale<\/em> because the decimal point can &#8220;float&#8221; to any position, use the following form:<\/p>\n<pre>NUMBER<\/pre>\n<p>To declare integers, which have no decimal point, use this form:<\/p>\n<pre>NUMBER(<em><code>precision<\/code><\/em>)  -- same as NUMBER(<em><code>precision<\/code><\/em>,0)<\/pre>\n<p>You cannot use constants or variables to specify <em>precision<\/em> and <em>scale<\/em>; you must use integer literals. The maximum precision of &gt;NUMBER value is 38 decimal digits. If you do not specify <em>precision<\/em>, it defaults to 38 or the maximum supported by your system, whichever is less.<\/p>\n<p>Scale, which can range from -84 to 127, determines where rounding occurs. For instance, of 2 rounds to the nearest hundredth (3.456 becomes 3.46). A negative scale rounds to the left of the decimal point. For example, of -3 rounds to the nearest thousand (3456 becomes 3000). A scale of 0 rounds to the nearest whole number. If you do not specify <em>scale<\/em>, it defaults to 0.<\/p>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">NUMBER Subtypes<\/span><\/h5>\n<p>You can use the following <code>NUMBER<\/code> subtypes for compatibility with ANSI\/ISO and IBM types or when you want descriptive name:<\/p>\n<dl>\n<dd><code>DEC<\/code><\/dd>\n<dd><code>DECIMAL<\/code><\/dd>\n<dd><code>DOUBLE<\/code> <code>PRECISION<\/code><\/dd>\n<dd><code>FLOAT<\/code><\/dd>\n<dd><code>INTEGER<\/code><\/dd>\n<dd><code>INT<\/code><\/dd>\n<dd><code>NUMERIC<\/code><\/dd>\n<dd><code>REAL<\/code><\/dd>\n<dd><code>SMALLINT<\/code><\/p>\n<pre><\/pre>\n<p>&nbsp;<\/dd>\n<\/dl>\n<p>Use the subtypes <code>DEC<\/code>, <code>DECIMAL<\/code>, and <code>NUMERIC<\/code> to declare fixed-point numbers with precision of 38 decimal digits. Use the subtypes <code>DOUBLE<\/code> <code>PRECISION<\/code> and <code>FLOAT<\/code> to declare floating-point numbers with precision of 126 binary digits, which is roughly equivalent to 38 decimal digits. Or, use the subtype REAL to declare floating-point numbers with precision of 63 binary digits, which is roughly equivalent to 18 decimal digits. Use the subtypes <code>INTEGER<\/code>, <code>INT<\/code>, and <code>SMALLINT<\/code> to declare integers with precision of 38 decimal digits.<\/p>\n<h4>PLS_INTEGER<\/h4>\n<p>You use the <code>PLS_INTEGER<\/code> datatype to store signed integers. Its magnitude range is -2**31 .. 2**31. <code>PLS_INTEGER<\/code> values require less storage than <code>NUMBER<\/code> values. Also, <code>PLS_INTEGER<\/code> operations use machine arithmetic, so they are faster than <code>NUMBER<\/code> and <code>BINARY_INTEGER<\/code> operations, which use library arithmetic. For efficiency, use <code>PLS_INTEGER<\/code> for all calculations that fall within its magnitude range. Although <code>PLS_INTEGER<\/code> and <code>BINARY_INTEGER<\/code> have the same magnitude range, they are not fully compatible. When &gt;PLS_INTEGER calculation overflows, an exception is raised. However, when &gt;BINARY_INTEGER calculation overflows, no exception is raised if the result is assigned to &gt;NUMBER variable. Because of this small semantic difference, you might want to continue using <code>BINARY_INTEGER<\/code> in old applications for compatibility. In new applications, always use <code>PLS_INTEGER<\/code> for better performance.<\/p>\n<h3>Character Types<\/h3>\n<p>Character types let you store alphanumeric data, represent words and text, and manipulate character strings.<\/p>\n<h4>CHAR<\/h4>\n<p>You use the <code>CHAR<\/code> datatype to store fixed-length character data. How the data is represented internally depends on the database character set. The <code>CHAR<\/code> datatype takes an optional parameter that lets you specify size up to 32767 bytes. You can specify the size in terms of bytes or characters, where each character contains one or more bytes, depending on the character set encoding. The syntax follows:<\/p>\n<pre>CHAR[(maximum_size [CHAR | BYTE] )]<\/pre>\n<p>You cannot use constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.<\/p>\n<p>If you do not specify size, it defaults to 1. If you specify the maximum size in bytes rather than characters, &gt;CHAR(n) variable might be too small to hold <code>n<\/code> multibyte characters. To avoid this possibility, use the notation <code>CHAR(n CHAR)<\/code>so that the variable can hold <code>n<\/code> characters in the database character set, even if some of those characters contain multiple bytes. When you specify the length in characters, the upper limit is still 32767 bytes. So for double-byte and multibyte character sets, you can only specify 1\/2 or 1\/3 as many characters as with -byte character set.<\/p>\n<p>Although PL\/SQL character variables can be relatively long, the maximum width of &gt;CHAR database column is 2000 bytes. So, you cannot insert <code>CHAR<\/code> values longer than 2000 bytes into &gt;CHAR database column.<\/p>\n<p>You can insert any <code>CHAR(n)<\/code> value into &gt;LONG database column because the maximum width of &gt;LONG column is 2**31 bytes or two gigabytes. However, you cannot retrieve longer than 32767 bytes from &gt;LONG column into &gt;CHAR(n) variable.<\/p>\n<p>When you do not use the <code>CHAR<\/code> or <code>BYTE<\/code> qualifiers, the default is determined by the setting of the <code>NLS_LENGTH_SEMANTICS<\/code> initialization parameter. When \/SQL procedure is compiled, the setting of this parameter is recorded, so that the same setting is used when the procedure is recompiled after being invalidated.<\/p>\n<p><strong>Note:<\/strong> Semantic differences between the <code>CHAR<\/code> and <code>VARCHAR2<\/code> base types are discussed in Appendix B.<\/p>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">CHAR Subtype<\/span><\/h5>\n<p>The <code>CHAR<\/code> subtype <code>CHARACTER<\/code> has the same range of values as its base type. That is, <code>CHARACTER<\/code> is just another name for <code>CHAR<\/code>. You can use this subtype for compatibility with ANSI\/ISO and IBM types or when you want an identifier more descriptive than <code>CHAR<\/code>.<\/p>\n<h4>LONG and LONG RAW<\/h4>\n<p>You use the <code>LONG<\/code> datatype to store variable-length character strings. The <code>LONG<\/code> datatype is like the <code>VARCHAR2<\/code> datatype, except that the maximum size of &gt;LONG value is 32760 bytes.<\/p>\n<p>You use the <code>LONG<\/code> <code>RAW<\/code> datatype to store binary data or byte strings. <code>LONG<\/code> <code>RAW<\/code> data is like <code>LONG<\/code> data, except that <code>LONG<\/code> <code>RAW<\/code> data is not interpreted by PL\/SQL. The maximum size of &gt;LONG <code>RAW<\/code> value is 32760 bytes.<\/p>\n<p>Starting in Oracle9<em>i<\/em>, LOB variables can be used interchangeably with <code>LONG<\/code> and <code>LONG RAW<\/code> variables. Oracle recommends migrating any <code>LONG<\/code> data to the <code>CLOB<\/code> type, and any <code>LONG RAW<\/code> data to the <code>BLOB<\/code> type.<\/p>\n<p>You can insert any <code>LONG<\/code> value into &gt;LONG database column because the maximum width of &gt;LONG column is 2**31 bytes. However, you cannot retrieve longer than 32760 bytes from &gt;LONG column into &gt;LONG variable.<\/p>\n<p>Likewise, you can insert any <code>LONG<\/code> <code>RAW<\/code> value into &gt;LONG <code>RAW<\/code> database column because the maximum width of &gt;LONG <code>RAW<\/code> column is 2**31 bytes. However, you cannot retrieve longer than 32760 bytes from &gt;LONG <code>RAW<\/code> column into &gt;LONG <code>RAW<\/code> variable.<\/p>\n<p><code>LONG<\/code> columns can store text, arrays of characters, or even short documents. You can reference <code>LONG<\/code> columns in <code>UPDATE<\/code>, <code>INSERT<\/code>, and (most) <code>SELECT<\/code> statements, but <em>not<\/em> in expressions, SQL function calls, or certain SQL clauses such as <code>WHERE<\/code>, <code>GROUP<\/code> <code>BY<\/code>, and <code>CONNECT<\/code> <code>BY<\/code>.<\/p>\n<p><strong>Note:<\/strong> In SQL statements, PL\/SQL binds <code>LONG<\/code> values as <code>VARCHAR2<\/code>, not as <code>LONG<\/code>. However, if the length of the bound <code>VARCHAR2<\/code> exceeds the maximum width of &gt;VARCHAR2 column (4000 bytes), Oracle converts the bind type to <code>LONG<\/code> automatically, then issues an error message because you cannot pass <code>LONG<\/code> values to function.<\/p>\n<h4>RAW<\/h4>\n<p>You use the <code>RAW<\/code> datatype to store binary data or byte strings. For example, &gt;RAW variable might store of graphics characters or picture. Raw data is like <code>VARCHAR2<\/code> data, except that PL\/SQL does not interpret raw data. Likewise, Oracle Net does no character set conversions when you transmit raw data from one system to another.<\/p>\n<p>The <code>RAW<\/code> datatype takes parameter that lets you specify size up to 32767 bytes. The syntax follows:<\/p>\n<pre>RAW(maximum_size)<\/pre>\n<p>You cannot use constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.<\/p>\n<p>The maximum width of &gt;RAW database column is 2000 bytes. So, you cannot insert <code>RAW<\/code> values longer than 2000 bytes into &gt;RAW column. You can insert any <code>RAW<\/code> value into &gt;LONG <code>RAW<\/code> database column because the maximum width of &gt;LONG <code>RAW<\/code> column is 2**31 bytes. However, you cannot retrieve longer than 32767 bytes from &gt;LONG <code>RAW<\/code> column into &gt;RAW variable.<\/p>\n<h4>ROWID and UROWID<\/h4>\n<p>Internally, every database table has &gt;ROWID pseudocolumn, which stores binary values called <strong>rowids<\/strong>. Each rowid represents the storage address of . A <strong>physical rowid<\/strong> identifies in an ordinary table. A <strong>logical rowid<\/strong> identifies in an index-organized table. The <code>ROWID<\/code> datatype can store only physical rowids. However, the <code>UROWID<\/code> (universal rowid) datatype can store physical, logical, or foreign (non-Oracle) rowids.<\/p>\n<p><strong>Suggestion:<\/strong> Use the <code>ROWID<\/code> datatype only for backward compatibility with old applications. For new applications, use the <code>UROWID<\/code> datatype.<\/p>\n<p>When you select or fetch into &gt;ROWID variable, you can use the built-in function <code>ROWIDTOCHAR<\/code>, which converts the binary value into an 18-byte character string. Conversely, the function <code>CHARTOROWID<\/code> converts &gt;ROWID character string into . If the conversion fails because the character string does not represent rowid, PL\/SQL raises the predefined exception <code>SYS_INVALID_ROWID<\/code>. This also applies to implicit conversions.<\/p>\n<p>To convert between <code>UROWID<\/code> variables and character strings, use regular assignment statements without any function call. The values are implicitly converted between <code>UROWID<\/code> and character types.<\/p>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">Physical Rowids<\/span><\/h5>\n<p>Physical rowids provide fast access to particular rows. As long as the row exists, its physical rowid does not change. Efficient and stable, physical rowids are useful for selecting of rows, operating on the whole set, and then updating . For example, you can compare &gt;UROWID variable with the <code>ROWID<\/code> pseudocolumn in the <code>WHERE<\/code> clause of an <code>UPDATE<\/code> or <code>DELETE<\/code> statement to identify the latest row fetched from .<\/p>\n<p>A physical rowid can have either of two formats. The 10-byte <em>extended rowid<\/em> format supports tablespace-relative block addresses and can identify rows in partitioned and non-partitioned tables. The 6-byte <em>restricted rowid<\/em> format is provided for backward compatibility.<\/p>\n<p>Extended rowids use -64 encoding of the physical address for each row selected. For example, in SQL*Plus (which implicitly converts rowids into character strings), the query<\/p>\n<pre>SQL&gt; SELECT rowid, ename FROM emp WHERE empno = 7788;<\/pre>\n<p>might return the following row:<\/p>\n<pre>ROWID              ENAME\r\n------------------ ----------\r\nAAAAqcAABAAADFNAAH SCOTT<\/pre>\n<p>The format, <code>OOOOOOFFFBBBBBBRRR<\/code>, has four parts:<\/p>\n<ul>\n<li type=\"disc\"><code>OOOOOO<\/code>: The data object number (<code>AAAAqc<\/code> in the example above) identifies the database segment. Schema objects in the same segment, such as of tables, have the same data object number.<\/li>\n<li type=\"disc\"><code>FFF<\/code>: The file number (<code>AAB<\/code> in the example) identifies the data file that contains the row. File numbers are unique within .<\/li>\n<li type=\"disc\"><code>BBBBBB<\/code>: The block number (<code>AAADFN<\/code> in the example) identifies the data block that contains the row. Block numbers are relative to their data file, not their tablespace. So, two rows in the same tablespace but in different data files can have the same block number.<\/li>\n<li type=\"disc\"><code>RRR<\/code>: The row number (<code>AAH<\/code> in the example) identifies the row in the block.<\/li>\n<\/ul>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">Logical Rowids<\/span><\/h5>\n<p>Logical rowids provide the fastest access to particular rows. Oracle uses them to construct secondary indexes on index-organized tables. Having no permanent physical address, rowid can move across data blocks when new rows are inserted. However, if the physical location of changes, its logical rowid remains valid.<\/p>\n<p>A logical rowid can include &gt;guess, which identifies the block location of at the time the guess is made. Instead of doing key search, Oracle uses the guess to search the block directly. However, as new rows are inserted, guesses can become stale and slow down access to rows. To obtain fresh guesses, you can rebuild the secondary index.<\/p>\n<p>You can use the <code>ROWID<\/code> pseudocolumn to select logical rowids (which are opaque values) from an index-organized table. Also, you can insert logical rowids into of type <code>UROWID<\/code>, which has size of 4000 bytes.<\/p>\n<p>The <code>ANALYZE<\/code> statement helps you track the staleness of guesses. This is useful for applications that store rowids with guesses in &gt;UROWID column, then use the rowids to fetch rows.<\/p>\n<p><strong>Note:<\/strong> To manipulate rowids, you can use the supplied package <code>DBMS_ROWID<\/code>. For more information.<\/p>\n<h4>VARCHAR2<\/h4>\n<p>You use the <code>VARCHAR2<\/code> datatype to store variable-length character data. How the data is represented internally depends on the database character set. The <code>VARCHAR2<\/code> datatype takes parameter that specifies size up to 32767 bytes. The syntax follows:<\/p>\n<pre>VARCHAR2(maximum_size [CHAR | BYTE])<\/pre>\n<p>You cannot use constant or variable to specify the maximum size; you must use an integer literal in the range 1 .. 32767.<\/p>\n<p>Small <code>VARCHAR2<\/code> variables are optimized for performance, and larger ones are optimized for efficient memory use. The cutoff point is 2000 bytes. For &gt;VARCHAR2 that is <code>2000<\/code> bytes or longer, PL\/SQL dynamically allocates only enough memory to hold the actual value. For &gt;VARCHAR2 variable that is shorter than 2000 bytes, PL\/SQL preallocates the full declared length of the variable. For example, if you assign the same 500-byte value to &gt;VARCHAR2(2000 BYTE) variable and to &gt;VARCHAR2(1999 BYTE) variable, the former takes up 500 bytes and the latter takes up 1999 bytes.<\/p>\n<p>If you specify the maximum size in bytes rather than characters, &gt;VARCHAR2(n) variable might be too small to hold <code>n<\/code> multibyte characters. To avoid this possibility, use the notation <code>VARCHAR2(n CHAR)<\/code>so that the variable can hold <code>n<\/code> characters in the database character set, even if some of those characters contain multiple bytes. When you specify the length in characters, the upper limit is still 32767 bytes. So for double-byte and multibyte character sets, you can only specify 1\/2 or 1\/3 as many characters as with -byte character set.<\/p>\n<p>Although PL\/SQL character variables can be relatively long, the maximum width of &gt;VARCHAR2 database column is 4000 bytes. So, you cannot insert <code>VARCHAR2<\/code> values longer than 4000 bytes into &gt;VARCHAR2 database column.<\/p>\n<p>You can insert any <code>VARCHAR2(n)<\/code> value into &gt;LONG database column because the maximum width of &gt;LONG column is 2**31 bytes. However, you cannot retrieve longer than 32767 bytes from &gt;LONG column into &gt;VARCHAR2(n) variable.<\/p>\n<p>When you do not use the <code>CHAR<\/code> or <code>BYTE<\/code> qualifiers, the default is determined by the setting of the <code>NLS_LENGTH_SEMANTICS<\/code> initialization parameter. When \/SQL procedure is compiled, the setting of this parameter is recorded, so that the same setting is used when the procedure is recompiled after being invalidated.<\/p>\n<h5><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">VARCHAR2 Subtypes<\/span><\/h5>\n<p>The <code>VARCHAR2<\/code> subtypes below have the same range of values as their base type. For example, <code>VARCHAR<\/code> is just another name for <code>VARCHAR2<\/code>.<\/p>\n<dl>\n<dd><code>STRING<\/code><\/dd>\n<dd><code>VARCHAR<\/code><\/dd>\n<\/dl>\n<p>You can use these subtypes for compatibility with ANSI\/ISO and IBM types.<\/p>\n<p><strong>Note:<\/strong> Currently, <code>VARCHAR<\/code> is synonymous with <code>VARCHAR2<\/code>. However, in future releases of PL\/SQL, to accommodate emerging SQL standards, <code>VARCHAR<\/code> might become datatype with different comparison semantics. So, it is idea to use <code>VARCHAR2<\/code> rather than <code>VARCHAR<\/code>.<\/p>\n<h3>National Character Types<\/h3>\n<p>The widely used one-byte ASCII and EBCDIC character sets are adequate to represent the Roman alphabet, but some Asian languages, such as Japanese, contain thousands of characters. These languages require two or three bytes to represent each character. To deal with such languages, Oracle provides globalization support, which lets you process single-byte and multibyte character data and convert between character sets. It also lets your applications run in different language environments.<\/p>\n<p>With globalization support, number and date formats adapt automatically to the language conventions specified for session. Thus, users around the world can interact with Oracle in their native languages.<\/p>\n<p>PL\/SQL supports two character sets called the <em>database character set<\/em>, which is used for identifiers and source code, and the <em>national character set<\/em>, which is used for national language data. The datatypes <code>NCHAR<\/code> and <code>NVARCHAR2<\/code> store character strings formed from the national character set.<\/p>\n<p><strong>Note:<\/strong> When converting <code>CHAR<\/code> or <code>VARCHAR2<\/code> data between databases with different character sets, make sure the data consists of well-formed strings. For more information<\/p>\n<h4>Comparing UTF8 and AL16UTF16 Encodings<\/h4>\n<p>The national character set represents data as Unicode, using either the <code>UTF8<\/code> or <code>AL16UTF16<\/code> encoding.<\/p>\n<p>Each character in the <code>AL16UTF16<\/code> encoding takes up 2 bytes. This makes it simple to calculate string lengths to avoid truncation errors when mixing different programming languages, but requires extra storage overhead to store strings made up mostly of ASCII characters.<\/p>\n<p>Each character in the <code>UTF8<\/code> encoding takes up 1, 2, or 3 bytes. This lets you fit more characters into or table column, but only if most characters can be represented in byte. It introduces the possibility of truncation errors when transferring the data to measured in bytes.<\/p>\n<p>Oracle Corporation recommends that you use the default <code>AL16UTF16<\/code> encoding wherever practical, for maximum runtime reliability. If you need to determine how many bytes are required to hold string, use the <code>LENGTHB<\/code> function rather than <code>LENGTH<\/code>.<\/p>\n<h4>NCHAR<\/h4>\n<p>You use the <code>NCHAR<\/code> datatype to store fixed-length (blank-padded if necessary) national character data. How the data is represented internally depends on the national character set specified when the database was created, which might use -width encoding (<code>UTF8<\/code>) or -width encoding (<code>AL16UTF16<\/code>). Because this type can always accommodate multibyte characters, you can use it to hold any Unicode character data.<\/p>\n<p>The <code>NCHAR<\/code> datatype takes an optional parameter that lets you specify size in characters. The syntax follows:<\/p>\n<pre>NCHAR[(maximum_size)]<\/pre>\n<p>Because the physical limit is 32767 bytes, the maximum value you can specify for the length is 32767\/2 in the <code>AL16UTF16<\/code> encoding, and 32767\/3 in the <code>UTF8<\/code> encoding.<\/p>\n<p>You cannot use constant or variable to specify the maximum size; you must use an integer literal.<\/p>\n<p>If you do not specify size, it defaults to 1. The value always represents the number of characters, unlike <code>CHAR<\/code> which can be specified in either characters or bytes.<\/p>\n<pre>my_string NCHAR(100);  -- maximum size is 100 characters<\/pre>\n<p>The maximum width of an <code>NCHAR<\/code> database column is 2000 bytes. So, you cannot insert <code>NCHAR<\/code> values longer than 2000 bytes into an <code>NCHAR<\/code> column.<\/p>\n<p>If the <code>NCHAR<\/code> value is shorter than the defined width of the <code>NCHAR<\/code> column, Oracle blank-pads the value to the defined width.<\/p>\n<p>You can interchange <code>CHAR<\/code> and <code>NCHAR<\/code> values in statements and expressions. It is always safe to turn &gt;CHAR value into an <code>NCHAR<\/code> value, but turning an <code>NCHAR<\/code> value into &gt;CHAR value might cause data loss if the character set for the <code>CHAR<\/code> value cannot represent all the characters in the <code>NCHAR<\/code> value. Such data loss can result in characters that usually look like question marks (?).<\/p>\n<h4>NVARCHAR2<\/h4>\n<p>You use the <code>NVARCHAR2<\/code> datatype to store variable-length Unicode character data. How the data is represented internally depends on the national character set specified when the database was created, which might use -width encoding (<code>UTF8<\/code>) or -width encoding (<code>AL16UTF16<\/code>). Because this type can always accommodate multibyte characters, you can use it to hold any Unicode character data.<\/p>\n<p>The <code>NVARCHAR2<\/code> datatype takes parameter that specifies size in characters. The syntax follows:<\/p>\n<pre>NVARCHAR2(maximum_size)<\/pre>\n<p>Because the physical limit is 32767 bytes, the maximum value you can specify for the length is 32767\/2 in the <code>AL16UTF16<\/code> encoding, and 32767\/3 in the <code>UTF8<\/code> encoding.<\/p>\n<p>You cannot use constant or variable to specify the maximum size; you must use an integer literal.<\/p>\n<p>The maximum size always represents the number of characters, unlike <code>VARCHAR2<\/code> which can be specified in either characters or bytes.<\/p>\n<pre>my_string NVARCHAR2(200);  -- maximum size is 200 characters<\/pre>\n<p>The maximum width of &gt;NVARCHAR2 database column is 4000 bytes. Therefore, you cannot insert <code>NVARCHAR2<\/code> values longer than 4000 bytes into &gt;NVARCHAR2 column.<\/p>\n<p>You can interchange <code>VARCHAR2<\/code> and <code>NVARCHAR2<\/code> values in statements and expressions. It is always safe to turn &gt;VARCHAR2 value into an <code>NVARCHAR2<\/code> value, but turning an <code>NVARCHAR2<\/code> value into &gt;VARCHAR2 value might cause data loss if the character set for the <code>VARCHAR2<\/code> value cannot represent all the characters in the <code>NVARCHAR2<\/code> value. Such data loss can result in characters that usually look like question marks (?).<\/p>\n<h3>LOB Types<\/h3>\n<p>The <code>LOB<\/code> (large object) datatypes <code>BFILE<\/code>, <code>BLOB<\/code>, <code>CLOB<\/code>, and <code>NCLOB<\/code> let you store blocks of unstructured data (such as text, graphic images, video clips, and sound waveforms) up to four gigabytes in size. And, they allow efficient, random, piece-wise access to the data.<\/p>\n<p>The <code>LOB<\/code> types differ from the <code>LONG<\/code> and <code>LONG<\/code> <code>RAW<\/code> types in several ways. For example, <code>LOB<\/code>s (except <code>NCLOB<\/code>) can be attributes of an object type, but <code>LONG<\/code>s cannot. The maximum size of &gt;LOB is four gigabytes, but the maximum size of &gt;LONG is two gigabytes. Also, <code>LOB<\/code>s support random access to data, but <code>LONG<\/code>s support only sequential access.<\/p>\n<p><code>LOB<\/code> types store <em>lob locators<\/em>, which point to large objects stored in an external file, <em>in-line<\/em> (inside the row) or <em>out-of-line<\/em> (outside the row). Database columns of type <code>BLOB<\/code>, <code>CLOB<\/code>, <code>NCLOB<\/code>, or <code>BFILE<\/code> store the locators. <code>BLOB<\/code>, <code>CLOB<\/code>, and <code>NCLOB<\/code> data is stored in the database, in or outside the row. <code>BFILE<\/code> data is stored in operating system files outside the database.<\/p>\n<p>PL\/SQL operates on <code>LOB<\/code>s through the locators. For example, when you select &gt;BLOB column value, only is returned. If you got it during , the <code>LOB<\/code> locator includes ID, so you cannot use it to update that <code>LOB<\/code> in another transaction. Likewise, you cannot save &gt;LOB locator during one session, then use it in another session.<\/p>\n<p>Starting in Oracle9<em>i<\/em>, you can also convert <code>CLOB<\/code>s to <code>CHAR<\/code> and <code>VARCHAR2<\/code> types and vice versa, or <code>BLOB<\/code>s to <code>RAW<\/code> and vice versa, which lets you use <code>LOB<\/code> types in most SQL and PL\/SQL statements and functions. To read, write, and do piecewise operations on <code>LOB<\/code>s, you can use the supplied package <code>DBMS_LOB<\/code>.<\/p>\n<h4>BFILE<\/h4>\n<p>You use the <code>BFILE<\/code> datatype to store large binary objects in operating system files outside the database. Every <code>BFILE<\/code> variable stores locator, which points to binary file on the server. The locator includes alias, which specifies path name (logical path names are not supported).<\/p>\n<p><code>BFILE<\/code>s are read-only, so you cannot modify them. The size of &gt;BFILE is system dependent but cannot exceed four gigabytes (2**32 &#8211; 1 bytes). Your DBA makes sure that <code>BFILE<\/code> exists and that Oracle has read permissions on it. The underlying operating system maintains file integrity.<\/p>\n<p><code>BFILE<\/code>s do not participate in transactions, are not recoverable, and cannot be replicated. The maximum number of open <code>BFILE<\/code>s is set by the Oracle initialization parameter <code>SESSION_MAX_OPEN_FILES<\/code>, which is system dependent.<\/p>\n<h4>BLOB<\/h4>\n<p>You use the <code>BLOB<\/code> datatype to store large binary objects in the database, in-line or out-of-line. Every <code>BLOB<\/code> variable stores , which points to binary object. The size of &gt;BLOB cannot exceed four gigabytes.<\/p>\n<p><code>BLOB<\/code>s participate fully in transactions, are recoverable, and can be replicated. Changes made by package <code>DBMS_LOB<\/code> can be committed or rolled back. <code>BLOB<\/code> locators can span transactions (for reads only), but they cannot span sessions.<\/p>\n<h4>CLOB<\/h4>\n<p>You use the <code>CLOB<\/code> datatype to store large blocks of character data in the database, in-line or out-of-line. Both fixed-width and variable-width character sets are supported. Every <code>CLOB<\/code> variable stores , which points to block of character data. The size of &gt;CLOB cannot exceed four gigabytes.<\/p>\n<p><code>CLOB<\/code>s participate fully in transactions, are recoverable, and can be replicated. Changes made by package <code>DBMS_LOB<\/code> can be committed or rolled back. <code>CLOB<\/code> locators can span transactions (for reads only), but they cannot span sessions.<\/p>\n<h4>NCLOB<\/h4>\n<p>You use the <code>NCLOB<\/code> datatype to store large blocks of <code>NCHAR<\/code> data in the database, in-line or out-of-line. Both fixed-width and variable-width character sets are supported. Every <code>NCLOB<\/code> variable stores , which points to block of <code>NCHAR<\/code> data. The size of an <code>NCLOB<\/code> cannot exceed four gigabytes.<\/p>\n<p><code>NCLOB<\/code>s participate fully in transactions, are recoverable, and can be replicated. Changes made by package <code>DBMS_LOB<\/code> can be committed or rolled back. <code>NCLOB<\/code> locators can span transactions (for reads only), but they cannot span sessions.<\/p>\n<h3>Boolean Type<\/h3>\n<h4>BOOLEAN<\/h4>\n<p>You use the <code>BOOLEAN<\/code> datatype to store the logical values <code>TRUE<\/code>, <code>FALSE<\/code>, and <code>NULL<\/code> (which stands for , unknown, or inapplicable value). Only logic operations are allowed on <code>BOOLEAN<\/code> variables.<\/p>\n<p>The <code>BOOLEAN<\/code> datatype takes no parameters. Only the values <code>TRUE<\/code>, <code>FALSE<\/code>, and <code>NULL<\/code> can be assigned to &gt;BOOLEAN variable. You cannot insert the values <code>TRUE<\/code> and <code>FALSE<\/code> into column. Also, you cannot select or fetch column values into &gt;BOOLEAN variable.<\/p>\n<h3>Datetime and Interval Types<\/h3>\n<p>The datatypes in this section let you store and manipulate dates, times, and intervals (periods of time). A variable that has \/time datatype holds values called <em>datetimes<\/em>; that has an interval datatype holds values called <em>intervals<\/em>. A datetime or interval consists of fields, which determine its value. The following list shows the valid values for each field:<\/p>\n<table dir=\"ltr\" title=\"\" border=\"1\" summary=\"\" width=\"100%\" frame=\"HSIDES\" rules=\"GROUPS\" cellspacing=\"0\" cellpadding=\"3\">\n<thead>\n<tr>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Field Name<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Valid Datetime Values<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Valid Interval Values<\/strong><\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr align=\"left\" valign=\"top\">\n<td><code>YEAR<\/code><\/td>\n<td>-4712 to 9999 (excluding year 0)<\/td>\n<td>Any nonzero integer<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>MONTH<\/code><\/td>\n<td>01 to 12<\/td>\n<td>0 to 11<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>DAY<\/code><\/td>\n<td>01 to 31 (limited by the values of <code>MONTH<\/code> and <code>YEAR<\/code>, according to the rules of the calendar for the locale)<\/td>\n<td>Any nonzero integer<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>HOUR<\/code><\/td>\n<td>00 to 23<\/td>\n<td>0 to 23<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>MINUTE<\/code><\/td>\n<td>00 to 59<\/td>\n<td>0 to 59<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>SECOND<\/code><\/td>\n<td>00 to 59.9(n), where 9(n) is the precision of time fractional seconds<\/td>\n<td>0 to 59.9(n), where 9(n) is the precision of interval fractional seconds<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>TIMEZONE_HOUR<\/code><\/td>\n<td>-12 to 14 (range accommodates daylight savings time changes)<\/td>\n<td>Not applicable<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>TIMEZONE_MINUTE<\/code><\/td>\n<td>00 to 59<\/td>\n<td>Not applicable<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>TIMEZONE_REGION<\/code><\/td>\n<td>Found in the view <code>V$TIMEZONE_NAMES<\/code>.<\/td>\n<td>Not applicable.<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><code>TIMEZONE_ABBR<\/code><\/td>\n<td>Found in the view <code>V$TIMEZONE_NAMES<\/code>.<\/td>\n<td>Not applicable.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Except for <code>TIMESTAMP WITH LOCAL TIMEZONE<\/code>, these types are all part of the SQL92 standard. For information about datetime and interval format models, literals, time-zone names, and SQL functions.<\/p>\n<h4>DATE<\/h4>\n<p>You use the <code>DATE<\/code> datatype to store fixed-length datetimes, which include the time of day in seconds since midnight. The date portion defaults to the first day of the current month; the time portion defaults to midnight. The date function <code>SYSDATE<\/code> returns the current date and time.<\/p>\n<p><strong>Tip:<\/strong> To compare dates for equality, regardless of the time portion of each date, use the function result <code>TRUNC(<\/code><em><code>date_variable<\/code><\/em><code>)<\/code> in comparisons, <code>GROUP BY<\/code> operations, and so on.<\/p>\n<p>Valid dates range from January 1, 4712 BC to December 31, 9999 AD. A Julian date is the number of days since January 1, 4712 BC. Julian dates allow continuous dating from reference. You can use the date format model <code>'J'<\/code> with the date functions <code>TO_DATE<\/code> and <code>TO_CHAR<\/code> to convert between <code>DATE<\/code> values and their Julian equivalents.<\/p>\n<p>In date expressions, PL\/SQL automatically converts character values in the default date format to <code>DATE<\/code> values. The default date format is set by the Oracle initialization parameter <code>NLS_DATE_FORMAT<\/code>. For example, the default might be <code>'DD-MON-YY'<\/code>, which includes -digit number for the day of the month, an abbreviation of the month name, and the last two digits of the year.<\/p>\n<p>You can add and subtract dates. For example, the following statement returns the number of days since an employee was hired:<\/p>\n<pre>SELECT SYSDATE - hiredate INTO days_worked FROM emp\r\n   WHERE empno = 7499;<\/pre>\n<p>In arithmetic expressions, PL\/SQL interprets integer literals as days. For instance, <code>SYSDATE<\/code> + 1 is tomorrow.<\/p>\n<h4>TIMESTAMP<\/h4>\n<p>The datatype <code>TIMESTAMP<\/code>, which extends the datatype <code>DATE<\/code>, stores the year, month, day, hour, minute, and second. The syntax is:<\/p>\n<pre>TIMESTAMP[(<em><code>precision<\/code><\/em>)]<\/pre>\n<p>where the optional parameter <code>precision<\/code> specifies the number of digits in the fractional part of the seconds field. You cannot use constant or variable to specify the precision; you must use an integer literal in the range 0 .. 9.<\/p>\n<p>The default timestamp format is set by the Oracle initialization parameter <code>NLS_TIMESTAMP_FORMAT<\/code>.<\/p>\n<p>In the following example, you declare of type <code>TIMESTAMP<\/code>, then assign value to it:<\/p>\n<pre>DECLARE\r\n   checkout TIMESTAMP(3);\r\nBEGIN\r\n   checkout := '1999-06-22 07:48:53.275';\r\n   ...\r\nEND;<\/pre>\n<p>In this example, the fractional part of the seconds field is <code>0.275<\/code>.<\/p>\n<h4>TIMESTAMP WITH TIME ZONE<\/h4>\n<p>The datatype <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>TIME<\/code> <code>ZONE<\/code>, which extends the datatype <code>TIMESTAMP<\/code>, includes &gt;time-zone displacement. The time-zone displacement is the difference (in hours and minutes) between local time and Coordinated Universal Time (UTC)&#8211;formerly Greenwich Mean Time. The syntax is:<\/p>\n<pre>TIMESTAMP[(<em><code>precision<\/code><\/em>)] WITH TIME ZONE<\/pre>\n<p>where the optional parameter <code>precision<\/code> specifies the number of digits in the fractional part of the seconds field. You cannot use constant or variable to specify the precision; you must use an integer literal in the range 0 .. 9.<\/p>\n<p>The default timestamp with time zone format is set by the Oracle initialization parameter <code>NLS_TIMESTAMP_TZ_FORMAT<\/code>.<\/p>\n<p>In the following example, you declare of type <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>TIME<\/code> <code>ZONE<\/code>, then assign value to it:<\/p>\n<pre>DECLARE\r\n   logoff TIMESTAMP(3) WITH TIME ZONE;\r\nBEGIN\r\n   logoff := '1999-10-31 09:42:37.114 +02:00';\r\n   ...\r\nEND;<\/pre>\n<p>In this example, the time-zone displacement is +<code>02:00<\/code>.<\/p>\n<p>You can also specify the time zone by using name. The specification can include form such as <code>'US\/Pacific'<\/code>, an abbreviation such as <code>'PDT'<\/code>, or . For example, the following literals all represent the same time. The third form is most reliable because it specifies the rules to follow at the point when switching to daylight savings time.<\/p>\n<pre>TIMESTAMP '1999-04-15 8:00:00 -8:00'\r\nTIMESTAMP '1999-04-15 8:00:00 US\/Pacific'\r\nTIMESTAMP '1999-10-31 01:30:00 US\/Pacific PDT'<\/pre>\n<p>You can find the available names for time zones in the <code>TIMEZONE_REGION<\/code> and <code>TIMEZONE_ABBR<\/code> columns of the <code>V$TIMEZONE_NAMES<\/code> data dictionary view.<\/p>\n<p>Two <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>TIME<\/code> <code>ZONE<\/code> values are considered identical if they represent the same instant in UTC, regardless of their time-zone displacements. For example, the following two values are considered identical because, in UTC, 8:00 AM Pacific Standard Time is the same as 11:00 AM Eastern Standard Time:<\/p>\n<pre>'1999-08-29 08:00:00 -8:00'\r\n'1999-08-29 11:00:00 -5:00'<\/pre>\n<h4>TIMESTAMP WITH LOCAL TIME ZONE<\/h4>\n<p>The datatype <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>LOCAL<\/code> <code>TIME<\/code> <code>ZONE<\/code>, which extends the datatype <code>TIMESTAMP<\/code>, includes &gt;time-zone displacement. The time-zone displacement is the difference (in hours and minutes) between local time and Coordinated Universal Time (UTC)&#8211;formerly Greenwich Mean Time. You can also use named time zones, as with <code>TIMESTAMP WITH TIME ZONE<\/code>.<\/p>\n<p>The syntax is<\/p>\n<pre>TIMESTAMP[(<em><code>precision<\/code><\/em>)] WITH LOCAL TIME ZONE<\/pre>\n<p>where the optional parameter <code>precision<\/code> specifies the number of digits in the fractional part of the seconds field. You cannot use constant or variable to specify the precision; you must use an integer literal in the range 0 .. 9.<\/p>\n<p>This datatype differs from <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>TIME<\/code> <code>ZONE<\/code> in that when you insert into column, the value is normalized to the database time zone, and the time-zone displacement is not stored in the column. When you retrieve the value, Oracle returns it in your local session time zone.<\/p>\n<p>In the following example, you declare of type <code>TIMESTAMP<\/code> <code>WITH<\/code> <code>LOCAL<\/code> <code>TIME<\/code> <code>ZONE<\/code>:<\/p>\n<pre>DECLARE\r\n   logoff TIMESTAMP(3) WITH LOCAL TIME ZONE;\r\nBEGIN\r\n   ...\r\nEND;<\/pre>\n<p>You cannot assign literal values to of this type.<\/p>\n<h4>INTERVAL YEAR TO MONTH<\/h4>\n<p>You use the datatype <code>INTERVAL<\/code> <code>YEAR<\/code> <code>TO<\/code> <code>MONTH<\/code> to store and manipulate intervals of years and months. The syntax is:<\/p>\n<pre>INTERVAL YEAR[(<em><code>precision<\/code><\/em>)] TO MONTH<\/pre>\n<p>where <em><code>precision<\/code><\/em> specifies the number of digits in the years field. You cannot use constant or variable to specify the precision; you must use an integer literal in the range 0 .. 4. The default is 2.<\/p>\n<p>In the following example, you declare of type <code>INTERVAL<\/code> <code>YEAR<\/code> <code>TO<\/code> <code>MONTH<\/code>, then assign of 101 years and 3 months to it:<\/p>\n<pre>DECLARE\r\n   lifetime INTERVAL YEAR(3) TO MONTH;\r\nBEGIN\r\n   lifetime := INTERVAL '101-3' YEAR TO MONTH; -- interval literal\r\n   lifetime := '101-3'; -- implicit conversion from character type\r\n   lifetime := INTERVAL '101' YEAR; -- Can specify just the years\r\n   lifetime := INTERVAL '3' MONTH; -- Can specify just the months\r\n   ...\r\nEND;<\/pre>\n<h4>INTERVAL DAY TO SECOND<\/h4>\n<p>You use the datatype <code>INTERVAL<\/code> <code>DAY<\/code> <code>TO<\/code> <code>SECOND<\/code> to store and manipulate intervals of days, hours, minutes, and seconds. The syntax is:<\/p>\n<pre>INTERVAL DAY[(<em><code>leading_precision<\/code><\/em>)] TO \r\nSECOND[(<em><code>fractional_seconds_precision<\/code><\/em>)]<\/pre>\n<p>where <em><code>leading_precision<\/code><\/em> and <em><code>fractional_seconds_precision<\/code><\/em> specify the number of digits in the days field and seconds field, respectively. In both cases, you cannot use constant or variable to specify the precision; you must use an integer literal in the range 0 .. 9. The defaults are 2 and 6, respectively.<\/p>\n<p>In the following example, you declare of type <code>INTERVAL<\/code> <code>DAY<\/code> <code>TO<\/code> <code>SECOND<\/code>:<\/p>\n<pre>DECLARE\r\n   lag_time INTERVAL DAY(3) TO SECOND(3);\r\nBEGIN\r\n   IF lag_time &gt; INTERVAL '6' DAY THEN ...\r\n   ...\r\nEND;<\/pre>\n<h3>Datetime and Interval Arithmetic<\/h3>\n<p>PL\/SQL lets you construct datetime and interval expressions. The following list shows the operators that you can use in such expressions:<\/p>\n<table dir=\"ltr\" title=\"\" border=\"1\" summary=\"\" width=\"100%\" frame=\"HSIDES\" rules=\"GROUPS\" cellspacing=\"0\" cellpadding=\"3\">\n<thead>\n<tr>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Operand 1<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Operator<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Operand 2<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>Result Type<\/strong><\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr align=\"left\" valign=\"top\">\n<td>datetime<\/td>\n<td><code>+<\/code><\/td>\n<td>interval<\/td>\n<td>datetime<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>datetime<\/td>\n<td><code>-<\/code><\/td>\n<td>interval<\/td>\n<td>datetime<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>interval<\/td>\n<td><code>+<\/code><\/td>\n<td>datetime<\/td>\n<td>datetime<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>datetime<\/td>\n<td><code>-<\/code><\/td>\n<td>datetime<\/td>\n<td>interval<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>interval<\/td>\n<td><code>+<\/code><\/td>\n<td>interval<\/td>\n<td>interval<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>interval<\/td>\n<td><code>-<\/code><\/td>\n<td>interval<\/td>\n<td>interval<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>interval<\/td>\n<td><code>*<\/code><\/td>\n<td>numeric<\/td>\n<td>interval<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>numeric<\/td>\n<td><code>*<\/code><\/td>\n<td>interval<\/td>\n<td>interval<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td>interval<\/td>\n<td><code>\/<\/code><\/td>\n<td>numeric<\/td>\n<td>interval<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can also manipulate datetime value using various functions, such as <code>EXTRACT<\/code>.<\/p>\n<p>Avoiding Truncation Problems Using Date and Time Subtypes<\/p>\n<p>The default precisions for some of the date and time types are less than the maximum precision. For example, the default for <code>DAY TO SECOND<\/code> is <code>DAY(2) TO SECOND(6)<\/code>, while the highest precision is <code>DAY(9) TO SECOND(9)<\/code>. To avoid truncation when assigning variables and passing procedure parameters of these types, you can declare variables and procedure parameters of the following subtypes, which use the maximum values for precision:<\/p>\n<dl>\n<dd><code>TIMESTAMP_UNCONSTRAINED<\/code><\/dd>\n<dd><code>TIMESTAMP_TZ_UNCONSTRAINED<\/code><\/dd>\n<dd><code>TIMESTAMP_LTZ_UNCONSTRAINED<\/code><\/dd>\n<dd><code>YMINTERVAL_UNCONSTRAINED<\/code><\/dd>\n<dd><code>DSINTERVAL_UNCONSTRAINED<\/code><\/dd>\n<\/dl>\n<h2><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">User-Defined Subtypes<\/span><\/h2>\n<p>Each PL\/SQL base type specifies of values and of operations applicable to items of that type. Subtypes specify the same set of operations as their base type but only of its values. Thus, does <em>not<\/em> introduce type; it merely places an optional constraint on its base type.<\/p>\n<p>Subtypes can increase reliability, provide compatibility with ANSI\/ISO types, and improve readability by indicating the intended use of constants and variables. PL\/SQL predefines several subtypes in package <code>STANDARD<\/code>. For example, PL\/SQL predefines the subtypes <code>CHARACTER<\/code> and <code>INTEGER<\/code> as follows:<\/p>\n<pre>SUBTYPE CHARACTER IS CHAR;\r\nSUBTYPE INTEGER IS NUMBER(38,0);  -- allows only whole numbers<\/pre>\n<p>The subtype <code>CHARACTER<\/code> specifies the same set of values as its base type <code>CHAR<\/code>, so <code>CHARACTER<\/code> is an <em>unconstrained subtype<\/em>. But, the subtype <code>INTEGER<\/code> specifies only of the values of its base type <code>NUMBER<\/code>, so <code>INTEGER<\/code> is &gt;constrained subtype.<\/p>\n<h3>Defining Subtypes<\/h3>\n<p>You can define your own subtypes in the declarative part of any PL\/SQL block, subprogram, or package using the syntax<\/p>\n<pre>SUBTYPE subtype_name IS base_type[(constraint)] [NOT NULL];<\/pre>\n<p>where <code>subtype_name<\/code> is specifier used in subsequent declarations, <code>base_type<\/code> is any scalar or user-defined PL\/SQL datatype, and <code>constraint<\/code> applies only to base types that can specify precision and scale or size.<\/p>\n<p>Some examples follow:<\/p>\n<pre>DECLARE\r\n   SUBTYPE BirthDate IS DATE NOT NULL;  -- based on DATE type\r\n   SUBTYPE Counter IS NATURAL;          -- based on NATURAL subtype\r\n   TYPE NameList IS TABLE OF VARCHAR2(10);\r\n   SUBTYPE DutyRoster IS NameList;      -- based on TABLE type\r\n   TYPE TimeRec IS RECORD (minutes INTEGER, hours INTEGER);\r\n   SUBTYPE FinishTime IS TimeRec;       -- based on RECORD type\r\n   SUBTYPE ID_Num IS emp.empno%TYPE;    -- based on column type<\/pre>\n<p>You can use <code>%TYPE<\/code> or <code>%ROWTYPE<\/code> to specify the base type. When <code>%TYPE<\/code> provides the datatype of column, the subtype inherits the size constraint (if any) of the column. However, the subtype does <em>not<\/em> inherit other kinds of constraints such as <code>NOT<\/code> <code>NULL<\/code>.<\/p>\n<h3>Using Subtypes<\/h3>\n<p>Once you define , you can declare items of that type. In the example below, you declare of type <code>Counter<\/code>. Notice how the subtype name indicates the intended use of the variable.<\/p>\n<pre>DECLARE \r\n   SUBTYPE Counter IS NATURAL;\r\n   rows Counter;<\/pre>\n<p>The following example shows that you can constrain -defined subtype when declaring variables of that type:<\/p>\n<pre>DECLARE \r\n   SUBTYPE Accumulator IS NUMBER;\r\n   total Accumulator(7,2);<\/pre>\n<p>Subtypes can increase reliability by detecting out-of-range values. In the example below, you restrict the subtype <code>Numeral<\/code> to storing integers in the range -9 .. 9. If your program tries to store outside that range in &gt;Numeral variable, PL\/SQL raises an exception.<\/p>\n<pre>DECLARE \r\n   SUBTYPE Numeral IS NUMBER(1,0);\r\n   x_axis Numeral;  -- magnitude range is -9 .. 9\r\n   y_axis Numeral;\r\nBEGIN\r\n   x_axis := 10;  -- raises VALUE_ERROR\r\n   ...\r\nEND;<\/pre>\n<h4>Type Compatibility<\/h4>\n<p>An unconstrained subtype is interchangeable with its base type. For example, given the following declarations, the value of <code>amount<\/code> can be assigned to <code>total<\/code> without conversion:<\/p>\n<pre>DECLARE \r\n   SUBTYPE Accumulator IS NUMBER;\r\n   amount NUMBER(7,2);\r\n   total  Accumulator;\r\nBEGIN\r\n   ...\r\n   total := amount;\r\n   ...\r\nEND;<\/pre>\n<p>Different subtypes are interchangeable if they have the same base type. For instance, given the following declarations, the value of <code>finished<\/code> can be assigned to <code>debugging<\/code>:<\/p>\n<pre>DECLARE \r\n   SUBTYPE Sentinel IS BOOLEAN;\r\n   SUBTYPE Switch IS BOOLEAN;\r\n   finished  Sentinel;\r\n   debugging Switch;\r\nBEGIN\r\n   ...\r\n   debugging := finished;\r\n   ...\r\nEND;<\/pre>\n<p>Different subtypes are also interchangeable if their base types are in the same datatype family. For example, given the following declarations, the value of <code>verb<\/code> can be assigned to <code>sentence<\/code>:<\/p>\n<pre>DECLARE \r\n   SUBTYPE Word IS CHAR(15);\r\n   SUBTYPE Text IS VARCHAR2(1500);\r\n   verb     Word;\r\n   sentence Text(150);\r\nBEGIN\r\n   ...\r\n   sentence := verb;\r\n   ...\r\nEND;<\/pre>\n<h2><span style=\"color: #330099; font-family: Arial,Helvetica,sans-serif;\">Datatype Conversion<\/span><\/h2>\n<p>Sometimes it is necessary to convert from one datatype to another. For example, if you want to examine , you must convert it to string. PL\/SQL supports both explicit and implicit (automatic) datatype conversion.<\/p>\n<h3>Explicit Conversion<\/h3>\n<p>To convert values from one datatype to another, you use built-in functions. For example, to convert &gt;CHAR value to &gt;DATE or <code>NUMBER<\/code> value, you use the function <code>TO_DATE<\/code> or <code>TO_NUMBER<\/code>, respectively. Conversely, to convert &gt;DATE or <code>NUMBER<\/code> value to &gt;CHAR value, you use the function <code>TO_CHAR<\/code>.<\/p>\n<h3>Implicit Conversion<\/h3>\n<p>When it makes sense, PL\/SQL can convert the datatype of implicitly. This lets you use literals, variables, and parameters of one type where another type is expected. In the example below, the <code>CHAR<\/code> variables <code>start_time<\/code> and <code>finish_time<\/code> hold string values representing the number of seconds past midnight. The difference between those values must be assigned to the <code>NUMBER<\/code> variable <code>elapsed_time<\/code>. So, PL\/SQL converts the <code>CHAR<\/code> values to <code>NUMBER<\/code> values automatically.<\/p>\n<pre>DECLARE\r\n   start_time   CHAR(5);\r\n   finish_time  CHAR(5);\r\n   elapsed_time NUMBER(5);\r\nBEGIN\r\n   \/* Get system time as seconds past midnight. *\/\r\n   SELECT TO_CHAR(SYSDATE,'SSSSS') INTO start_time FROM sys.dual;\r\n   -- do something\r\n   \/* Get system time again. *\/\r\n   SELECT TO_CHAR(SYSDATE,'SSSSS') INTO finish_time FROM sys.dual;\r\n   \/* Compute elapsed time in seconds. *\/\r\n   elapsed_time := finish_time - start_time;\r\n   INSERT INTO results VALUES (elapsed_time, ...);\r\nEND;<\/pre>\n<p>Before assigning column value to , PL\/SQL will, if necessary, convert the value from the datatype of the source column to the datatype of the variable. This happens, for example, when you select &gt;DATE column value into &gt;VARCHAR2 variable.<\/p>\n<p>Likewise, before assigning the value of to column, PL\/SQL will, if necessary, convert the value from the datatype of the variable to the datatype of the target column. If PL\/SQL cannot determine which implicit conversion is needed, you get error. In such cases, you must use conversion function. Table 3-1 shows which implicit conversions PL\/SQL can do.<\/p>\n<p><strong>Notes:<\/strong><\/p>\n<ul>\n<li type=\"disc\">The table lists only types that have different representations. Types that have the same representation, such as <code>CLOB<\/code> and <code>NCLOB<\/code>, <code>CHAR<\/code> and <code>NCHAR<\/code>, and <code>VARCHAR<\/code> and <code>NVARCHAR2<\/code>, can be substituted for each other.<\/li>\n<li type=\"disc\">To convert between <code>CLOB<\/code> and <code>NCLOB<\/code>, you must use the conversion functions <code>TO_CLOB<\/code> and <code>TO_NCLOB<\/code>.<\/li>\n<li type=\"disc\"><code>TIMESTAMP<\/code>, <code>TIMESTAMP WITH TIME ZONE<\/code>, <code>TIMESTAMP WITH LOCAL TIME ZONE<\/code>, <code>INTERVAL DAY TO SECOND<\/code>, and <code>INTERVAL YEAR TO MONTH<\/code> can all be converted using the same rules as the <code>DATE<\/code> type. However, because of their different internal representations, these types cannot always be converted to each other.<\/li>\n<\/ul>\n<h5><span style=\"font-family: Helvetica,Arial,sans-serif;\"> <strong><span style=\"font-family: Arial,Helvetica,sans-serif;\"><em>Table 3-1 <strong><em>Implicit Conversions<\/em><\/strong><\/em><\/span><\/strong><\/span><\/h5>\n<table dir=\"ltr\" title=\"\" border=\"1\" summary=\"\" width=\"100%\" frame=\"HSIDES\" rules=\"GROUPS\" cellspacing=\"0\" cellpadding=\"3\">\n<thead>\n<tr>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>BIN_INT<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>BLOB<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>CHAR<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>CLOB<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>DATE<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>LONG<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>NUMBER<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>PLS_INT<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>RAW<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>UROWID<\/strong><\/span><\/th>\n<th scope=\"col\" align=\"left\" valign=\"bottom\"><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>VARCHAR2<\/strong><\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>BIN_INT<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>BLOB<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>CHAR<\/strong><\/span><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>CLOB<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>DATE<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>LONG<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>NUMBER<\/strong><\/span><\/td>\n<td>X<\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>PLS_INT<\/strong><\/span><\/td>\n<td>X<\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>RAW<\/strong><\/span><\/td>\n<td><\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>UROWID<\/strong><\/span><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td>X<\/td>\n<\/tr>\n<tr align=\"left\" valign=\"top\">\n<td><span style=\"font-family: Arial,Helvetica,sans-serif;\"><strong>VARCHAR2<\/strong><\/span><\/td>\n<td>X<\/td>\n<td><\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td>X<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>It is your responsibility to ensure that values are convertible. For instance, PL\/SQL can convert the <code>CHAR<\/code> value <code>'02-JUN-92'<\/code> to &gt;DATE value but cannot convert the <code>CHAR<\/code> value <code>'YESTERDAY'<\/code> to &gt;DATE value. Similarly, PL\/SQL cannot convert &gt;VARCHAR2 value containing alphabetic characters to &gt;NUMBER value.<\/p>\n<h3>Implicit versus Explicit Conversion<\/h3>\n<p>Generally, to rely on implicit datatype conversions is programming practice because they can hamper performance and might change from one software release to the next. Also, implicit conversions are context sensitive and therefore not always predictable. Instead, use datatype conversion functions. That way, your applications will be more reliable and easier to maintain.<\/p>\n<h3>DATE Values<\/h3>\n<p>When you select &gt;DATE column value into &gt;CHAR or <code>VARCHAR2<\/code> variable, PL\/SQL must convert the internal binary value to value. So, PL\/SQL calls the function <code>TO_CHAR<\/code>, which returns string in the default date format. To get other information such as the time or Julian date, you must call <code>TO_CHAR<\/code> with mask.<\/p>\n<p>A conversion is also necessary when you insert &gt;CHAR or <code>VARCHAR2<\/code> value into &gt;DATE column. So, PL\/SQL calls the function <code>TO_DATE<\/code>, which expects the default date format. To insert dates in other formats, you must call <code>TO_DATE<\/code> with mask.<\/p>\n<h3>RAW and LONG RAW Values<\/h3>\n<p>When you select &gt;RAW or <code>LONG<\/code> <code>RAW<\/code> column value into &gt;CHAR or <code>VARCHAR2<\/code> variable, PL\/SQL must convert the internal binary value to value. In this case, PL\/SQL returns each binary byte of <code>RAW<\/code> or <code>LONG<\/code> <code>RAW<\/code> data as of characters. Each character represents the hexadecimal equivalent of (half ). For example, PL\/SQL returns the binary byte 11111111 as the pair of characters <code>'FF'<\/code>. The function <code>RAWTOHEX<\/code> does the same conversion.<\/p>\n<p>A conversion is also necessary when you insert &gt;CHAR or <code>VARCHAR<\/code>2 value into &gt;RAW or <code>LONG<\/code> <code>RAW<\/code> column. Each pair of characters in the variable must represent the hexadecimal equivalent of byte. If either character does not represent the hexadecimal equivalent of , PL\/SQL raises an exception.<\/p>\n<h6>-Oracle<\/h6>\n<div class=\"apply\">\n<h3>Apply for PL SQL Certification Now!!<\/h3>\n<p><a href=\"http:\/\/www.vskills.in\/certification\/Certified-PL-SQL-Developer\">http:\/\/www.vskills.in\/certification\/Certified-PL\/SQL-Developer<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lexical elements and basic data types Certify and Increase Opportunity. Be Govt. Certified PL SQL Developer PL\/SQL LEXICAL ELEMENTS A lexical element refers to a character or groupings of characters that may legally appear in a source file. Basic lexical elements are Tokens Source program character set Comments PL\/SQL DATATYPES Every constant, variable, and parameter&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[288],"tags":[],"class_list":["post-22056","page","type-page","status-publish","hentry","category-pl-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Lexical elements and basic data types<\/title>\n<meta name=\"description\" content=\"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lexical elements and basic data types\" \/>\n<meta property=\"og:description\" content=\"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:46:42+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"37 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/\",\"name\":\"Lexical elements and basic data types\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2013-05-13T04:57:16+00:00\",\"dateModified\":\"2024-04-12T08:46:42+00:00\",\"description\":\"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lexical elements and basic data types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lexical elements and basic data types","description":"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/","og_locale":"en_US","og_type":"article","og_title":"Lexical elements and basic data types","og_description":"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:46:42+00:00","twitter_misc":{"Est. reading time":"37 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/","name":"Lexical elements and basic data types","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2013-05-13T04:57:16+00:00","dateModified":"2024-04-12T08:46:42+00:00","description":"Learn about Lexical elements and basic data types and improve your knowledge towards PL\/SQL certification of Vskills. These are globally recognized.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/lexical-elements-and-basic-data-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Lexical elements and basic data types"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/22056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=22056"}],"version-history":[{"count":11,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/22056\/revisions"}],"predecessor-version":[{"id":51925,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/22056\/revisions\/51925"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=22056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=22056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=22056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}