How PL/SQL outputs the Boolean Type

Source: Internet
Author: User

Boolean is a type of PL/SQL data. Logical values are true and false. Only logical operators can be applied to boolean variables. The Database SQL type does not support Boolean
Type. Only PL/SQL is supported. Therefore, you cannot insert or retrieve boolean values in the database. The following describes the Declaration and value assignment of the Boolean Type and how to output the boolean type.

1. boolean declaration and value assignment PL/SQL provide two values, indicating that the direct values of Boolean values are true and false. These values are not strings, and we do not need to quote them. You can directly assign values to boolean variables using Boolean values. -- Declaration and value assignment example: declare is_boolean; -- declare a Boolean variable begin is_boolean: = false; -- assign an end value to this variable; -- by default, the default value of boolean type is falsedeclare v_boolean Boolean; begin if v_boolean then dbms_output.put_line ('true'); else Merge ('false'); end if; end; falsepl/SQL procedure successfully completed. only true, false, and null can be assigned to boolean variables. When Relational operators are used in an expression, the returned results are also boolean values, as shown in the following example: v_flag: = (count> 200 ); 2. How to output the Boolean Type -- the following example shows a case where the put_line function is used to output SQL> declare 2 v_bool Boolean; 3 begin 4 v_bool: = true; 5 dbms_output.put_line ('the value if v_bool is '| v_bool); 6 end; 7/dbms_output.put_line ('the value if v_bool is' | v_bool); * error at line 5: ORA-06550: line 5, column 26: PLS-00306: Wrong number or types of arguments in call to '| 'ora-06 550: line 5, column 4: PL/SQL: Statement ignored -- the error message PLS-00306 was received when the boolean type was output above -- note that the put_line function is used here, because the parameters of the dbms_output function do not support the boolean type, an error message is displayed. The following is the description of the put_line function parameter SQL> DESC dbms_outputprocedure put_line argument name type in/out default? ------------------------------ --------------------- ------ -------- A varchar2 in can be implemented by calling the I _convert_from_boolean function in the dbms_sqltcb_internal package, and the corresponding permissions should be granted when calling. SQL> declare 2 v_bool Boolean; 3 begin 4 v_bool: = true; 5 dbms_output.put_line ('firstly, v_bool is '| sys. dbms_sqltcb_internal. I _convert_from_boolean (v_bool); 6 v_bool: = false; 7 dbms_output.put_line ('Next, v_bool is '| sys. dbms_sqltcb_internal. I _convert_from_boolean (v_bool); 8 end; 9/firstly, v_bool is truenext, v_bool is falsepl/SQL procedure successfully completed. also, return the Boolean function bool2char (bool in Boolean) return varchar2 is begin if bool then return 'true'; elsif not bool then return 'false '; else return 'null'; end if; end; SQL> declare 2 v_bool Boolean; 3 4 function bool2char (bool in Boolean) 5 return varchar2 is 6 begin 7 if bool then 8 return 'true'; 9 elsif not bool then 10 return 'false'; 11 else 12 Return 'null'; 13 end if; 14 end; 15 begin 16 v_bool: = true; 17 dbms_output.put_line ('firstly, v_bool is '| bool2char (v_bool); 18 v_bool: = false; 19 dbms_output.put_line ('Next, v_bool is '| bool2char (v_bool); 20 v_bool: = NULL; 21 dbms_output.put_line ('Finally, v_bool is' | bool2char (v_bool); 22 end; 23/firstly, v_bool is truenext, v_bool is falsefinally, v_bool is nullpl/SQL procedure successfully completed. --> author: Robinson Cheng blog: http://blog.csdn.net/robinson_0612

More references

Batch SQL forall statements

Bulk collect clause for batch SQL

Initialization and assignment of PL/SQL Sets

PL/SQL Union arrays and nested tables
PL/SQL variable-length Array
PL/SQL --> PL/SQL records

SQL tuning steps

Efficient SQL statements

Parent cursor, child cursor, and shared cursor

Bind variables and their advantages and disadvantages

Use of the display_cursor function of dbms_xplan

Use of the display function of dbms_xplan

Description of each field module in the execution plan

Use explain plan to obtain the SQL statement execution plan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.