1

I made this account just for this question because I'm really not sure how to word it properly for google to pick up on it. So here goes...

I was working on a query for a group project that I was assigned in my database II course. I made 2 and was working on a third when I wanted to see if I could do something like the following.

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;

I attempted to do this previously but with a more simple code snippet. Figured I would see if I could do this just to simplify how much I have to type out.

TL;DR - Can I use a reference like +Emp_ID in a Oracle SQL dbms output?

1
  • The concatenation operator is ||. I’m not clear what this has to do with dbms_output specifically though, or with PL/SQL in general. Commented Nov 22, 2019 at 17:14

2 Answers 2

1

In oracle, There are two ways of concating the string.

  • using || operator.

Like this.

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

Like this:

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

Note that CONCAT uses only two parameter as input. So you need to use it multiple times to concat more than 2 strings.

Cheers!!

Sign up to request clarification or add additional context in comments.

Comments

0

The string concatenation operator is || in PL/SQL, so you'd want to write

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.