Oracle循環語句的寫法有哪些呢
如果您對Oracle循環語句方面感興趣的話,不妨一看。
loop循環: 1。 create or replace procedure pro_test_loop is 2。
i number; 3。 begin 4。
i:=0; 5。 loop 6。
ii:=i+1; 7。 dbms_output。
put_line(i); 8。 if i》5 then 9。
exit; 10。 end if; 11。
end loop; 12。 end pro_test_loop; while循環: 1。
create or replace procedure pro_test_while is 2。 i number; 3。
begin 4。 i:=0; 5。
while i《5 loop 6。 ii:=i+1; 7。
dbms_output。 put_line(i); 8。
end loop; 9。 end pro_test_while; for循環1: 1。
create or replace procedure pro_test_for is 2。 i number; 3。
begin 4。 i:=0; 5。
for i in 1。
5 loop 6。 dbms_output。
put_line(i); 7。 end loop; 8。
end pro_test_for; for循環2: 1。 create or replace procedure pro_test_cursor is 2。
userRow t_user%rowtype; 3。 cursor userRows is 4。
select * from t_user; 5。 begin 6。
for userRow in userRows loop 7。 dbms_output。
put_line(userRow。Id||','||userRow。
Name||','||userRows%rowcount); 8。 end loop; 9。
end pro_test_cursor;。
請問這個oracle的for循環語句怎么寫
create table temp_tab( id number primary key not null, name varchar2(50) not null, age number not null);declare ids number(30) :=0; names varchar2(50) :='卡卡'; age number(30) :=5;begin for i in 1..15 loop ids :=ids+1; age :=age+1; insert into temp_tab values(ids,names,age); end loop;end;。
Oracle中循環語句的幾種用法
--* FOR <循環變量> IN [REVERSE] <下界..上界> LOOP <語句組> END LOOP; --計算5的階乘,并在屏幕上打印出來。
DECLARE num NUMBER(3):=5; resu NUMBER(3):=1; BEGIN for i in 1..num loop resu:= resu * i; end loop; dbms_*_line(TO_CHAR(resu)); END;--*循環語法格式: WHILE <條件> LOOP <語句組> END LOOP; --用WHILE循環求1~100所有整數的和 DECLARE summ number :=0; i number(3):=100;BEGIN WHILE i>0 LOOP summ:=summ+i; i:=i - 1; END LOOP; dbms_*_line(summ);END;。
oracle 循環語句的問題
劃分區域的表有么?
應該建立一張劃分區域的表,表內表名經度和緯度的邊界,我舉個例子(僅為舉例,具體邊界自己掌握),假設你定義緯度為南緯10°到北緯10°,東經10°到西經10°為一個區域,那么再這張表中,至少要有這些邊界數據,另外還要有區域編號等內容。(具體內容自己考慮,可能還需要其他內容)
然后另外一張表中,只要判斷大于小于就好了,假設一個坐標為北緯5°,東經7°,那么就是在這個區域內。這塊就是兩次截取+判斷(不能只判斷小于,也要判斷大于,這里就是大于0,小于10,其他還有大于10,小于20之類的,也可以加入北緯,東經等判斷字樣,這個就要看你表的設置了),前面輸出的是在已經建立的邊界表的區域編號就可以了,不需要循環。
用循環做,那么就不用建立這張表,但是如果這樣的話,別人會不知道你的區域表示的是什么,你還要挨個解釋,不是很麻煩。
個人考慮區域劃分表的內容(考慮不把東西經南北緯放在一起,與上面的例子有所不同)
區域編號 東西經 南北緯 最低緯度 最高緯度 最低經度 最高經度
1 東經 北緯 0 20 0 20
都是這樣的內容,然后你在表中存儲的是東經15度,北緯5度。
那么就可以通過substr截取,東西經和南北緯相等,在最低和最高之間,那么就顯示區域編號,只是截取的次數多了一點。
請教大神,oracle數據庫循環語句怎么寫
假設表中字段分別為:student 中字段:class_id, student_name,score,pass(number類型)class中字段:class_id,class_nameselect *_name,count(*) total ,sum(pass) as pass_count,sum(pass)/count(*) as pass_ratiofrom student s,class cwhere *_id=*_idgroup by *_name。
請問這個oracle的for循環語句怎么寫
create table temp_tab
(
id number primary key not null,
name varchar2(50) not null,
age number not null
);
declare
ids number(30) :=0;
names varchar2(50) :='卡卡';
age number(30) :=5;
begin
for i in 1..15 loop
ids :=ids+1;
age :=age+1;
insert into temp_tab values(ids,names,age);
end loop;
end;
oracle的幾種循環示例
--* FOR <;循環變量> IN [REVERSE] <;下界..上界> LOOP <;語句組> END LOOP; --計算5的階乘,并在屏幕上打印出來。 DECLARE num NUMBER(3):=5; resu NUMBER(3):=1; BEGIN for i in 1..num loop resu:= resu * i; end loop; dbms_*_line(TO_CHAR(resu)); END;
--*循環語法格式: WHILE <;條件> LOOP <;語句組> END LOOP; --用WHILE循環求1~100所有整數的和 DECLARE summ number :=0; i number(3):=100;BEGIN WHILE i>0 LOOP summ:=summ+i; i:=i - 1; END LOOP; dbms_*_line(summ);END;
oracle循環排序語句
sqlserver或者oracle如下:
創建表,數據:
create table t(id int,star int) insert into t values (1,1)insert into t values (2,3)insert into t values (3,5)insert into t values (4,2)insert into t values (5,2)insert into t values (6,1)insert into t values (7,5)insert into t values (8,4)insert into t values (9,2)insert into t values (10,2)insert into t values (11,3)insert into t values (12,3)insert into t values (13,4)
執行:
select id,star from(select t.*,row_number() over (partition by star order by id) rn from t) tmporder by rn,star
結果大概這個樣子:
其他數據庫另說,就沒這么簡單了。
轉載請注明出處華閱文章網 » oracle的循環語句