我创建了一个for循环,循环直到它达到10并且每次碰到6或8时输出INSERT现在我想在每次碰到6或8时在结果列中插入一个空值。我怎么能这样做?
declare var1 number := 0;
begin
loop exit when var1 > 10;
if var1 IN (6,8) THEN dbms_output.put_line(' INSERT'); ELSE
dbms_output.put_line(var1);
end if;
var1 := var1 + 1;
end loop;
dbms_output.put_line('Done');
end;
/
表
SQL> describe messages
Name Null? Type
----------------------------------------- -------- ----------------------------
RESULTS VARCHAR2(60)
答案 0 :(得分:0)
在dbms_output.put_line(' INSERT');
之后
写下你的插入语句。
然后决定是自动提交,还是最后手动提交。
答案 1 :(得分:0)
SQL> describe messages
Name Null? Type
---------------------------------------- -------- ----------------------------
RESULTS VARCHAR2(60)
SQL> SELECT COUNT(*) FROM messages;
COUNT(*)
----------
0
SQL> SELECT * FROM messages;
no rows selected
SQL> get a.sql
1 DECLARE
2 var1 NUMBER := 0;
3 BEGIN
4 LOOP
5 EXIT WHEN var1 > 10;
6 IF var1 IN (6,8) THEN
7 DBMS_OUTPUT.PUT_LINE(' INSERT');
8 INSERT INTO messages VALUES (NULL);
9 ELSE
10 DBMS_OUTPUT.PUT_LINE(var1);
11 END IF;
12 var1 := var1 + 1;
13 END LOOP;
14 DBMS_OUTPUT.PUT_LINE('Done.');
15* END;
16
17 /
0
1
2
3
4
5
INSERT
7
INSERT
9
10
Done.
PL/SQL procedure successfully completed.
SQL> SELECT COUNT(*) FROM messages;
COUNT(*)
----------
2
SQL> SELECT * FROM messages;
RESULTS
------------------------------------------------------------
SQL>