为什么Oracle SQL Developer无法识别我的if语句 [英] Why won't oracle sql developer recognise my if statement

查看:150
本文介绍了为什么Oracle SQL Developer无法识别我的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用oracle SQL开发人员,并试图在其中运行带有if语句的查询.

I am using oracle SQL developer and am trying to run a query with an if statement in it.

我已经定义了一个变量并为其分配了一个值.

I have defined a variable and assigned a value to it.

define
var buyer varchar2(1)

/* define variable values */ 
exec :buyer := 'Yep'

if :buyer = 'Yep' then 
begin
dbms_output.put_line('Yep');
else 
dbms_output.put_line('Nope');
end;

但是,当我运行脚本时,收到一条错误消息,指出IF是未知命令.

However, when I run the script, I get an error message stating that IF is an unknown command.

从第8行开始的错误-
如果:buyer ='是',那么
错误报告-
未知命令

Error starting at line : 8 in command -
if :buyer = 'Yep' then
Error report -
Unknown Command

任何建议都将不胜感激.

Any advice is greatly appreciated.

推荐答案

您必须定义DECLARE-BEGIN-END块才能运行IF-ELSIF-ELSE-END条件. 根据您的示例代码,我假设这就是您想要做的.

You have to define a DECLARE-BEGIN-END block to run IF-ELSIF-ELSE-END conditions. Based on your sample code, I'm assuming this is what you would like to do.

DECLARE
  buyer VARCHAR2(3) := 'Yep';
BEGIN
  IF ( buyer = 'Yep' ) THEN
    dbms_output.put_line('Yep' );
  ELSE
    dbms_output.put_line('Nope');
  END IF;
END;
/

您可以在sql developer中将其作为脚本运行. HTH!

You could run this as a script in sql developer. HTH!

这篇关于为什么Oracle SQL Developer无法识别我的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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