我使用SQLTools 1.5编写Oracle SQL脚本。我想将数据从Excel文件导入Oracle数据库。我该怎么做?
另外,如何将数据从Oracle数据库导出到Excel文件?
答案 0 :(得分:1)
SQL Tools支持将数据从Excel文件导入Oracle。您可以使用Oracle的SQL Developer从Excel文件中将数据导入数据库。
杰夫史密斯在他的blog post中解释了如何做到这一点
- 右键点击表格 - >导入数据
- 选择您的文件
- 记住标题!您的Excel文件是否有列标题?我们是否想将这些作为一行来对待?可能不是。默认 选项可以解决这个问题。
- 选择要导入的Excel列
- 告诉SQL Developer电子表格中的哪些列与Oracle表中的哪些列匹配。
- 点击“验证”按钮。修复任何错误。
- 一切看起来都合适!单击“完成”按钮。
- 验证导入查看新表数据
您也可以从SQL Developer反向执行,只需右键单击表&选择导出。
答案 1 :(得分:0)
检查一下,这可能有帮助
WebUtil:如何将Excel文件读入Oracle表单
https://sites.google.com/site/craigsoraclestuff/oracle-forms-webutil/read-excel-into-forms
答案 2 :(得分:0)
Below sniplet works...
Imports Oracle.DataAccess.Client
Imports System.Configuration
Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel
Module Module1
Sub Main()
Dim dt As New DataTable
Dim connString = ConfigurationManager.ConnectionStrings("oraConnectionString").ConnectionString
Using conn As New OracleConnection(connString)
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = "select Doc_name,Doc_id from Document;"
conn.Open()
Using oda As New OracleDataAdapter(cmd.CommandText, conn)
oda.Fill(dt)
End Using
conn.Close()
End Using
'exportTOExcel
savetoXcel(dt, dt.Rows.Count)
End Sub
Private Sub savetoXcel(dt As DataTable, rows As Int64)
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = True
' Add a new workbook.
wbXl = appXL.Workbooks.Add
shXL = wbXl.ActiveSheet
' Add table headers going cell by cell.
shXL.Cells(1, 1).Value = "Document ID"
shXL.Cells(1, 2).Value = "Document Name"
Console.WriteLine("rows:" + rows.ToString)
' Format A1:D1 as bold, vertical alignment = center.
With shXL.Range("A1", "B1")
.Font.Bold = True
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
End With
' Create an array to set multiple values at once.
Dim students(rows, 2) As String
Dim i As Int32 = 0
For Each Dr As DataRow In dt.Rows
students(i, 0) = Dr.Item(0)
students(i, 1) = Dr.Item(1)
i = i + 1
Next
Dim BRange As String = "B" + rows.ToString
'Console.WriteLine("BRange:" + BRange)
shXL.Range("A2", BRange).Value = students
'AutoFit columns A:D.
raXL = shXL.Range("A1", "B1")
raXL.EntireColumn.AutoFit()
' Make sure Excel is visible and give the user control
' of Excel's lifetime.
appXL.Visible = True
appXL.UserControl = True
'Export to excel
wbXl.SaveAs(Filename:="d:\Db_report.xls", FileFormat:=50, ReadOnlyRecommended:=True)
' Release object references.
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
Exit Sub
End Sub
End Module