我在表格中有一个字段,其中包含' SMITH,ALLEN,WARD,JONES'。我尝试使用游标从表中读取行,当找到此特定字段时,使用regexp_substr将','
作为分隔符进行拆分。
以下是代码:
PROCEDURE x26837a_dummy IS
CURSOR d_cursor IS
SELECT regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, level)
FROM x26837a_dummy_table
CONNECT BY regexp_substr('SMITH,ALLEN,WARD,JONES', '[^,]+', 1, 1) IS NOT NULL
lvar VARCHAR2(128) := '';
BEGIN
OPEN d_cursor;
LOOP
FETCH d_cursor
INTO lvar;
EXIT WHEN d_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(lvar);
END LOOP;
CLOSE d_cursor;
END x26837a_dummy;
我希望单独返回名称,因此在打印四个值后此光标应该退出,因为之后它返回空值。但是%NOTFOUND
条件不会退出循环并且它会保持循环。似乎无法弄清楚这个问题。
答案 0 :(得分:2)
所以问题是你的正则表达式没有终止。正如您所指出的那样,游标一直在使用null" name"。
来获取记录一种选择是更改测试以退出循环:
library(ggplot2)
theme_set(theme_bw())
sample <- data.frame(x = 1:10, y = 1:10)
# [Plot 1] Works fine using aes and stipulating variables
ggplot(sample, aes(x = x, y = y)) +
geom_point(aes(colour = ifelse(x < 3, 1, ifelse(x > 7, 10, x)))) +
scale_colour_identity()
# [Plot 2] "x" replaced by "var" and "aes" replaced by "aes_string"
var = "x"
ggplot(sample, aes(x = x, y = y)) +
geom_point(aes_string(colour = ifelse(var < 3, 1, ifelse(var > 7, 10, var)))) +
scale_colour_identity()
另一种选择是修复正则表达式。 if lvar is null then exit; end if;
子句应为:
CONNECT BY