<legend id='9eEqo'><style id='9eEqo'><dir id='9eEqo'><q id='9eEqo'></q></dir></style></legend>
          <bdo id='9eEqo'></bdo><ul id='9eEqo'></ul>

        <small id='9eEqo'></small><noframes id='9eEqo'>

        <tfoot id='9eEqo'></tfoot>

        <i id='9eEqo'><tr id='9eEqo'><dt id='9eEqo'><q id='9eEqo'><span id='9eEqo'><b id='9eEqo'><form id='9eEqo'><ins id='9eEqo'></ins><ul id='9eEqo'></ul><sub id='9eEqo'></sub></form><legend id='9eEqo'></legend><bdo id='9eEqo'><pre id='9eEqo'><center id='9eEqo'></center></pre></bdo></b><th id='9eEqo'></th></span></q></dt></tr></i><div id='9eEqo'><tfoot id='9eEqo'></tfoot><dl id='9eEqo'><fieldset id='9eEqo'></fieldset></dl></div>
      1. PL/SQL 中布尔值的使用

        Use of boolean in PL/SQL(PL/SQL 中布尔值的使用)

          • <bdo id='iF1zv'></bdo><ul id='iF1zv'></ul>
          • <tfoot id='iF1zv'></tfoot>

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

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

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

                1. 本文介绍了PL/SQL 中布尔值的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 PL/SQL 中有一个函数,它检查特定的 emp_id 是否存在,即:

                  I have a function in PL/SQL which checks if a particular emp_id exists or not which is:

                  CREATE OR REPLACE FUNCTION checkEmpNo(eno numeric)
                  RETURN boolean IS
                      emp_number number;
                  BEGIN
                      SELECT emp_id INTO emp_number
                      FROM emp;
                      IF eno=emp_number
                      THEN
                          return true;
                      ELSE
                          return false;
                      END IF;
                  END checkEmpNo;
                  

                  该函数编译成功,但是当我尝试将其运行为:

                  The function compiles successfully, but when I try to run it as:

                  DECLARE
                      exist boolean;
                  BEGIN
                      exist=checkEmpNo(1);
                      dbms_output.put_line(exist);
                  END;
                  

                  它返回错误:

                  ORA-06550: line 5, column 1:
                  PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
                  ORA-06550: line 5, column 1:
                  PL/SQL: Statement ignored
                  
                  3. BEGIN
                  4. exist:=checkEmpNo(1);
                  5. dbms_output.put_line(exist);
                  6. END;
                  

                  我也试过这个:

                  DECLARE
                      exist boolean:=true;
                  BEGIN
                      if(exist=checkEmpNo(1))
                      then
                          dbms_output.put_line('true');
                      else
                          dbms_output.put_line('false');
                      end if;
                  END;
                  

                  它返回错误:ORA-01422:exact fetch返回超过请求的行数

                  推荐答案

                  dbms_output.put_line 未重载以接受布尔参数.你可以做类似的事情

                  dbms_output.put_line is not overloaded to accept a boolean argument. You can do something like

                  dbms_output.put_line( case when exist = true 
                                             then 'true'
                                             else 'false'
                                          end );
                  

                  将布尔值转换为字符串,然后您可以将其传递给 dbms_output.

                  to convert the boolean into a string that you can then pass to dbms_output.

                  ORA-01422 错误是一个完全独立的问题.函数 checkEmpNo 包括 SELECT INTO 语句

                  The ORA-01422 error is a completely separate issue. The function checkEmpNo includes the SELECT INTO statement

                  SELECT emp_id 
                    INTO emp_number
                    FROM emp;
                  

                  如果查询返回除 1 行以外的任何内容,SELECT INTO 将生成错误.在这种情况下,如果 emp 表中有多行,您将收到错误消息.我的猜测是您希望您的函数执行类似

                  A SELECT INTO will generate an error if the query returns anything other than 1 row. In this case, if there are multiple rows in the emp table, you'll get an error. My guess is that you would want your function to do something like

                  CREATE OR REPLACE FUNCTION checkEmpNo(p_eno number)
                    RETURN boolean 
                  IS
                    l_count number;
                  BEGIN
                    SELECT count(*)
                      INTO l_count
                      FROM emp
                     WHERE emp_id = p_eno;
                  
                    IF( l_count = 0 )
                    THEN
                      RETURN false;
                    ELSE
                      RETURN true;
                    END IF;
                  END checkEmpNo;
                  

                  这篇关于PL/SQL 中布尔值的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的重置序列)
                  <legend id='rpDCH'><style id='rpDCH'><dir id='rpDCH'><q id='rpDCH'></q></dir></style></legend>

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

                            <tbody id='rpDCH'></tbody>
                            <bdo id='rpDCH'></bdo><ul id='rpDCH'></ul>
                            <tfoot id='rpDCH'></tfoot>