首页 > 解决方案 > 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 这样的引用吗?

标签: sqloracleplsqlsyntax

解决方案


在 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仅使用两个参数作为输入。所以你需要多次使用它来连接两个以上的字符串。

干杯!!


推荐阅读