Monday, July 7, 2008

Literals and literal Types in Oracle

The word literals in oracle just point to a fixed data value. Suppose in a table dept(id, name) we insert value as (1,'CIT') then both 1 and 'CIT' are termed as literals. Now we we want to insert just CIT data value without single quote into name column then it will generate error.

So numeric values should be entered without quota and character values should be within single quotes.
Based on the data values inserted into a table literals can be classified into four categories.

1)Text Literals
------------------------------

Use the text literal notation to specify values of strings. The format to specify text literal forms any one of the following,
-[N]{'}{character}{'}
-[N][Q]{'}{quote delimeter}{character}{quote delimeter}{'}


Note that {} /braces indicates the mandatory and brackets [] indicate optional.
In the second format of text literals,
•Q or q indicates that the alternative quoting mechanism will be used.
•C or c is any member of the user's character set. You can include quotation marks (") in the text literal made up of c characters. You can also include the quote_delimiter, as long as it is not immediately followed by a single quotation mark.

Using first format method example of valid literals are,
'testing'
N'testing'
'test''s'

Using second format method example of valid literals are,
q'!name LIKE '%ARJU_%%'!'
q'<'So,' I said 'It's going.'>'
q'{SELECT * FROM dept where name = 'ARJU';}'
q'"dept like '['"'

SQL> select q'<'So,' I said 'It's going.'>' from dual;

Q'<'SO,'ISAID'IT'SGOING.'>
--------------------------
'So,' I said 'It's going.'

2)Numeric Literals
------------------------------

•The interger literals form [+|-]{digit} format like +10,9. -100 etc.
•The number and floating point literals hold any one of the following format,
-[+|-]{digit}[.][digit][e][+|-][digit][f|d]
-[+|-][.]{digit}[digit][e][+|-][digit][f|d]

-f or F indicates that the number is a 32-bit binary floating point number (of type BINARY_FLOAT).
-d or D indicates that the number is a 64-bit binary floating point number (of type BINARY_DOUBLE)
The example of valid unmber and floating point literals are +1.23F,.123,1e-9 -1D etc.



3)Datetime Literals
------------------------------------
4)Interval Literals
-----------------------------------------

Both of these are dicussed in
http://arjudba.blogspot.com/2008/06/datetime-and-interval-datatypes.html

No comments:

Post a Comment