0

我正在使用 SQLTools 1.5 编写 Oracle SQL 脚本。我想将数据从 Excel 文件导入 Oracle 数据库。我该怎么做?

另外,如何将数据从 Oracle 数据库导出到 Excel 文件?

4

3 回答 3

1

SQL Tools 支持将数据从 Excel 文件导入 Oracle。您可以使用 Oracle 的 SQL Developer 将数据从 Excel 文件导入数据库。

杰夫史密斯在他的博客文章中解释了如何做到这一点

  • 右键单击表格 -> 导入数据
  • 选择您的文件
  • 注意标题!您的 Excel 文件是否有列标题?我们想把它们当作表格的一行吗?可能不是。默认选项会处理这个问题。
  • 选择要导入的 Excel 列
  • 告诉 SQL Developer 电子表格中的哪些列与 Oracle 表中的哪些列相匹配。
  • 点击“验证”按钮。修正任何错误。
  • 一切看起来都不错!单击“完成”按钮。
  • 验证导入查看您的新表数据

您也可以从 SQL Developer 执行相反的操作,只需右键单击表并选择导出。

于 2012-08-22T05:54:51.073 回答
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
于 2015-02-28T05:57:43.810 回答
0

检查这个,它可能会有所帮助

WebUtil:如何将 Excel 文件读入 Oracle 表单

https://sites.google.com/site/craigsoraclestuff/oracle-forms-webutil/read-excel-into-forms

于 2013-10-09T10:31:05.160 回答