Search This Blog

Wednesday, February 9, 2022

Oracle / PLSQL: Literals

 

Oracle / PLSQL: Literals

This Oracle tutorial explains how to use literals (text, integer, and number) in Oracle with examples.

Description

In Oracle, a literal is the same as a constant. We'll cover four types of literals - text literals, integer literals, number, and date/time literals.

Text Literals

Text literals are always surrounded by single quotes (').

For example:

'Hewlett Packard'
'28-FEB-22'

Integer Literals

Integer literals can be up to 38 digits. Integer literals can be either positive numbers or negative numbers. If you do not specify a sign, then a positive number is assumed. Here are some examples of valid integer literals:

23
+23
-23

Number Literals

Number literals can be up to 38 digits. Number literals can be either positive or negative numbers. If you do not specify a sign, then a positive number is assumed. Here are some examples of valid number literals:

25
+25
-25
25e-04
25.607

Date/Time Literals

Date and time are enclosed in single quotes (').

For example:

'2021-04-30'
'2021-04-30 08:13:24'

When dealing with date/time values, you will want to use the TO_DATE function to convert a literal to a date.

For example:

SELECT TO_DATE('2021/04/30', 'yyyy/mm/dd')
FROM dual;

This example will take a literal value of '2021/04/30' and convert it to a date.

No comments:

Post a Comment

PL/SQL - Collections

A collection is an ordered group of elements having the same data type. Each element is identified by a unique subscript that represents its...