“布尔"Oracle 存储过程的参数

quot;Booleanquot; parameter for Oracle stored procedure(“布尔Oracle 存储过程的参数)
本文介绍了“布尔"Oracle 存储过程的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Oracle 没有用于参数的布尔类型,并且目前正在采用 NUMBER 类型,该类型的 True/False 为 1/0(而不是 'Y'/'N' CHAR(1) 方法).

I'm aware that Oracle does not have a boolean type to use for parameters, and am currently taking in a NUMBER type which would have 1/0 for True/False (instead of the 'Y'/'N' CHAR(1) approach).

我不是一个非常高级的 Oracle 程序员,但是在进行了一些挖掘和阅读一些 ASKTOM 帖子之后,您似乎可以使用如下格式来限制字段:

I'm not a very advanced Oracle programmer, but after doing some digging and reading some ASKTOM posts, it seems like you can restrict a field using a format for the column like:

MyBool NUMBER(1) CHECK (MyBool IN (0,1))

有没有办法对存储过程的输入参数应用相同类型的检查约束?我想将可能的输入限制为 0 或 1,而不是在收到输入后明确检查它.

Is there a way to apply the same sort of a check constraint to an input parameter to a stored procedure? I'd like to restrict the possible inputs to 0 or 1, rather than checking for it explicitly after receiving the input.

推荐答案

可以使用布尔值作为存储过程的参数:

You can use Booleans as parameters to stored procedures:

procedure p (p_bool in boolean) is...

但是,您不能在 SQL 中使用布尔值,例如选择语句:

However you cannot use Booleans in SQL, e.g. select statements:

select my_function(TRUE) from dual; -- NOT allowed

对于数字参数,无法以声明方式向其添加检查约束",您必须编写一些验证代码,例如

For a number parameter there is no way to declaratively add a "check constraint" to it, you would have to code some validation e.g.

procedure p (p_num in number) is
begin
   if p_num not in (0,1) then
      raise_application_error(-20001,'p_num out of range');
   end if;
   ...

这篇关于“布尔"Oracle 存储过程的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)