<legend id='2wOru'><style id='2wOru'><dir id='2wOru'><q id='2wOru'></q></dir></style></legend>

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

      1. <small id='2wOru'></small><noframes id='2wOru'>

        IF NOT EXISTS 在函数 PLSQL 中

        IF NOT EXISTS In Function PLSQL(IF NOT EXISTS 在函数 PLSQL 中)

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

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

          • <bdo id='VBZDF'></bdo><ul id='VBZDF'></ul>

                1. 本文介绍了IF NOT EXISTS 在函数 PLSQL 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个函数,它在打开游标之前具有三个 If/Then 语句.If/Then 语句在打开游标之前检查有效性.

                  I have a function which has three If/Then statements before opening a cursor. The If/Then statements check validity prior to opening the cursor.

                  我想再添加一个 If/Then 有效性检查,但是,它比其他的要复杂一些.下面是一个示例,我已经阻止评论了我想添加的内容:

                  I would like to add one more If/Then validity check, however, it is a bit more complicated than the others. Below is a sample, and I have block commented what I would like to add:

                  begin
                      if not procedure.validation_function (<variable>, <condition>=TRUE) then
                          return variable2;
                      end if;
                  
                     /* if not exists
                      (
                         SELECT 'x' FROM table1
                         WHERE table1_id = variable1_id
                         AND trunc(sysdate) < trunc(table1_date + 60)
                      ) then
                          return variable2;
                      end if; */
                  
                      open cursor(<argument>);
                      fetch cursor into <variable>;
                      close cursor;
                      return <variable>;
                  
                  
                  end;
                  

                  我的问题是我来自 T-SQL 世界,我发现在 PL/SQL 中 if not exists 命令不起作用.有没有办法可以从函数内部使用 If NO_DATA_FOUND 语句来使用 SELECT?

                  My problem is that I come from a T-SQL world, and I am finding in PL/SQL the if not exists command does not work. Is there a way I can, from within the function, have an If NO_DATA_FOUND statement where I utilize SELECT?

                  有没有办法在其中嵌套另一个函数,以便我可以:

                  Is there a way to nest another function within that, so I can:

                  begin
                       SELECT ....
                       FROM ....
                       WHERE ....
                          if NO_DATA_FOUND then
                             return variable2;
                          end if;
                  end;
                  

                  推荐答案

                  Exists 条件只能在 SQL 语句中使用,不能在 PL/SQL 中直接使用.有几个选项:

                  Exists condition can be used only in SQL statement, it cannot be used directly in PL/SQL. There are several options:

                  • select 语句中使用case 表达式和exists 条件:

                  • Using case expression with exists condition inside a select statement:

                  SQL> declare
                    2    l_exists number(1);
                    3  begin
                    4    select case
                    5             when exists(select 1
                    6                           from employees
                    7                          where department_id = 1)
                    8             then 1
                    9             else 0
                   10           end into l_exists
                   11      from dual;
                   12  
                   13     if (l_exists = 1)
                   14     then
                   15       dbms_output.put_line('exists');
                   16     else
                   17       dbms_output.put_line(q'[doesn't exist]');
                   18     end if;
                   19  end;
                   20  /
                  
                   doesn't exist
                  
                   PL/SQL procedure successfully completed
                  

                2. Or(需要rownum,保证多条记录满足匹配条件,只返回一条记录):

                3. Or (rownum is needed to guarantee that the only one record will be returned if there are several records meet matching condition):

                  SQL> declare
                    2    l_exists number;
                    3  begin
                    4  
                    5    select 1
                    6      into l_exists
                    7      from employees
                    8     where department_id = 100
                    9       and rownum = 1;
                   10  
                   11     dbms_output.put_line('exists');
                   12  
                   13  exception
                   14    when no_data_found
                   15    then dbms_output.put_line(q'[doesn't exist]');
                   16  end;
                   17  /
                  
                   exists
                  
                   PL/SQL procedure successfully completed
                  

                4. 这篇关于IF NOT EXISTS 在函数 PLSQL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to redirect the output of DBMS_OUTPUT.PUT_LINE to a file?(如何将 DBMS_OUTPUT.PUT_LINE 的输出重定向到文件?)
                  How do I get column datatype in Oracle with PL-SQL with low privileges?(如何使用低权限的 PL-SQL 在 Oracle 中获取列数据类型?)
                  Get a list of all functions and procedures in an Oracle database(获取 Oracle 数据库中所有函数和过程的列表)
                  Why cannot I create triggers on objects owned by SYS?(为什么我不能在 SYS 拥有的对象上创建触发器?)
                  Returning result even for elements in IN list that don#39;t exist in table(即使对于表中不存在的 IN 列表中的元素也返回结果)
                  Reset Sequence in oracle 11g(oracle 11g 中的重置序列)

                      <bdo id='8m4il'></bdo><ul id='8m4il'></ul>
                        <tbody id='8m4il'></tbody>
                    • <small id='8m4il'></small><noframes id='8m4il'>

                        <legend id='8m4il'><style id='8m4il'><dir id='8m4il'><q id='8m4il'></q></dir></style></legend>
                          • <tfoot id='8m4il'></tfoot>

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