Variables in Oracle

Source: Internet
Author: User

In an SQL statement, you can define a variable before you use it, and you can use that variable multiple times in the same SQL statement. You can use the Define or accept command to define variables, and you can use the undefine command to delete variables.
Using the Define Command
Define show all defined variables
Define variable displays the name, value, and parameter type of the specified variable
Define Variable=value creates a user variable of type char and assigns an initial value to the variable.
You can also use the Accept command to define variables and to customize a user prompt that prompts the user to enter data for the specified variable. When you define a variable, you can explicitly specify whether the variable is number or date lamp data type. For security reasons, you can also hide the information entered by the user.
The syntax of the Accept command is as follows:
Accept variable [data_type][format][default][prompt text|noprompt][hide]
Define examples are as follows:
Sql> Define Temp=20
Sql> Define Temp
DEFINE TEMP = "(CHAR)"
Sql> SELECT * FROM dept where deptno>&temp
2;
Original Value 1:select * from dept where deptno>&temp
New Value 1:select * from dept where deptno>20


DEPTNO dname LOC
---------- -------------- -------------
SALES CHICAGO
OPERATIONS BOSTON
The following are the examples of accept:
Sql> Accept Test Number format 999 prompt ' Please enter a digit '
Please enter a number 20
Sql> SELECT * FROM dept where deptno>&test;
Original Value 1:select * from dept where deptno>&test
New Value 1:select * from dept where deptno> 20


DEPTNO dname LOC
---------- -------------- -------------
SALES CHICAGO
OPERATIONS BOSTON

Variables in Oracle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.