Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Variables Scope in SQL Procedure 
 

Variable Scope in SQL Procedure is used to define the scope of a variable used in SQL.

 

Variables Scope in SQL Procedure

                         

 

Variable Scope in SQL Procedure is used to define the scope of a variable used in SQL.

Understand with Example

The Tutorial illustrates an example from Variable Scope in SQL Procedure. 

For sake of your understanding : 

Local  variables - These variable are declared inside a inner block and cannot be referenced by outside blocks.

Global variables - These variable  are declared in a outer block and  reference itself and its inner blocks.

To understand Variable Scope in SQL, we create a Procedure abc that include a Local variable. The Local variable are declared in a inner block and cannot be accessed by outside blocks In this example we declare a variable 'x', whose data type is char and default value is 'inner' in the Local variables. The SQL Query include a outer block and declare a variable 'x' whose data type is 'char' type. These are declared in outer block which can be referenced by its itself and inner blocks.

 Create Procedure

delimiter $$
create procedure abc()
BEGIN
DECLARE x CHAR(5) DEFAULT 'outer';
	BEGIN 
		DECLARE x CHAR(5) DEFAULT 'inner';
		Select x;
	END;
Select x;
END$$
delimiter ;

Call Procedure

To invoke a Procedure 'abc', we use the given below Syntax :

call abc();

Result

+-------+
| x     |
+-------+
| inner |
+-------+
1 row in set (0.00 sec)
+-------+
| x     |
+-------+
| outer |
+-------+
1 row in set (0.03 sec)

                         

» View all related tutorials
Related Tags: sql mysql c query syntax ant reference sed display range limit number int tar start show if for poi ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.