SELECT INTO ステートメント
SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。
SQL クエリを使ったデータのエクスポート
次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。
C#
String connectionString = "Api Key=MyAPIKey;";
using (IBMCloudSQLQueryConnection connection = new IBMCloudSQLQueryConnection(connectionString)) {
IBMCloudSQLQueryCommand cmd = new IBMCloudSQLQueryCommand("SELECT Id, Status INTO [csv://[CloudObjectStorage_1].[SampleBucket_1].Jobs.txt] FROM [[CloudObjectStorage_1].[SampleBucket_1].Jobs] WHERE UserId = '[email protected]' ", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "Api Key=MyAPIKey;"
Using connection As New IBMCloudSQLQueryConnection(connectionString)
Dim cmd As New IBMCloudSQLQueryCommand("SELECT Id, Status INTO [csv://[CloudObjectStorage_1].[SampleBucket_1].Jobs.txt] FROM [[CloudObjectStorage_1].[SampleBucket_1].Jobs] WHERE UserId = '[email protected]'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。
C#
String connectionString = "Api Key=MyAPIKey;";
using (IBMCloudSQLQueryConnection connection = new IBMCloudSQLQueryConnection(connectionString)) {
IBMCloudSQLQueryCommand cmd = new IBMCloudSQLQueryCommand("SELECT * INTO [[CloudObjectStorage_1].[SampleBucket_1].Jobs] IN [csv://filename=c:/[CloudObjectStorage_1].[SampleBucket_1].Jobs.csv;delimiter=tab] FROM [[CloudObjectStorage_1].[SampleBucket_1].Jobs] WHERE UserId = '[email protected]'", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "Api Key=MyAPIKey;"
Using connection As New IBMCloudSQLQueryConnection(connectionString)
Dim cmd As New IBMCloudSQLQueryCommand("SELECT * INTO [[CloudObjectStorage_1].[SampleBucket_1].Jobs] IN [csv://filename=c:/[CloudObjectStorage_1].[SampleBucket_1].Jobs.csv;delimiter=tab] FROM [[CloudObjectStorage_1].[SampleBucket_1].Jobs] WHERE UserId = '[email protected]'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using