Reputation: 23
I need to get a value in Oracle SQl with Quotes Example
SQL: SELECT mrpid from demandbasic;
MRPID
------------
DEM#000001
I need to get the result as
MRPID
------------
'DEM#000001'
how to get the result as it is desired
Upvotes: 2
Views: 6263
Reputation: 3729
By the way, there is an alternate way to quote in SQL (starting with 10gR2), it's called the Q-quote mechanism. You can do this:
select q'[']' || mrpid || q'[']' from demandbasic;
Using normal quoting as described in Michael's answer makes more sense in simple examples like this one but the q-quote technique is more convenient to use if the quoted text itself contains single quotes.
Related links:
The Q-quote mechanism
Oracle Documentation
Upvotes: 8
Reputation: 270607
Just concatenate it with escaped quotes:
SELECT '''' || mrpid || '''' AS mrpid FROM demandbasic;
Four single-quotes ''''
is one string literal single-quote. That is, one quote escaped as ''
and surrounded in quotes to be a string literal.
Upvotes: 8