Aspirant
Aspirant

Reputation: 2278

How to include double quotes in select statement?

i have a table like

 id    name 
 10    bob
 20    bill

i want to select only name column in output with double quotes

like select '"'||name||'"' from table it is giving me the correct output but is there any other way without using concatenation ...

Thank you..

Upvotes: 4

Views: 58344

Answers (5)

Sakthivel
Sakthivel

Reputation: 1938

There are two scenarios you would want to use double quotes in sql in my opinion.

  1. Updating a string column which contains single multiple quotes in it. (you have to escape it)
  2. updating blog contents in columns which you cant edit in "edit top 200 rows"

    so, if you want to use double quotes follow this.

    SET QUOTED_IDENTIFIER OFF
    BEGIN
    DECLARE @YourSqlStmt AS VarChar(5000) -- Declare a variable.
    SET @YourSqlStmt = "ok"
    PRINT @YourSqlStmt -- do your operations here
    END

    This saves time and you need not to escape single quotes in a existing string content of the column.

Upvotes: 0

Viranja kaushalya
Viranja kaushalya

Reputation: 785

Using this you can get result with double quotes

' " ' + columnName + ' " '

Example

Query

SELECT '"'+Name+'"' , Age
FROM customer

Result

"Viranja" | 27

Upvotes: 9

Robert Co
Robert Co

Reputation: 1715

If your intention is to be able to "export" the result into space or comma-delimited text file, use a view to "format" your data. You will need to this for your date columns as well.

Upvotes: 0

davek
davek

Reputation: 22895

Create a virtual column that adds the quotes:

CREATE TABLE
....
quoted_name VARCHAR2 GENERATED ALWAYS AS ('"' || name || '"') VIRTUAL,
...

See here for more information:

http://www.oracle-base.com/articles/11g/virtual-columns-11gr1.php

Upvotes: 3

Joe G Joseph
Joe G Joseph

Reputation: 24046

this will check for any name with at least one double quote

select * from table
where name like '%"%'

Upvotes: 0

Related Questions