VBA从Excel中生成Oracle create table

有时会碰到Oracle设计文档用Excel,需要根据Excel生成create table语句。当表多,列多,设计变更时,这个VBA小函数就能节省很多时间。在google, baidu搜了一圈,没有找到类似的。写出来方便自己也方便他人。

假设:
Sheet名字为表名
第一行作为Excel表格表头
第一列为列名
第二列null 约束
第三列数据类型

目前还不支持分区语法

Private Sub Worksheet_Activate()
    Dim ddl As String
    Dim i As Integer
    ddl = "Create table " + Sheet1.Name + " ("
    'MsgBox (Sheet1.Range("A" & 2).Value)
    For i = 2 To 27
        ddl = ddl + Sheet1.Range("A" & i).Value + " "         'Column name
        ddl = ddl + Sheet1.Range("C" & i).Value + " "              'Data type
        If Sheet1.Range("B" & i).Value = "N" Then
            ddl = ddl + "not null"
        End If
        ddl = ddl + ","
    Next i
    ddl = Left(ddl, Len(ddl) - 1) + ");"
    'Write the DDL to Sheet11
    Sheet11.Range("A2").Value = Sheet1.Name
    Sheet11.Range("B2").Value = ddl
End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值