`
zsjg13
  • 浏览: 142402 次
  • 性别: Icon_minigender_1
  • 来自: 安徽
社区版块
存档分类
最新评论

DEFINEs and bind variables

 
阅读更多

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.

分享到:
评论

相关推荐

    STM8A Firmware Library and Examples

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

    jdk-9.0.1_doc-all 最新版

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

    Ruby Pocket Reference

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

    EXECUTABLE AND LINKABLE FORMAT

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

    Introduction to Java programing and Data structures 2019版

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

    Introduction_to_Optimum_Design.pdf

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

    标题中的"cl_platform.rar_contains(DEFINES"暗示了这是一个与OpenCL平台相关的代码库,其中包含了定义(DEFINES)。OpenCL是一种跨平台的并行计算框架,主要用于利用GPU和其他处理器进行计算。描述提到"AVAILABLE_...

    Software.Testing.Concepts.and.Operations.1118662873.epub

    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

    Software Defines Tactics

    C 程序设计教学课件:Chapter 3 class and object.ppt

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

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    MULTIGIG RT 2, RT 2-R, and RT 3 Signal Connectors .pdf

    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.

    Understanding augmented reality concepts and applications 、Alan B. Craig.

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

    Object-Oriented Analysis and Design 第六章

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

    eating.cpp : Defines the class behaviors for the application

    17.C++不仅仅是支持面向对象的程序设计语言;  18.学习编程最好的方法之一就是阅读源代码;  19.在任何时刻都不要认为自己手中的书已经足够了;  20.请阅读《The Standard C++ Bible》(中文版:标准C++宝典...

    opengles_spec_2_0

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

    PXI Hardware and Software Specification

    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.

Global site tag (gtag.js) - Google Analytics