- 1、本文档共19页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
05.一般变量与替代变量
目标 了解变量的声明 掌握一般变量与替代变量应用 声明 PL/SQL 一般变量 一般变量 PL/SQL 块中可以使用变量 在声明部分声明,使用前必须先声明 声明时必须指定数据类型,每行声明一个标识符 在可执行部分的 SQL 语句和过程语句中使用 一般变量作用域 变量声明开始到块的结束(不能在块的声明部分同时声明两个同名的变量,但可在不同的块中声明同名变量) 替代变量 使用SQL*Plus 替代变量来暂时保存值. 单个()符号 两个 ()符号 DEFINE和 ACCEPT 命令 在 SQL命令中传递变量值. 动态更改表头和表尾. 带有一个的替换变量 使用 SET VERIFY 命令 带有两个的替换变量 使用带有两个的变量可以使得该变量可以重复使用,而不必在每次使用时提醒用户输入. 定义用户变量 可以使用下面的两个 SQL*Plus 命令来预定义用户变量: DEFINE: 创建 CHAR类型的用户变量。 ACCEPT: 读取用户输入并把它存在一个变量里面。 当使用DEFINE命令来定义一个包含空格的变量时,要用单引号将该变量括起来。 ACCEPT 命令 当接收用户输入时,创建可定制的用户提示。 明确地定义 NUMBER或者DATE类型的变量。 出于安全方面的因素,隐藏用户的输入。 DEFINE 和 UNDEFINE 命令 一个变量将保持在被定义的状态,直到: 使用 UNDEFINE 命令将它清除 离开 SQL*Plus 可以用DEFINE 命令验证所做的改变. 使用 DEFINE命令 创建一个deptname变量以存储部门名称. 总结 一般变量的应用 替代变量的应用 本课程版权归北风网所有 欢迎访问我们的官方网站 Substitution Variables In SQL*Plus, you can use single-ampersand () substitution variables to temporarily store values. You can predefine variables in SQL*Plus by using the ACCEPT or DEFINE commands. ACCEPT reads a line of user input and stores it in a variable. DEFINE creates and assigns a value to a variable. Examples of Restricted Ranges of Data Report figures for the current quarter or specified date range only Report on data relevant to the user requesting the report only Display personnel within a given department only Other Interactive Effects Interactive effects are not restricted to direct user interaction with the WHERE clause. The same principles can be used to achieve other goals. For example: Dynamically altering headers and footers Obtaining input values from a file rather than from a person Passing values from one SQL statement to another SQL*Plus does not support validation checks (except for datatype) on user input. Make sure that the prompts that you write for the user are simple and unambiguous. Instructor Note A substitution variable can be used anywhere in SQL and SQL*Plus commands, except as the first word entered at the command prompt. Single-Ampersand Substitution Variable When running a report, users often want to restrict
文档评论(0)