SQL*Plus can also create and manipulate its own in-memory variables, and it set aside a few special variables that will affect its behavior. Actually, there are two separate types of variables in SQL*Plus:
DEFINEs and bind variables. To assign a value to a DEFINE variable, you can use the DEFINE command:
SQL> DEFINE x = "the answer is 42"
To view the value of x, specify:
SQL> DEFINE x
DEFINE X = "the answer is 42" (CHAR)
You would refer to such a variable using an ampersand (&). SQL*Plus dose a simple substitution before
sending the statement to the Oracle database, so you will need single quote marks around the variable when you want to use it as a literal string:
SELECT '&x' FROM DUAL;
For bind variables, you first declare the variable. You can then use it in PL/SQL, and display it using the
SQL*Plus PRINT command:
SQL> VARIABLE x VARCHAR2(10)
SQL> BEGIN
2 :x := 'hullo';
3 END;
4 /
PL/SQL procedure successfully completed.
SQL> PRINT :x
X
--------------------------------
hullo
This can get a little bit confusing because there are now two different “x” variables, one
that has been defined and one that has been declared:
SQL> SELECT :x, '&x' FROM DUAL;
old 1: SELECT :x, '&x' FROM DUAL
new 1: SELECT :x, 'the answer is 42' FROM DUAL
:X 'THEANSWERIS42'
-------------------------------- ----------------
hullo the answer is 42
Just remember that DEFINEs are always character strings expanded by SQL*Plus, and declared variables are used as true bind variables in SQL and PL/SQL.
相关推荐
"Data Structures": Lists the variables, defines, structures, ... "Files" : Lists all the files and globals. "Directories" : List of directories. Note: Use ADC and LINUART for STM8A 128K (STM8AF51...
Defines the rmic compiler for generating stubs and skeletons using the Java Remote Method Protocol (JRMP) and stubs and tie class files (IIOP protocol) for remote objects. jdk.scripting.nashorn ...
- **Predefined Variables:** Ruby defines several predefined variables that hold important values, such as `$0` for the name of the current program, `$!` for the last error message, etc. The book lists...
In summary, the **Executable and Linkable Format** (ELF) is a comprehensive standard that defines the structure and behavior of executable and linkable files. It is widely used across various ...
The new ACM/IEEE Computer Science Curricular 2013 defines the Body of Knowledge organized into 18 Knowledge Areas. To help instructors design the courses based on this book, we provide sample syllabi ...
- **Definition of a Standard Linear Programming Problem:** Defines the standard form of LP problems and discusses key components like linear constraints and unrestricted variables. - **Basic Concepts ...
标题中的"cl_platform.rar_contains(DEFINES"暗示了这是一个与OpenCL平台相关的代码库,其中包含了定义(DEFINES)。OpenCL是一种跨平台的并行计算框架,主要用于利用GPU和其他处理器进行计算。描述提到"AVAILABLE_...
Defines the concept of a software fault, and the related concept of relative correctness, and shows how relative correctness can be used to characterize monotonic fault removal Presents the activity ...
Software Defines Tactics
A class defines the properties and actions that its objects will have. For instance, in designing a car, the class might include attributes like color, model, and speed, while methods could include ...
VPX 连接器资料 This specification covers the requirements for ... The VITA 46 standard defines connector requirements and OpenVPX standard slot configurations are defined in VITA 65.0 and 65.1.
Chapter 1 also provides a history of augmented reality, compares and situates augmented reality with related media an technologies, and defines some key terms related to augmented reality, including ...
- Interpreter pattern defines a grammatical representation for a language and provides an interpreter to evaluate the language. - Iterator pattern provides a way to access the elements of an aggregate...
17.C++不仅仅是支持面向对象的程序设计语言; 18.学习编程最好的方法之一就是阅读源代码; 19.在任何时刻都不要认为自己手中的书已经足够了; 20.请阅读《The Standard C++ Bible》(中文版:标准C++宝典...
variables and command parameters no longer support fixed point in order to simplify the API and also because the fixed point variants do not offer any additional performance. The OpenGL ES 2.0 ...
This section describes the primary objectives and scope of the PCI eXtensions for Instrumentation (PXI) ... It also defines the intended audience and lists relevant terminology and documents.