英文:
Oracle plsql syntax confusion?
问题
declare
v_name varchar2(10) := 'bruce';
v_name2 number;
begin
case v_name
when 'bruce' then DBMS_OUTPUT.PUT_LINE('corr');
else DBMS_OUTPUT.PUT_LINE('incorrect');
end case;
DBMS_OUTPUT.PUT_LINE(v_name2);
end;
declare
v_name varchar2(10) := 'bruce';
num number(2) := 10;
begin
num := case v_name
when 'bruce' then 2
else 12
end;
DBMS_OUTPUT.PUT_LINE(num);
end;
Getting confuse about semi colons. why in first code semicolon required and end case; keyword needed. But in 2nd code no semicolon & also just end; I know in 2nd I am assigning value to variable, but so what ?
英文:
declare
v_name varchar2(10) := 'bruce';
v_name2 number;
begin
case v_name
when 'bruce' then DBMS_OUTPUT.PUT_LINE('corr');
else DBMS_OUTPUT.PUT_LINE('incorrect');
end case;
DBMS_OUTPUT.PUT_LINE(v_name2);
end;
declare
v_name varchar2(10) := 'bruce';
num number(2) := 10;
begin
num := case v_name
when 'bruce' then 2
else 12
end;
DBMS_OUTPUT.PUT_LINE(num);
end;
Getting confuse about semi colons. why in first code semicolon required and end case; keyword needed. But in 2nd code no semicolon & also just end; I know in 2nd I am assigning value to variable, but so what ?
答案1
得分: 6
case statement vs. case expression.
case statement 用于条件执行 PL/SQL 代码:
case v_name
when 'bruce' then DBMS_OUTPUT.PUT_LINE('corr');
else DBMS_OUTPUT.PUT_LINE('incorrect');
end case;
case expression 可以在 PL/SQL 和常规 SQL 中使用,返回一个值:
num := case v_name
when 'bruce' then 2
else 12
end;
英文:
case statement vs. case expression.
The case statement is for conditional execution of PL/SQL code:
case v_name
when 'bruce' then DBMS_OUTPUT.PUT_LINE('corr');
else DBMS_OUTPUT.PUT_LINE('incorrect');
end case;
The case expression can be used both in PL/SQL and in regular SQL, and returns a value:
num := case v_name
when 'bruce' then 2
else 12
end;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论