Sql 如何将数字替换/转换为字符串

Sql 如何将数字替换/转换为字符串,sql,oracle,Sql,Oracle,我有一个查询工作正常,返回-1: 但我想将-1转换/替换为string->‘no_doc’ 如果使用replace,则返回0 我想,因为这是一个数字 NVL不工作了。To_char-1也不起作用。或者我失败了 SELECT REPLACE('-1', '-1', 'no_doc') FROM .... output: 0 SELECT REPLACE(-1, -1, 2) FROM .... output: 2 我怎样才能达到预期的产出?”没有文档“这将起作用: select decode(

我有一个查询工作正常,返回-1:

但我想将-1转换/替换为string->‘no_doc’

如果使用replace,则返回0

我想,因为这是一个数字

NVL不工作了。To_char-1也不起作用。或者我失败了

SELECT REPLACE('-1', '-1', 'no_doc') FROM ....
output: 0
SELECT REPLACE(-1, -1, 2) FROM .... 
output: 2
我怎样才能达到预期的产出?”没有文档“

这将起作用:

select decode((select -1 from dual),-1,'no_doc','anything') from dual;
对于您的查询:

 select decode((SELECT -1 FROM (select SUM(column1), column2 
 from documents where column2 is NULL group by column2) aa
 where aa.column2_rid = rid and typ_doc in (4,2) and rownum = 
 1),-1,'no_doc','anything') from dual;
这将有助于:

select decode((select -1 from dual),-1,'no_doc','anything') from dual;
对于您的查询:

 select decode((SELECT -1 FROM (select SUM(column1), column2 
 from documents where column2 is NULL group by column2) aa
 where aa.column2_rid = rid and typ_doc in (4,2) and rownum = 
 1),-1,'no_doc','anything') from dual;
为什么不能在查询中使用“no_doc”而不是-1

select 'no_doc'
from (select SUM(column1), column2 
      from documents
      where column2 is NULL
      group by column2
     ) aa
where aa.column2_rid = rid and typ_doc in (4,2) and
      rownum = 1;
为什么不能在查询中使用“no_doc”而不是-1

select 'no_doc'
from (select SUM(column1), column2 
      from documents
      where column2 is NULL
      group by column2
     ) aa
where aa.column2_rid = rid and typ_doc in (4,2) and
      rownum = 1;
您也可以使用NVL2函数

您也可以使用NVL2函数


你能取消删除你刚刚删除的问题吗。请把数字显示出来好吗?我有一个答案给你。@Boneist我做了。你能取消删除刚才删除的问题吗。请把数字显示出来好吗?我有一个答案给你。@Boneist是我做的。对不起,我忘了提到,我正在使用NVL函数来测试我的查询。NVLquery1,query2-在第一个查询中我有数字,所以我不能在2中使用。一个没有医生。是的,我知道在这种情况下,这不是正确的答案,但它对我帮助很大。我给你+1,因为你的答案也是正确的。对不起,我忘了提到,我正在使用NVL函数来测试我的查询。NVLquery1,query2-在第一个查询中我有数字,所以我不能在2中使用。一个没有医生。是的,我知道在这种情况下,这不是正确的答案,但它对我帮助很大。我给你+1,因为你的答案也是正确的。