declare
va_id es_product.id%type:= &請輸入購買編號;
va_num number(5,0):=&請輸入購買數量;
va_stockcount es_product.stockcount%type;
begin
select stockcount into va_stockcount from es_product where id =va_id ;
if va_stockcount< va_num then
dbms_output.put_line('庫存'+va_stockcount+'無法購買');
end if;
commit;
end;
----------------------------
declare
va_id es_order.id%type:= &請輸入訂單編號;
status2 es_order.status%type;
begin
select status into status2 from es_order where id=1;
case status2
when 1 then
dbms_output.put_line('訂單已提交');
when 2 then
dbms_output.put_line('已經付款');
when 3 then
dbms_output.put_line('貨物已發出');
else
dbms_output.put_line('nnn');
end case;
end;
declare
va_id es_order.id%type:= &請輸入訂單編號;
status2 es_order.status%type;
begin
select status into status2 from es_order where id=1;
if status2=1 then
dbms_output.put_line('訂單已提交');
else if status2=2 then
dbms_output.put_line('已經付款');
else
dbms_output.put_line('nnn');
end if;
end;
declare
va_num number(5,0):=0;
va_sum number(5,0):=0;
begin
loop
if va_num <=100 then
dbms_output.put_line(va_num);
end if;
va_sum:=va_num+1;
exit va_num > 100;
end loop;
dbms_output.put_line('zh'+va_sum);
end;
declare
va_num number(5):=0;
va_sum number(5):=0;
begin
while va_num<=100 loop
va_sum:=va_sum+va_num;
va_num:=va_num+1;
end loop;
dbms_output.put_line(va_sum);
end;
declare
va_sum number(5):=0;
begin
for va_num in 1..100 loop
va_sum:=va_sum+va_num;
end loop;
dbms_output.put_line('hh:'||va_sum);
end;
declare
va_num number(5):=0;
va_sum number(5):=0;
begin
loop
va_sum:=va_sum+va_num;
va_num:=va_num+1;
exit when va_num>100;
end loop;
dbms_output.put_line('hh:'||va_sum);
end;
declare
va_sum number(5):=0;
begin
for va_num in 1..100 loop
if mod(va_num,2)=0 then
va_sum:=va_sum+va_num;
end if;
end loop;
dbms_output.put_line(va_sum);
end;
declare
begin
for va_num in 5..7 loop
insert into es_sort values(va_num,'類別'||va_num,0);
end loop;
commit;
end;
package com.test;
public class demo1
public static void method1()
system.out.println("1到100累加的和為:" + sum);
}public static void method2()
system.out.println("1到100累加的和為:" + sum);
}public static void method3() while (i <= 100);
system.out.println("1到100累加的和為:" + sum);}}
declare
pid number(10):=&請輸入商品id;
stockcount number(12);
pname varchar2(16);
begin
select name,stockcount into pname,stockcount from es_product where id=pid;
dbms_output.put_line('商品名稱:'||pname||' 庫存:'||stockcount);
end;
declare
pid number(10):=&請輸入商品id;
stockcount es_product.stockcount%type;
pname es_product.name%type;
begin
select name,stockcount into pname,stockcount from es_product where id=pid;
dbms_output.put_line('商品名稱:'||pname||' 庫存:'||stockcount);
end;
declare
pid number(10):=&請輸入商品id;
resultji es_product%rowtype;
begin
select name ,stockcount into resultji from es_product where id=pid;
dbms_output.put_line('商品名稱:'||resultji.name||' 庫存:'||resultji.stockcount);
end;
Oracle條件語句
條件語句主要作用是根據條件的變化選擇執行不同的 例項 指定乙個月份數值,然後使用if.then.elsif語句判斷它所屬的季節,並輸出季節資訊。declare month int 10 定義整型變數並賦值 begin if month 0 and month 3 then 判斷春季 dbms out...
Oracle條件查詢
條件查詢 關係運算子 邏輯運算子 and or not 其他運算子 like 模糊查詢 in set 在某個區間內 between and.在某個區間內 is not 判斷為空 is not null 判斷不為空 查詢每月能得到獎金的員工資訊 select from emp select from ...
條件分支結構
一 條件分支結構 if else if分支語句 1 if判斷 if 條件語句 2 if else分支 if 條件語句 else 3 if else if分支 if 條件語句1 else if 條件語句2 elseelse else switch分支 switch a 注意 1 值不能重複,值的型別和...