--------------------------------------------------------------------
-- Load an O/S file into a MySql table
--------------------------------------------------------------------
truncate table output;
/
drop procedure read_file
/
create procedure read_file(p_file_name varchar(64)) 
begin
-- ===============================
-- Param: p_file_name varchar(64)
-- ===============================
      declare v_file 	 text; 
      declare v_line 	 varchar(500);
      declare v_newline  char(1) default char(10);		-- Unix newline char, PC char(13)char(10)
      declare v_line_beg int default 1;
      declare v_line_end int default 1;
      declare v_line_len int;  

      set v_file     = load_file(p_file_name);				 
      set v_file     = replace(v_file,'<','<');		-- load the file from O/S

      WHILE  v_line_end < length(v_file) DO
	 set v_line_end = locate(v_newline, v_file, v_line_beg);
         set v_line_len = v_line_end - v_line_beg; 
         set v_line     = substring(v_file, v_line_beg, v_line_len); 
         insert into output values(v_line); 
         set v_line_beg = v_line_end + 1;
      END WHILE;
end;

/
call read_file('/etc/passwd');
--call read_file('/home/sultans/web/index.html');  
/

select * from output