I need a Stored Procedure that reads a text file and give the text as output;
I have one in MS SQL that works well; can anyone help in converting that into MySQL Stored Procedure.
I will be passing the Full Path of the File as parameter.
I have one in MS SQL that works well; can anyone help in converting that into MySQL Stored Procedure.
I will be passing the Full Path of the File as parameter.
Code:
/****** Object: StoredProcedure [dbo].[readTextFile] Script Date: 08/06/2011 13:08:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[readTextFile]
@os_file_name NVARCHAR(256)
,@text_file NVARCHAR(MAX) OUTPUT
/* Reads a text file into @text_file */
AS
DECLARE @sql NVARCHAR(MAX)
, @parmsdeclare NVARCHAR(MAX)
SET NOCOUNT ON
SET @sql = 'select @text_file=(select * from openrowset (
bulk ''' + @os_file_name + '''
,SINGLE_CLOB) x
)'
SET @parmsdeclare = '@text_file NVARCHAR(max) OUTPUT'
EXEC sp_executesql @stmt = @sql
, @params = @parmsdeclare
, @text_file = @text_file OUTPUT
-- Example calling above proc
--DECLARE @t NVARCHAR(MAX)
--EXEC readTextFile 'c:\readMe.txt', @t output
GO