Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 2-Sep-18 5:52am

1 solution

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[^]
 
Share this answer
 
Comments
navidshaikh0702 2-Sep-18 13:06pm    
Thanks for suggestion!!!
But thing is I can't iterate through each record as it is time consuming
So I am trying with making a stored procedure with spool command
Kindly suggest me how to execute this procedure
Wendelius 2-Sep-18 14:32pm    
What comes to the data handling there are two options. Either the procedure writes the data into a file on the server side or the data is returned to the client where it's written into the file by looping the record set.

If you want to write the data into a file inside the procedure then UTL_FILE package (see the link in the answer) is a common way to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900