oracle储存过程中,if条件为某变量不等于1,怎么写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle储存过程中,if条件为某变量不等于1,怎么写相关的知识,希望对你有一定的参考价值。

if v_storeid520 <>1 then
v_sql := 'update ' || v_userinfo.aorgalias ||
'.tab520 t set t.nbyj=''' || v_nbyj ||
''' Where t.StoreID = '||v_storeid520||' ';
execute immediate v_sql;
end if;

这是我的语句,意思是想如果这个v_storeid520变量,等于1的话,不执行update。而如果不等于1,则执行update。
但无论我是上面写v_storeid520 <>1还是v_storeid520 !=1,似乎都不起作用,还是执行了update。求各位接惑啊

oracle存储过程中的if条件判断的写法:
比如:
temp varchar2(10) := \'10000\';
if temp <> \'10000\' then
insert into ...
else
update .......

end if;
参考技术A 用plsql developer调试下,看看v_storeid520的值是多少,有没有执行update;
或者在 if then end if; 中加上dbms_output打印下,例如:
if v_storeid520 <>1 then
v_sql := 'update ' || v_userinfo.aorgalias ||
'.tab520 t set t.nbyj=''' || v_nbyj ||
''' Where t.StoreID = '||v_storeid520||' ';
execute immediate v_sql;
dbms_output.putline('执行update语句,语句SQL:||v_sql||chr(10)||变量v_storeid520的值为'||v_storeid520);
end if;本回答被提问者采纳
参考技术B 应该是这样写 的啊,哪你调试一下,看到底v_storeid520等于几。就知道是怎么回事了

设置变量等于 if 语句条件

【中文标题】设置变量等于 if 语句条件【英文标题】:Setting variable equal to if statement condition 【发布时间】:2018-12-15 15:44:07 【问题描述】:

我有一个 if 语句,用于检查数组元素是否与局部变量匹配。

 if pinArray.contains(where: $0.title == restaurantName)

如何创建这个元素的变量? 我试过了

 let thePin = pinArray.contains(where: $0.title == restaurantName) 

但这带有“无法将布尔值转换为 MKAnnotation”。

我也尝试了

的变体
let pins = [pinArray.indexPath.row]
let pinn = pins(where: pin.title == restaurantName) (or close to it)

mapp.selectAnnotation(thePin as! MKAnnotation, animated: true)

无济于事。我缺少什么基本步骤?

【问题讨论】:

如果你真的有if pinArray.contains(where: $0.title == restaurantName) // some stuff 这样的代码,那么你绝对可以用let thePin = pinArray.contains(where: $0.title == restaurantName)替换它,然后是if thePin // some stuff 是否在更新中看到任何导致信号 sibart 的内容? 请勿发布代码图片。以文本形式发布代码。 您为什么要强制将Bool 强制转换为MKAnnotationthePin 是一个Bool,表示数组是否包含该值。 我试图创建一个等于 pinArray 的 pin 的变量,该 pinArray 等于/具有与 restaurantName 相同的标题。 【参考方案1】:

contains(where:) 返回一个 Bool 指示是否找到匹配项。它不返回匹配的值。

所以thePinBool,然后您尝试将其强制转换为MKAnnotation,这当然会崩溃。

如果您想要匹配值,请将代码更改为:

if let thePin = pinArray.first(where:  $0.title == restaurantName ) 
    do 
        mapp.selectionAnnotation(thePin, animated: true)
     catch 
    
 else 
    // no match in the array

根本不需要contains。无需转换(假设pinArrayMKAnnotation 的数组)。

【讨论】:

我不得不问,你在几个项目中都帮助了我 - 谢谢,哈哈 - 但是你是怎么知道这么多的?另外,在 if let 语句中,“first”指的是第一个匹配 restaurantName 的元素? 是的,这是第一场比赛。请参阅first(where:) 的文档。我从 1979 年就开始编程了。

以上是关于oracle储存过程中,if条件为某变量不等于1,怎么写的主要内容,如果未能解决你的问题,请参考以下文章

oracleif判断语句

oracle 存储过程里的if else

c# if 不等于 怎么写?

Oracle 函数

oracle if 后可以给多个条件不?

Oracle存储过程——日常记录