暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

CAST Between Boolean Data Type and Other Oracle Built-In Data Types

zy 2024-08-30
162

The rules to cast between BOOLEAN and other Oracle built-in data types are as follows:

When casting BOOLEAN to numeric :
• If the boolean value is true, then resulting value is 1.
• If the boolean value is false, then resulting value is 0.

When casting numeric to BOOLEAN :
• If the numeric value is non-zero (e.g., 1, 2, -3, 1.2), then resulting value is true.
• If the numeric value is zero, then resulting value is false.

When casting BOOLEAN to CHAR(n) and NCHAR(n):
• If the boolean value is true and n is not less than 4, then the resulting value is ‘TRUE’ extended on the right by n - 4 spaces.
• If the boolean value is false and n is not less than 5, then the resulting value is ‘FALSE’ extended on the right by n – 5 spaces.
• Otherwise, a data exception error is raised.

When casting a character string to boolean, leading and trailing spaces of the character string are ignored. If the resulting character string is one of the accepted literals used to determine a valid boolean value, then the result is that valid boolean value.

When casting BOOLEAN to VARCHAR(n), NVARCHAR(n)
• If the boolean value is true and n is not less than 4, then resulting value is true.
• If the boolean value is false and n is not less than 5, then resulting value is false.
• Otherwise, a data exception error is raised.

You can use the function TO_BOOLEAN to explicitly convert character value expressions or numeric value expressions to boolean values.
Functions TO_CHAR, TO_NCHAR, TO_CLOB, TO_NCLOB, TO_NUMBER, TO_BINARY_DOUBLE, and TO_BINARY_FLOAT have boolean overloads to convert boolean values to number or character types.

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论