简体   繁体   中英

Oracle SQL : concatenation - missing expression

I am using the Employees table to practice the following:

I would like to display a column with a statement saying

This is my New salary after 10% increase :- and salary + 10% 

Below is the script I used but it didn't work

select 
    Salary,
    'This is my new Salary after 10% increase :- ' || Salary + 10%, 
From 
    Employees;

Huh, that's what you can only wish (I mean, invent your own syntax). Should have been eg

SQL> select sal,
  2    'This is my new salary after 10% increase: ' || sal * 1.1 as result
  3  from emp
  4  where empno = 7369;

       SAL RESULT
---------- -------------------------------------------------------------------
      1000 This is my new salary after 10% increase: 1100

SQL>

Please try this:

select 
Salary,
'This is my new Salary after 10% increase :- ' || Salary * 1.1 NEW_SAL
From Employees;

Output: 2600 This is my new Salary after 10% increase:- 2860

I think you should be able to use val + its 10%, so 110% of the val. Furthermore you cannot use 110% (you would be forced to cast it etc.) so it is much better to use 1.1 of the val.

SELECT 
   sal AS Salary,
   'This is my new salary after 10% increase: ' || sal * 1.1 AS 'New Salary'
 FROM emp;

So for all employees you should see their current salary and 110% of the salary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM