Oracle過程語句

來源:互聯網
上載者:User

標籤:begin   注意   declare   sys   drop   插入資料   多列   條件   cas   

--過程語句
select * from wan3;
--三段式 先寫固定結構 declare begin end
declare
a varchar2 (6) :=‘ere‘;
begin
DELETE FROM wan3 WHERE ename=a;
end;

--
DECLARE
v_deptno NUMBER;
v_dname VARCHAR2(100);
BEGIN
INSERT INTO wan3
VALUES
(‘hfe‘,15,5411,sysdate,null,null);
END;

--條件陳述式 if case
--注意變數命名的類型問題
declare
v_ename varchar2 (6);
v_sal wan3.sal%type; --可以用已知類型的 關鍵字 %
begin
select name into v_ename from wan3 where name=‘jh‘;
dbms_output.put_line(‘輸出的名字是:‘||v_ename);
select sal into v_sal from wan3 where age=30;
--固定格式輸出 串連用||
dbms_output.put_line(v_ename||‘的工資是:‘||v_sal);
--if 用法
if v_sal <7000 then
dbms_output.put_line(v_ename||‘的工資小於8000‘);
else
dbms_output.put_line(v_ename||‘的工資是.自己更好:‘||v_sal);
end if ;

end ;

----條件陳述式 case
declare
v_sal number := 3000;
a varchar2(50) ;
begin
--給變數a 賦值 裡面是一個case運算式
a :=
case v_sal
when 5000 then ‘我的工資是5000‘
when 4500 then ‘我的工資是4500‘
else ‘沒有你的工資‘
end;
dbms_output.put_line(‘看都是不可個::‘||a);
end ;


--迴圈語句 loop exit when 是必須的 退出迴圈
declare
a number(3) :=0; --聲明變數並賦值
begin
loop --迴圈開始位置
a :=a+2;
dbms_output.put_line(‘a的當前值是:‘||a);
exit when a=10; --迴圈允出準則
end loop; --迴圈結束
end;

--while 迴圈
declare
a number(5) ;
begin
select sal into a from wan3 where age=30;
dbms_output.put_line(a);
while a<10000 --條件為真的時候才執行
loop
dbms_output.put_line(‘a的值是:‘||a);
a:=a+500;
end loop;
end;


--for迴圈語句
declare
a number(5) ;
begin
for a in reverse 1..3 loop --for 迴圈計數器 in 下限..上限 依次升高(如果加入reverse則減小)
insert into wan3 values (‘85fe‘,15,5411,sysdate,null,null); --插入資料
end loop;
end;


select * from wan;

delete from wan3 where age=15;
--同時刪除多列
alter table wan3 drop (kjj,age);
--重新命名列
alter table wan3 rename column sal to salll
--重新命名表名
rename wan3 to wan

 

Oracle過程語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.