SQLcl 22.4

简介: SQLcl 22.4

PROMPT

The PROMPT option of the ARGUMENT command allows us set the prompt text displayed if the argument is missing from the command line. Create a file called "test.sql" with the following contents.

set verify off

argument 1 prompt "Enter a value for the first argument:"


column arguments format a10


select '&1' as arguments;


undefine 1

Let's breakdown what we are doing here.

  • We use SET VERIFY OFF so we don't display old and new values for the argument.
  • We use the ARGUMENT command to define the prompt text for argument number 1.
  • We use the argument in a query to display the value.
  • We use UNDEFINE to make sure the current value of the argument is not reused. In SQLcl we could use SET PARAMETERPOLICY ISOLATE to achieve this, but using UNDEFINE works for both tools.

We test the script. In the first example we are prompted and provide the value "banana". In the second example we are prompted and provide the value "apple". In the third example we provide the value "pear" on the command line, and we are not prompted to enter a value.

SQL> @test.sql

Enter a value for the first argument:banana


ARGUMENTS

----------

banana


SQL> @test.sql

Enter a value for the first argument:apple


ARGUMENTS

----------

apple


SQL> @test.sql pear


ARGUMENTS

----------

pear


1 row selected.


SQL>

PROMPT and HIDE (SQL*Plus Only)

Adding the HIDE keyword to the ARGUMENT command means the text we enter is no longer echoed to the screen. This is useful when entering passwords. We amend the previous script to add the HIDE keyword.

set verify off

argument 1 prompt "Enter a value for the first argument:" hide


column arguments format a10


select '&1' as arguments;


undefine 1

We test the amended script. In the first example we are prompted and provide the value "secret". Notice this is not echoed to the screen. In the second example we provide the value "secret2" on the command line, and we are not prompted to enter a value.

SQL> @test.sql

Enter a value for the first argument:


ARGUMENTS

----------

secret


1 row selected.


SQL> @test.sql secret2


ARGUMENTS

----------

secret2


1 row selected.


SQL>

DEFAULT

Not surprisingly the DEFAULT keyword allows us to define a default value to use if an argument is not specified. We amend the previous script to assign a default value.

set verify off

argument 1 default "banana"


column arguments format a10


select '&1' as arguments;


undefine 1

We test the amended script. If we don't provide a command line argument the default value of "banana" is used. If we provide the command line argument, it is used.

SQL> @test.sql


ARGUMENTS

----------

banana


1 row selected.


SQL> @test.sql apple


ARGUMENTS

----------

apple


1 row selected.


SQL>

ARGUMENT with DEFINE

In the previous examples we have used the arguments directly, but we could use them in conjunction with a DEFINE command. We amend the test script giving it the following contents. In this example we have used the first argument to define "arg1", which we use the in the subsequent query.

set verify off

argument 1 prompt "Enter a value for arg1:"

define arg1 = '&1';


column arguments format a10


select '&arg1' as arguments;


undefine 1

We test the amended script and it performs as expected.

SQL> @test.sql

Enter a value for arg1:banana


ARGUMENTS

----------

banana


1 row selected.


SQL> @test.sql apple


ARGUMENTS

----------

apple


1 row selected.


SQL>

ARGUMENT with VARIABLE

We can also use arguments with variables defined in SQL*Plus and SQLcl. We amend the test script giving it the following contents. In this example we have defined a variable called "var1" and set it to the value if the first argument. We use the variable in the subsequent query.

variable var1 varchar2(10);


set verify off

argument 1 prompt "Enter a value for var1:"

set feedback off

exec :var1:= '&1';

set feedback on


column arguments format a10


select :var1 as arguments;


undefine 1

We test the amended script and it performs as expected.

SQL> @test.sql

Enter a value for var1:banana


ARGUMENTS

----------

banana


1 row selected.


SQL> @test.sql apple


ARGUMENTS

----------

apple


1 row selected.


SQL>

For more information see:

相关文章
|
3天前
|
弹性计算 人工智能 安全
云上十五年——「弹性计算十五周年」系列客户故事(第二期)
阿里云弹性计算十五年深耕,以第九代ECS g9i实例引领算力革新。携手海尔三翼鸟、小鹏汽车、微帧科技等企业,实现性能跃升与成本优化,赋能AI、物联网、智能驾驶等前沿场景,共绘云端增长新图景。
|
9天前
|
存储 弹性计算 人工智能
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
2025年9月24日,阿里云弹性计算团队多位产品、技术专家及服务器团队技术专家共同在【2025云栖大会】现场带来了《通用计算产品发布与行业实践》的专场论坛,本论坛聚焦弹性计算多款通用算力产品发布。同时,ECS云服务器安全能力、资源售卖模式、计算AI助手等用户体验关键环节也宣布升级,让用云更简单、更智能。海尔三翼鸟云服务负责人刘建锋先生作为特邀嘉宾,莅临现场分享了关于阿里云ECS g9i推动AIoT平台的场景落地实践。
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
|
8天前
|
人工智能 自然语言处理 自动驾驶
关于举办首届全国大学生“启真问智”人工智能模型&智能体大赛决赛的通知
关于举办首届全国大学生“启真问智”人工智能模型&智能体大赛决赛的通知
|
8天前
|
云安全 人工智能 自然语言处理
阿里云x硅基流动:AI安全护栏助力构建可信模型生态
阿里云AI安全护栏:大模型的“智能过滤系统”。
|
9天前
|
编解码 自然语言处理 文字识别
Qwen3-VL再添丁!4B/8B Dense模型开源,更轻量,仍强大
凌晨,Qwen3-VL系列再添新成员——Dense架构的Qwen3-VL-8B、Qwen3-VL-4B 模型,本地部署友好,并完整保留了Qwen3-VL的全部表现,评测指标表现优秀。
654 7
Qwen3-VL再添丁!4B/8B Dense模型开源,更轻量,仍强大
|
4天前
|
人工智能 运维 Java
Spring AI Alibaba Admin 开源!以数据为中心的 Agent 开发平台
Spring AI Alibaba Admin 正式发布!一站式实现 Prompt 管理、动态热更新、评测集构建、自动化评估与全链路可观测,助力企业高效构建可信赖的 AI Agent 应用。开源共建,现已上线!
|
11天前
|
存储 机器学习/深度学习 人工智能
大模型微调技术:LoRA原理与实践
本文深入解析大语言模型微调中的关键技术——低秩自适应(LoRA)。通过分析全参数微调的计算瓶颈,详细阐述LoRA的数学原理、实现机制和优势特点。文章包含完整的PyTorch实现代码、性能对比实验以及实际应用场景,为开发者提供高效微调大模型的实践指南。
779 2
|
2天前
|
编解码 文字识别 算法
一张图能装下“千言万语”?DeepSeek-OCR 用视觉压缩长文本,效率提升10倍!
一张图能装下“千言万语”?DeepSeek-OCR 用视觉压缩长文本,效率提升10倍!
333 10