{"id":244,"date":"2010-07-16T03:47:54","date_gmt":"2010-07-16T08:47:54","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?page_id=244"},"modified":"2010-07-16T03:57:33","modified_gmt":"2010-07-16T08:57:33","slug":"separate-the-sql-commands-in-a-sql-script","status":"publish","type":"page","link":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/separate-the-sql-commands-in-a-sql-script\/","title":{"rendered":"Separate the SQL Commands in a SQL script"},"content":{"rendered":"

Sometimes you just want to get separate SQL statement from a big SQL script, this is not that easy in a SQL Server script, because there is no delimiter operator such as ; required to separate SQL statements in SQL Server script like Oracle or other databases do.<\/p>\n

\nGeneral SQL Parser can help you to achieve this quickly.<\/p>\n

Code in Java:<\/p>\n

    \r\n    TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmssql);\r\n    sqlparser.sqlfilename  = args[0];\r\n\r\n    int ret = sqlparser.getrawsqlstatements();\r\n    if (ret == 0){\r\n        for(int i=0;i<sqlparser.sqlstatements.size();i++){\r\n            System.out.println(sqlparser.sqlstatements.get(i).sqlstatementtype.toString());\r\n            System.out.println(sqlparser.sqlstatements.get(i).toString());\r\n            System.out.println();\r\n        }\r\n    }else{\r\n        System.out.println(sqlparser.getErrormessage());\r\n    }\r\n<\/pre>\n\nDownload this dem: Java version<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Sometimes you just want to get separate SQL statement from a big SQL script, this is not that easy in a SQL Server script, because there is no delimiter operator such as ; required to separate SQL statements in SQL Server script like Oracle or other databases do. General SQL Parser can help you to achieve this quickly. Code in Java: TGSqlParser sqlparser = new TGSqlParser(EDbVendor.dbvmssql); sqlparser.sqlfilename = args[0]; int ret = sqlparser.getrawsqlstatements(); if (ret == 0){ for(int i=0;i<sqlparser.sqlstatements.size();i++){ System.out.println(sqlparser.sqlstatements.get(i).sqlstatementtype.toString()); System.out.println(sqlparser.sqlstatements.get(i).toString()); System.out.println(); } }else{ System.out.println(sqlparser.getErrormessage()); } Download this dem: Java version<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":235,"menu_order":0,"comment_status":"open","ping_status":"open","template":"gsp_feature_page_tt.php","meta":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"yoast_head":"\nHelp you to make better use of General SQL Parser<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n