PL / SQL字符串转换为布尔 [英] PL/SQL Convert String To Boolean

查看:1186
本文介绍了PL / SQL字符串转换为布尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有发送的形式与一些值的EXT JS网页。该值在字符串中的所有发送,有的送布尔。它被调用在其中PARAMS都是VARCHAR一个PL / SQL过程。用于当表单提交某些原因,即使有些值作为布尔送出,它们不能由过程作为布尔接收。从程序接收到的所有值都为varchar;而且必须,否则崩溃。

I have an EXT JS page which sends a form with some values. The values are all sent in string and some sent as boolean. It is calling a PL/SQL procedure where the params are all varchar. For some reason when the form is submitted, even though some values are sent as boolean, they can not be received by the procedure as boolean. All the values received from the procedure are varchar; and must be otherwise it crashes.

所以我把从形式到程序一个布尔值。当它得到的程序,现在是一个varchar。我如何转换这回一个布尔值?

So I am sending a boolean from the form to the procedure. When it gets to the procedure it is now a varchar. How can I convert this back to a boolean?

在所有AP preciated任何帮助,我觉得我在这里做得不对。我不明白为什么它正在接收此为VARCHAR。

Any help at all appreciated, I feel like I'm doing something wrong here. I don't understand why it is receiving this as a varchar.

推荐答案

您是对的,没有甲骨文内置字符串到布尔函数,但是你可以很容易地自己创建一个:

You are right that there is no Oracle built-in string-to-boolean function, but you could easily create one yourself:

create or replace function to_boolean
  ( p_string varchar2
  ) return boolean
is
begin
  return
    case upper(p_string) 
      when 'TRUE' then true
      when 'FALSE' then false
      else null
      end;
end;

(以下简称否则返回null是多余的,但我把它放在那里,以提醒大家,如果上(p_string)比真或假的任何其他则函数将返回null)。

(The "else null" is redundant but I put it there to remind you that if upper(p_string) is anything other than 'TRUE' or 'FALSE' then the function will return null).

您当然可以增强功能对待其他字符串值是true或false也如'T','YES',...

You could of course enhance the function to treat other string values as true or false also e.g. 'T', 'YES', ...

这篇关于PL / SQL字符串转换为布尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆