我可以在存储过程中使用spool命令并从VB代码执行存储过程吗? [英] Can I use spool command in stored procedure and execute stored procedure from VB code?
问题描述
我是SQL开发人员的新手
我的要求是在txt文件中存储数百万条记录
首先我尝试通过VB.net执行spool命令而不是成功所以我试图用spool命令创建一个存储过程并从VB代码执行
我尝试过:
使用mOracleConnection作为新的OracleConnection(mConnectionString)
mOracleConnection.Open()
Dim mOracleCommand as OracleCommand
Dim mOracleDataReader作为OracleDataReader
mOracleCommand = mOracleConnection.CreateCommand()
mOracleCommand.CommandType = CommandType.Text
mOracleCommand.CommandText = GetStrSQL ()
mOracleCommand.ExecuteNonQuery()
结束使用
Private Sub GetStrSQL()AS String
Dim mStrSQL AS新的StringBuilder
使用mStrSQl
.AppendLine(spool D:\30Aug\Testing .txt)
.AppendLine(SELECT * FROM [Payroll.Payslip] .Payslip WHERE PayslipID> 1500; )
.AppendLine(假脱机)
结束
I am new to SQL developer
My requirement is to store million of records in txt file
So first I tried with executing spool command through VB.net and not succeeded so I am trying to create one store procedure with spool command and execute from VB code
What I have tried:
Using mOracleConnection As New OracleConnection(mConnectionString)
mOracleConnection.Open()
Dim mOracleCommand As OracleCommand
Dim mOracleDataReader As OracleDataReader
mOracleCommand = mOracleConnection.CreateCommand()
mOracleCommand.CommandType = CommandType.Text
mOracleCommand.CommandText = GetStrSQL()
mOracleCommand.ExecuteNonQuery()
End Using
Private Sub GetStrSQL() AS String
Dim mStrSQL AS New StringBuilder
With mStrSQl
.AppendLine(" spool D:\30Aug\Testing.txt ")
.AppendLine(" SELECT * FROM [Payroll.Payslip].Payslip WHERE PayslipID > 1500; ")
.AppendLine(" spool off ")
End With
推荐答案
Spool是一个被SQL开发人员识别的命令。当你使用ADO.NET命令时它不可用。
你有一些选择
- 使用SQL Developer或SQL * Plus将数据传递到文件中
- 使用ADO.NET循环遍历VB.NET中的结果集并为每行添加数据到文件中
- 使用存储过程将数据写入服务器端的文件中。为此,您可以使用UTL_FILE [ ^ ]
Spool is a command that is recognized by SQL developer. It is not available when you're working with ADO.NET commands.
Some options you have
- Spool the data into a file using SQL Developer or SQL*Plus
- Using ADO.NET loop through the result set in VB.NET and for each line append the data into a file
- Using a stored procedure write the data into a file on the server side. For this you can use UTL_FILE[^]
这篇关于我可以在存储过程中使用spool命令并从VB代码执行存储过程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!