English 中文(简体)
SQL 查询 - 如何删除空并替换为空白
原标题:SQL Query - How to remove null and replace with blank
  • 时间:2012-05-22 05:28:59
  •  标签:
  • sql

以下是我的查询:

SELECT ename, sal, comm
FROM EMP
WHERE comm IS NULL
ORDER BY sal DESC;

我想用空白空间替换 NULLL 导致 comm 列的空格。 我在 SELECT下被告知, 写 NULLL( com,) , 但是这有错误, 表示号码无效。 如果我有 < code> NULLL( com, 0) , 则查询有效, 在列中返回 0 。

根据我的理解,这意味着我只能在这个专栏中拥有一个数字值,无论我想要什么空白空间。有人能给我一些指导吗?

问题回答

如果您想要从查询中输出空格/空格, 如果您正在使用 Oracle( 正如您的 SQL 开发者引用建议), 那么您需要使用 < code> NVL () 函数, 使用 < code> TO_ CHAR () :

SELECT ename, sal, NVL( TO_CHAR(comm),     ) comm
FROM   EMP
WHERE  comm IS NULL
ORDER  BY sal DESC;

TO_CHAR() 需要将 NUMBER 转换为 >VARCHAR2 ,使其与空白(可能是某种字符值,可能存储为 VARCHAR2 内部)相容。 这样您就可以避免“ 无效编号” 错误 。

尝试此查询 :

UPDATE EMP SET `ename`=   WHERE `ename` IS NULL

我认为,你应该重复一遍这个查询, 重复你桌上每一列的查询。

我会用

SELECT coalesce(Comm,  ) FROM EMP WHERE comm IS NULL ORDER BY sal DESC
SELECT SUBJECT, DESCRIPTION, NVL(A.FILENAME,   ) AS FILENAME, 
            to_char(CREATEDATE,  yyyy-mm-dd ) AS CURRDATE, STATUS,  
            ASSIGNTO FROM RQST_DETAIL

使用下面的查询

从 EMP ORDER 中选择 ename, ISNULL( com, ) As com, sal 按 sal desc 键

它将用逗号列的空白替换空值

运行 DESCRIBE EMP 并张贴结果到问题。在查询的结果中,您已经运行了按 CTRL-A CTRL-STRL-SHIFT-C 并粘贴到问题。这将更好地描述您取得的成就以及您希望如何改变。

最终您可以运行以下 SQL 以校验您正在运行的 Oracle 版本

select * from v$version 

你该看看这个样子的

BANNER
Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE   11.2.0.1.0  Production"
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

如果这不起作用, 那么 SQL 开发者可能无法连接到 Oracle DB 。 在框中 SQL 开发者只连接到 Oracle DB 和 MS 访问 吗?

最后,为了回答你的实际问题, NVL 函数以传给它的第二个参数来取代 NVL 函数 。

这里有一个空间。

SELECT ename, sal, NVL(TO_CHAR(comm),   )
FROM EMP
WHERE comm IS NULL
ORDER BY sal DESC;

如果列不是字符串,您可以先投出,然后使用内核

select isnull(cast(columnname as varchar(102)),  ) as XYZ




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签