counting number of lines of a text file in a stored procedure
I need to open and count the number of lines in a text file using a stored 开发者_开发技巧procedure. The stored procedure should return a value whenever executed. Can you help me?
In Sybase it is simple.
EXEC @LineCount = xp_cmdshell(unix_command)
(Your DBA might have to fiddle around a tiny bit if they have not set the XP server up, but it comes on the CD, is fully documented, very easy (for a DBA), etc.)
The Unix command is of course word count, with the -line operator (indicating you want a count of lines):
santosh$ wc -l file_name
MS is identical, at least the last time I used it. But the issue there is, getting the line count on the MS-DOS side. If you have Cygwin or similar then use the Unix command.
精彩评论