循环到游标,直到 Oracle 中的每个 IF ELSE 为真
LOOP into cursor until each IF ELSE true in oracle
我写了一个cursor
,我想在其中循环每一列,直到它变为真。因此,如果所有 IF 语句都匹配为真,那么我想将数据插入 VALID
table 或者最后我想将不正确的数据插入 INVALID
TABLE。
下面是光标。请让我知道我的步骤是否准确,或者我是否需要对此进行任何更改。
create or replace procedure fiber_transm_valid_data as
begin
for cur_r in (select rj_span_id,
rj_maintenance_zone_name,
rj_maintenance_zone_code
from app_fttx.transmedia@sat
)
loop
if cur_r.rj_span_id > '0' then
elsif cur_r.rj_maintenance_zone_name = 'aa' then
elsif cur_r.rj_maintenance_zone_code = 'A123' then
INSERT INTO VALID TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values (cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
ELSE
INSERT INTO INVALID TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values (cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
end loop;
end fiber_transm_valid_data;
不太像; IF
是错误的。看看这个。
create or replace procedure fiber_transm_valid_data as
l_state_name table_of_states.rj_state_name%type;
begin
for cur_r in (select rj_span_id,
rj_maintenance_zone_name,
rj_maintenance_zone_code,
rj_state_name
from app_fttx.transmedia@sat
)
loop
select max(rj_state_name)
into l_state_name
from table_of_states
where rj_state_name = cur_r.rj_state_name
and rownum = 1;
if cur_r.rj_span_id > '0'
and cur_r.rj_maintenance_zone_name = 'aa'
and cur_r.rj_maintenance_zone_code = 'A123'
and l_state_name = 1
then
INSERT INTO VALID_TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values
(cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
else
INSERT INTO INVALID_TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values
(cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
end if;
end loop;
end fiber_transm_valid_data;
我写了一个cursor
,我想在其中循环每一列,直到它变为真。因此,如果所有 IF 语句都匹配为真,那么我想将数据插入 VALID
table 或者最后我想将不正确的数据插入 INVALID
TABLE。
下面是光标。请让我知道我的步骤是否准确,或者我是否需要对此进行任何更改。
create or replace procedure fiber_transm_valid_data as
begin
for cur_r in (select rj_span_id,
rj_maintenance_zone_name,
rj_maintenance_zone_code
from app_fttx.transmedia@sat
)
loop
if cur_r.rj_span_id > '0' then
elsif cur_r.rj_maintenance_zone_name = 'aa' then
elsif cur_r.rj_maintenance_zone_code = 'A123' then
INSERT INTO VALID TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values (cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
ELSE
INSERT INTO INVALID TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values (cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
end loop;
end fiber_transm_valid_data;
不太像; IF
是错误的。看看这个。
create or replace procedure fiber_transm_valid_data as
l_state_name table_of_states.rj_state_name%type;
begin
for cur_r in (select rj_span_id,
rj_maintenance_zone_name,
rj_maintenance_zone_code,
rj_state_name
from app_fttx.transmedia@sat
)
loop
select max(rj_state_name)
into l_state_name
from table_of_states
where rj_state_name = cur_r.rj_state_name
and rownum = 1;
if cur_r.rj_span_id > '0'
and cur_r.rj_maintenance_zone_name = 'aa'
and cur_r.rj_maintenance_zone_code = 'A123'
and l_state_name = 1
then
INSERT INTO VALID_TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values
(cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
else
INSERT INTO INVALID_TABLE
(span_id, maintenance_zone_name,rj_maintenance_zone_code)
values
(cur_r.rj_span_id, cur_r.rj_maintenance_zone_name, cur_r.rj_maintenance_zone_code);
end if;
end loop;
end fiber_transm_valid_data;