<bdo id='yTdCv'></bdo><ul id='yTdCv'></ul>

<small id='yTdCv'></small><noframes id='yTdCv'>

<tfoot id='yTdCv'></tfoot>

    <legend id='yTdCv'><style id='yTdCv'><dir id='yTdCv'><q id='yTdCv'></q></dir></style></legend>

  1. <i id='yTdCv'><tr id='yTdCv'><dt id='yTdCv'><q id='yTdCv'><span id='yTdCv'><b id='yTdCv'><form id='yTdCv'><ins id='yTdCv'></ins><ul id='yTdCv'></ul><sub id='yTdCv'></sub></form><legend id='yTdCv'></legend><bdo id='yTdCv'><pre id='yTdCv'><center id='yTdCv'></center></pre></bdo></b><th id='yTdCv'></th></span></q></dt></tr></i><div id='yTdCv'><tfoot id='yTdCv'></tfoot><dl id='yTdCv'><fieldset id='yTdCv'></fieldset></dl></div>
    1. 检查是否“这是一个数字"Oracle 中的函数

      时间:2023-09-20
        <bdo id='y7o72'></bdo><ul id='y7o72'></ul>
        <legend id='y7o72'><style id='y7o72'><dir id='y7o72'><q id='y7o72'></q></dir></style></legend>

              <tbody id='y7o72'></tbody>
          1. <i id='y7o72'><tr id='y7o72'><dt id='y7o72'><q id='y7o72'><span id='y7o72'><b id='y7o72'><form id='y7o72'><ins id='y7o72'></ins><ul id='y7o72'></ul><sub id='y7o72'></sub></form><legend id='y7o72'></legend><bdo id='y7o72'><pre id='y7o72'><center id='y7o72'></center></pre></bdo></b><th id='y7o72'></th></span></q></dt></tr></i><div id='y7o72'><tfoot id='y7o72'></tfoot><dl id='y7o72'><fieldset id='y7o72'></fieldset></dl></div>
            1. <tfoot id='y7o72'></tfoot>

                <small id='y7o72'></small><noframes id='y7o72'>

                本文介绍了检查是否“这是一个数字"Oracle 中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试检查 oracle (10g) 查询中列中的值是否为数字以便进行比较.类似的东西:

                I'm trying to check if a value from a column in an oracle (10g) query is a number in order to compare it. Something like:

                select case when ( is_number(myTable.id) and (myTable.id >0) ) 
                            then 'Is a number greater than 0' 
                            else 'it is not a number' 
                       end as valuetype  
                  from table myTable
                

                关于如何检查的任何想法?

                Any ideas on how to check that?

                推荐答案

                假设 myTable 中的 ID 列未声明为 NUMBER(这似乎是一个奇怪的选择并且可能有问题),您可以编写一个函数,尝试将(大概是 VARCHAR2)ID 转换为数字、捕获异常并返回Y"或N".类似的东西

                Assuming that the ID column in myTable is not declared as a NUMBER (which seems like an odd choice and likely to be problematic), you can write a function that tries to convert the (presumably VARCHAR2) ID to a number, catches the exception, and returns a 'Y' or an 'N'. Something like

                CREATE OR REPLACE FUNCTION is_number( p_str IN VARCHAR2 )
                  RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE
                IS
                  l_num NUMBER;
                BEGIN
                  l_num := to_number( p_str );
                  RETURN 'Y';
                EXCEPTION
                  WHEN value_error THEN
                    RETURN 'N';
                END is_number;
                

                然后您可以将该调用嵌入到查询中,即

                You can then embed that call in a query, i.e.

                SELECT (CASE WHEN is_number( myTable.id ) = 'Y' AND myTable.id > 0 
                               THEN 'Number > 0'
                             ELSE 'Something else'
                         END) some_alias
                  FROM myTable
                

                请注意,尽管 PL/SQL 具有布尔数据类型,但 SQL 没有.因此,虽然您可以声明一个返回布尔值的函数,但您不能在 SQL 查询中使用这样的函数.

                Note that although PL/SQL has a boolean data type, SQL does not. So while you can declare a function that returns a boolean, you cannot use such a function in a SQL query.

                这篇关于检查是否“这是一个数字"Oracle 中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:确定 Oracle null == null 下一篇:在 oracle 12c 中将 sql 查询的结果作为 JSON 返回

                相关文章

                  <bdo id='dwE80'></bdo><ul id='dwE80'></ul>
              • <small id='dwE80'></small><noframes id='dwE80'>

              • <i id='dwE80'><tr id='dwE80'><dt id='dwE80'><q id='dwE80'><span id='dwE80'><b id='dwE80'><form id='dwE80'><ins id='dwE80'></ins><ul id='dwE80'></ul><sub id='dwE80'></sub></form><legend id='dwE80'></legend><bdo id='dwE80'><pre id='dwE80'><center id='dwE80'></center></pre></bdo></b><th id='dwE80'></th></span></q></dt></tr></i><div id='dwE80'><tfoot id='dwE80'></tfoot><dl id='dwE80'><fieldset id='dwE80'></fieldset></dl></div>
              • <legend id='dwE80'><style id='dwE80'><dir id='dwE80'><q id='dwE80'></q></dir></style></legend>

                  1. <tfoot id='dwE80'></tfoot>