0

二重引用符を含むデータを含むテキスト ファイルをインポートする必要があります。実際に、aix コマンドとその説明を含むテキスト ファイルを作成しました。

コマンドに二重引用符が含まれるようになりました。そのため、バルク データを SQL Server 2005 にインポートする通常の方法を使用すると、エラーが発生します。

私のテキストファイルは次のようなものです:

1,acledit "file",for changing the ACL(access control list) of a file
2,anacheck -ap,error analysing for Escala E + T
3,bsh,starts a born shell
4,cancel "print job number",for killing a print job
5,chgrp "group" "file",changes the group of a file
6,chitab "inittab statement",for disabling a statement of the /etc/inittab
7,chmod 0777 "file",gives everybody the right to read, write and execute the specified file
8,chown "user" "file",changes the owner of a file
9,compress -v "file",compresses a file
10,cplv,copies a logical volume (no mirroring)

このデータを SQL Server 2005 にそのままインポートする方法を教えてもらえますか?

4

2 に答える 2

0

オプションBULK INSERTで使用FIELDTERMINATOR

bulk insert [yourtablename] from 'yourfilepath' with (fieldterminator = ',')
于 2012-07-28T08:59:01.800 に答える
0

以下のような関数ScalarValued関数を使用して、他の文字にエンコードし、保存して、取得時にデコードすることができます。

    CREATE FUNCTION EncodeString 
     (@data as varchar(max))
      RETURNS varchar(max)AS 
     BEGIN
        DECLARE @result as varchar (max)
        SELECT @result = REPLACE(@data , '"','_')
        RETURN @result
      END

上記の関数は1,acledit _file_,for changing the ACL(access control list) of a file入力番号1を返します。の代わりに他のASCII/unicodeを使用できます。_さらに、関数の取得と検索に使用するデコード関数を作成する必要があります。これがお役に立てば幸いです。

于 2012-07-28T08:35:00.133 に答える