Siva Kumar
Siva Kumar

Reputation: 23

How to write a query to print the output enclosed within single quote and percentage

SELECT employee_id FROM employee where employee_name='SMITH';

Output is 76123

How to write a query in Oracle to print the output as follows

'%76123%'

Upvotes: 0

Views: 40

Answers (1)

Littlefoot
Littlefoot

Reputation: 142958

Using concatenation is one option.

SQL> select chr(39) || '%' || empno || '%' ||chr(39) as result
  2  from emp
  3  where rownum = 1;

RESULT
--------------------------------------------
'%7369%'

SQL>

chr(39) is a single quote (simpler to use it than repeating several single quotes):

SQL> select '''%' || empno || '%''' as result
  2  from emp
  3  where rownum = 1;

RESULT
--------------------------------------------
'%7369%'

SQL>

Upvotes: 1

Related Questions