sql - Oracle 块语句 DBMS 输出语法
问题描述
我只是为了这个问题而创建了这个帐户,因为我真的不确定如何正确地用词来让谷歌接受它。所以这里...
我正在为我在数据库 II 课程中分配的一个小组项目进行查询。当我想看看我是否可以做类似以下的事情时,我做了 2 并且正在研究第三个。
declare
Emp_ID := 03;
Salary_Increment := 2.0 --constants do not change
Salary_ID := 03;
Current_Salary := 47500
Updated_Salary := Current_Salary * 2.0
BEGIN
dbms_output.put_line('The Employee with the ID of' +Emp_ID 'will receive a 2% bonus.');
dbms_output.put_line('This Employees new salary will be: ' +Updated_Salary ');
end;
我以前尝试过这样做,但使用了更简单的代码片段。想我会看看我是否可以这样做只是为了简化我必须输入的内容。
TL;DR - 我可以在 Oracle SQL dbms 输出中使用像 +Emp_ID 这样的引用吗?
解决方案
在 oracle 中,有两种连接字符串的方法。
- 使用
||
运算符。
像这样。
dbms_output.put_line('The Employee with the ID of' || Emp_ID || ' will receive a 2% bonus.');
- 使用
CONCAT
方法。
像这样:
dbms_output.put_line(CONCAT(CONCAT('The Employee with the ID of', Emp_ID), ' will receive a 2% bonus.'));
请注意,CONCAT
仅使用两个参数作为输入。所以你需要多次使用它来连接两个以上的字符串。
干杯!!
推荐阅读
- python-3.x - 是否可以在另一个数据框的列中搜索两个数据框列的值并返回匹配的 ID?
- node.js - 我有 Express + Mongo + Mongoose 后端应用程序。如果您没有通过 Modal 创建文档,如何从 DB 获取或更新文档?
- dart - 什么可能导致所附图片中显示的错误?
- c++ - 如何计算此循环的所有数字的总和
- php - 无法让 Laravel Passport 与 Vapor 一起使用
- solr - 带有空格的 Solr 查询以及查询和操作
- amazon-web-services - 如何使用 terraform 连接不同 VPC 中的副本 Postgres RDS 及其源?
- laravel - 为什么我在进行 Laravel 项目时需要公开宣传
- amazon-web-services - 每个 VPC 端口警报的 aws 网关负载均衡器终端节点
- c# - 创建一个接受类型并返回该类型实例的泛型方法