我已经返回一个程序,它将检查哪个文件存在与否,它将检查列
的否create or replace procedure chkcsvfile
(P_UTLDIR VARCHAR2,
P_FILENAME VARCHAR2,
P_tabnam VARCHAR2
)
is
P_fieldel varchar2(2):= ',';
V1 VARCHAR2(32767) ;
P_errlen number :=0;
lv_a number;
lv_b number;
lv_c number;
lv_d number;
lv_check_file_exist boolean;
v_file utl_file.file_type;
cursor c1 is
select count(*) from user_tables where TABLE_NAME =P_tabnam;
cursor c2 is
select count(*) from user_tab_columns where TABLE_NAME =P_tabnam;
begin
open c1;
fetch c1 into lv_c;
if lv_c = 0 then
dbms_output.put_line('table name is invalid : ' || P_tabnam);
end if;
--'test wheather file is available or not'
dbms_output.put_line ('test wheather file is available or not');
utl_file.fgetattr (P_UTLDIR,P_FILENAME, lv_check_file_exist, lv_a, lv_b );
if lv_check_file_exist then
dbms_output.put_line('file ' ||P_FILENAME ||' exists');
v_file := utl_file.fopen(P_UTLDIR,P_FILENAME, 'R');
UTL_FILE.get_line (v_file ,V1,32767);
DBMS_OUTPUT.put_line ('V1 :' || V1);
if (REGEXP_like (V1, ',',1))
then
P_errlen := P_errlen +1 ;
dbms_output.put_line ('errrooooooooooooooooooooooooooooooooooorr');
dbms_output.put_line (P_errlen );
end if;
end if;
if not lv_check_file_exist then
dbms_output.put_line('file ' || P_FILENAME ||' does not exist');
end if;
if lv_check_file_exist is null then
dbms_output.put_line('file check null');
end if;
if lv_check_file_exist is not null then
dbms_output.put_line('file check not null');
end if;
dbms_output.put_line('lv_a-->'||lv_a);
dbms_output.put_line('lv_b-->'||lv_b);
open c2;
fetch c2 into lv_d;
dbms_output.put_line ('No of columns in a table : ' || lv_d );
end;
/
现在我的问题是我必须在一个字符串中匹配“,”并且我想要它的计数。我写了这个程序,但它没有给我具体的计数。
字符串中的数据以下面的格式
给出7839,KING ,PRESIDENT,0000,17-nov-1981, 005000.00 ,000000.00,10,
请帮帮我 提前谢谢
答案 0 :(得分:2)
由于您使用的是11g,因此可以使用regexp_count功能。
select regexp_count('7839,KING ,PRESIDENT,0000,17-nov-1981, 005000.00 ,000000.00,10,',',')
from dual