Oracle SQL Parser
this is an oracle sql parser. ref: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf
supported statement
statement | sub statement | yacc | ast |
---|---|---|---|
Alter table | Add column | ||
Alter table | Modify column | ||
Alter table | Drop column | ||
Alter table | Rename column | ||
Alter table | Add constraint | ||
Alter table | Modify constraint | ||
Alter table | Rename constraint | ||
Alter table | Drop constraint | ||
Create table | Relational table | ||
Create index | Relational table | ||
Drop table | - | ||
Drop index | - |
usage
package main
import (
"fmt"
"github.com/sjjian/oracle-sql-parser"
"github.com/sjjian/oracle-sql-parser/ast"
)
func main() {
stmts, err := parser.Parser("alter table db1.t1 add (id number, name varchar2(255))")
if err != nil {
fmt.Println(err)
return
}
stmt := stmts[0]
switch s := stmt.(type) {
case *ast.AlterTableStmt:
fmt.Println(s.TableName.Table.Value) // t1
}
}