46

I want to generate an output with blank/empty column with a "Select" query in oracle. I'm able to achieve this with below sql query:

SELECT CustomerName AS Customer, "" AS Contact 
FROM Customers;

So when I run above sql query it returns a table with two columns "Customer" column with content in it and "Contact" column with no content or blank column. I want to achieve same with oracle query. Any help will be highly appreciated.

2
  • What do mean by "Oracle query"? Especially as distinct from "SQL Query"? My guess is you mean SQL as implemented in SQL Server and SQL as implemented in Oracle Database Server. Also, in Oracle strings are delimited with single quotes. So "" AS Contact would be '' AS Contact Note also, in Oracle, NULL and the empty string '' are the same thing. Commented Aug 2, 2016 at 20:54
  • @ShannonSeverance: I'm new to this database queries, so I'm sorry if I have confused you with my terminology. However your guess is correct. Also I tried '' AS Contact as you suggested in sql developer tool but I is generating (null) in each row of Contact column. My requirement is to generate blank/empty rows in Contact column. FYI, if I run "" AS Contact query on H2 database it is generating blank/empty rows. Actually my requirement is to convert already existing sql query on H2 database to Oracle database. Commented Aug 3, 2016 at 12:56

3 Answers 3

57

I think you should use null

SELECT CustomerName AS Customer, null AS Contact 
FROM Customers;

And Remember that Oracle

treats a character value with a length of zero as null.

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

7 Comments

I tried this query in sql developer tool, it is generating Contact column with (null) in every row. But my requirement is it should generate blank/empty rows in Contact column. Where as the same query when I run in SQuirrel tool running on H2 data base it generates blank/empty Contact column. I want to get same result when I run a query on oracle database.
I don't undetsand .. update your question with proper data sample
I have fixed my issue with below query: SELECT CustomerName Customer, NVL('',' ') Contact FROM Customers . Here it is replacing the null values with empty space.
Well ..so you needed that in the field there is a value, but it is not visible? I did not understand the question
There is a value as "Null" and I want it to be empty. So I just replacing this null value with empty space (' ').
|
13

In DB2, using single quotes instead of your double quotes will work. So that could translate the same in Oracle..

SELECT CustomerName AS Customer, '' AS Contact 
FROM Customers;

Comments

0

I guess you will get ORA-01741: illegal zero-length identifier if you use the following

SELECT "" AS Contact  FROM Customers;

And if you use the following 2 statements, you will be getting the same null value populated in the column.

SELECT '' AS Contact FROM Customers; OR SELECT null AS Contact FROM Customers;

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.