SQL查询中的游标值
I have two tables
1.
shiv_tab_col
TABLENAME | COLUMNNAME
--------------------------
SER_SHIV_SYN | TABLENAME
SER_SHIV_SYN | COLUMNNAME
AND SER_SHIV_SYN
TABLENAME | COLUMNNAME
--------------------------
A | B
E | NULL
NULL | NULL
NULL | NULL
NULL | NULL
NULL | NULL
BUT WHEN I M TRYING TO RUN THE BELOW CODE IT IS GIVING ME '0' AS VALUE OF TNAME
DECLARE
tname varchar(20):=null;
CURSOR C1 IS
SELECT *
FROM SHIV_TAB_COL;
BEGIN
for rec in C1
loop
select count(*) into tname from (select nvl(rec.columnname,1)b from ser_shiv_syn) where b ='1';
dbms_output.put_line(tname);
dbms_output.put_line(rec.columnname);
END LOOP;
END;
其实我想数数。每列中的空值将存储在变量 TNAME
对于第一列,它应该给出 4
对于 2 列,它应该给出 5
I have two tables
1.
shiv_tab_col
TABLENAME | COLUMNNAME
--------------------------
SER_SHIV_SYN | TABLENAME
SER_SHIV_SYN | COLUMNNAME
AND SER_SHIV_SYN
TABLENAME | COLUMNNAME
--------------------------
A | B
E | NULL
NULL | NULL
NULL | NULL
NULL | NULL
NULL | NULL
BUT WHEN I M TRYING TO RUN THE BELOW CODE IT IS GIVING ME '0' AS VALUE OF TNAME
DECLARE
tname varchar(20):=null;
CURSOR C1 IS
SELECT *
FROM SHIV_TAB_COL;
BEGIN
for rec in C1
loop
select count(*) into tname from (select nvl(rec.columnname,1)b from ser_shiv_syn) where b ='1';
dbms_output.put_line(tname);
dbms_output.put_line(rec.columnname);
END LOOP;
END;
Actually i m looking to count the no. of null values in each column which will be stored in variable TNAME
for first column it should give 4
for 2 column it should give 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个小提示:对于您的光标,请使用此:
而不是 shiv_tab_col。
该表会自动更新并且始终存在。
它还具有字段类型、大小等。一切皆为 0 成本。双赢。
Just a small hint: For your cursor use this:
Instead of shiv_tab_col.
This table is automatically updated and it's always in there.
It also has field type, size, etc. Everything and more for 0 cost. Win-Win.
您现在要做的是计算表
shiv_tab_col
中列COLUMNNAME
的所有空出现次数。哪个是 0(你已经发现了)。解决方案有点复杂,你需要动态SQL来完成你想做的事情:
What you are doing now is counting all empty occurrences of the column
COLUMNNAME
in the tableshiv_tab_col
. Which is 0 (you already found that out).The solution is a bit more complicated, you need dynamic SQL to accomplish what you want to do: