Oracle Block Statement DBMS输出语法

问题描述 投票:1回答:2

我仅为这个问题而创建了该帐户,因为我真的不确定如何正确地用词表达以供Google使用。所以这里去...

我正在查询数据库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这样的引用吗?

sql oracle plsql syntax
2个回答
0
投票

字符串连接运算符在PL / SQL中为||,所以您要编写

dbms_output.put_line('The Employee with the ID of' || Emp_ID || ' will receive a 2% bonus.');

0
投票

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

干杯!

© www.soinside.com 2019 - 2024. All rights reserved.