Microsoft.NET

……………………………………………….Expertise in .NET Technologies

Oracle Basics – Part IV

Posted by Ravi Varma Thumati on October 12, 2009

Literals

A literal is the same as a constant. We’ll cover three types of literals – text literals, integer literals, and number literals

Text literals are always surrounded by single quotes (‘). For example:

‘Hewlett Packard’
’28-MAY-03′

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 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

Declaring Variables

The syntax for declaring variables is:

variable_name [CONSTANT] datatype [NOT NULL] [:= | DEFAULT initial_value]

For example:

Declaring a variable:

LDescription varchar2(40);

Declaring a constant:

LTotal CONSTANT numeric(8,1) := 8363934.1;

Declaring a variable with an initial value (not a constant):

LType varchar2(10) := ‘Example’;

Is Null

In PLSQL to check if a value is null, you must use the “IS NULL” syntax.

For example,

IF Lvalue IS NULL then

    …

END IF;

If Lvalue contains a null value, the “IF” expression will evaluate to TRUE.

You can also use “IS NULL” in an SQL statement. For example:

select * from suppliers
where supplier_name IS NULL;

This will return all records from the suppliers table where the supplier_name contains a null value.

IS  NOT NULL

In PLSQL to check if a value is not null, you must use the “IS NOT NULL” syntax.

For example,

IF Lvalue IS NOT NULL then

    …

END IF;

If Lvalue does not contain a null value, the “IF” expression will evaluate to TRUE.

You can also use “IS NOT NULL” in an SQL statement. For example:

select * from suppliers
where supplier_name IS NOT NULL;

This will return all records from the suppliers table where the supplier_name does not contain a null value

 

Advertisements

One Response to “Oracle Basics – Part IV”

  1. Almost all I can say is, I’m not sure what to say! Except certainly, for the amazing tips that are shared with this blog. I’m able to think of a zillion fun ways to read the content on this site. I’m sure I will eventually make a move employing your tips on areas I could not have been able to handle alone. You had been so careful to let me be one of those to profit from your useful information. Please see how great I am thankful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: