├── .gitignore ├── LICENSE.txt ├── README.md ├── lexer-parser-walker-composed ├── .gitignore └── pom.xml ├── lexer-parser-walker ├── .gitignore └── pom.xml ├── lexer-parser ├── .gitignore └── pom.xml ├── parsers ├── PLSQLCommons.g ├── PLSQLKeys.g ├── PLSQLLexer.g ├── PLSQLParser.g ├── PLSQLWalker.g ├── PLSQL_DMLParser.g ├── SQLPLUSParser.g ├── TestPLSQLParser.testsuite ├── TestPLSQLWalker.testsuite ├── TestPLSQL_DML.testsuite ├── TestPLSQL_DMLWalker.testsuite ├── no-ast │ ├── PLSQLCommons.g │ ├── PLSQLKeys.g │ ├── PLSQLParser.g │ ├── PLSQL_DMLParser.g │ └── SQLPLUSParser.g └── walker-composed │ ├── PLSQLCommonsWalker.g │ ├── PLSQLWalker.g │ └── PLSQL_DMLWalker.g ├── pom.xml └── tests ├── aggregate01.sql ├── analytic_query02.sql ├── analytic_query03.sql ├── analytic_query04.sql ├── analytic_query05.sql ├── analytic_query06.sql ├── analytic_query07.sql ├── bindvar01.sql ├── bindvar02.sql ├── bindvar03.sql ├── bindvar04.sql ├── bindvar05.sql ├── case_when01.sql ├── case_when02.sql ├── case_when03.sql ├── case_when04.sql ├── case_when05.sql ├── cast_multiset01.sql ├── cast_multiset02.sql ├── cast_multiset03.sql ├── cast_multiset04.sql ├── cast_multiset05.sql ├── cast_multiset06.sql ├── cast_multiset07.sql ├── cast_multiset08.sql ├── columns01.sql ├── comment01.sql ├── condition01.sql ├── condition02.sql ├── condition03.sql ├── condition04.sql ├── condition05.sql ├── condition06.sql ├── condition07.sql ├── condition08.sql ├── condition09.sql ├── condition10.sql ├── condition11.sql ├── condition12.sql ├── condition14.sql ├── condition15.sql ├── condition16.sql ├── connect_by01.sql ├── connect_by02.sql ├── connect_by03.sql ├── connect_by04.sql ├── connect_by05.sql ├── datetime01.sql ├── datetime02.sql ├── datetime03.sql ├── datetime04.sql ├── datetime05.sql ├── dblink01.sql ├── explain01.sql ├── flashback01.sql ├── for_update01.sql ├── for_update02.sql ├── for_update03.sql ├── for_update04.sql ├── for_update05.sql ├── for_update06.sql ├── for_update07.sql ├── for_update08.sql ├── function01.sql ├── function02.sql ├── function03.sql ├── function04.sql ├── function05.sql ├── function06.sql ├── groupby01.sql ├── groupby02.sql ├── groupby03.sql ├── groupby04.sql ├── groupby05.sql ├── groupby06.sql ├── groupby07.sql ├── interval01.sql ├── interval02.sql ├── interval03.sql ├── interval04.sql ├── join01.sql ├── join02.sql ├── join03.sql ├── join04.sql ├── join05.sql ├── join06.sql ├── join07.sql ├── join08.sql ├── join09.sql ├── join10.sql ├── join11.sql ├── join12.sql ├── join13.sql ├── join14.sql ├── join15.sql ├── join16.sql ├── join17.sql ├── join18.sql ├── join19.sql ├── join20.sql ├── join21.sql ├── keywordasidentifier01.sql ├── keywordasidentifier02.sql ├── keywordasidentifier03.sql ├── keywordasidentifier04.sql ├── keywordasidentifier05.sql ├── lexer01.sql ├── lexer02.sql ├── lexer03.sql ├── lexer04.sql ├── lexer05.sql ├── like01.sql ├── merge01.sql ├── merge02.sql ├── merge03.sql ├── merge04.sql ├── model_clause01.sql ├── model_clause02.sql ├── model_clause03.sql ├── model_clause04.sql ├── model_clause05.sql ├── numbers01.sql ├── object_access01.sql ├── order_by01.sql ├── order_by02.sql ├── order_by03.sql ├── order_by04.sql ├── order_by05.sql ├── order_by06.sql ├── pivot01.sql ├── pivot02.sql ├── pivot03.sql ├── pivot04.sql ├── pivot05.sql ├── pivot06.sql ├── pivot07.sql ├── pivot08.sql ├── pivot09.sql ├── pivot10.sql ├── pivot11.sql ├── pivot12.sql ├── query_factoring01.sql ├── query_factoring02.sql ├── query_factoring03.sql ├── query_factoring04.sql ├── query_factoring05.sql ├── query_factoring06.sql ├── query_factoring07.sql ├── query_factoring08.sql ├── query_factoring09.sql ├── query_factoring10.sql ├── query_factoring11.sql ├── sample01.sql ├── simple02.sql ├── simple03.sql ├── simple04.sql ├── simple05.sql ├── simple06.sql ├── simple07.sql ├── simple08.sql ├── simple09.sql ├── simple10.sql ├── simple11.sql ├── simple12.sql ├── simple13.sql ├── string01.sql ├── union01.sql ├── union02.sql ├── union03.sql ├── union04.sql ├── union05.sql ├── union06.sql ├── union07.sql ├── union08.sql ├── union09.sql ├── union10.sql ├── xmltable01.sql └── xmltable02.sql /.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | jrat.output 3 | jrat.xml 4 | 5 | # IDE support files 6 | .classpath 7 | .project 8 | .metadata 9 | .settings 10 | .wtpmodules 11 | .pmd 12 | .idea 13 | atlassian-ide-plugin.xml 14 | 15 | #ANTLR temp files 16 | *.tokens 17 | 18 | #emacs bkp 19 | *~ 20 | 21 | # Maven generated folders 22 | temp-testng-customsuite.xml 23 | test-output 24 | target 25 | bin 26 | META-INF 27 | out.slql 28 | profiles.xml 29 | 30 | # General folders 31 | local 32 | nbproject 33 | 34 | # logs 35 | *.log 36 | 37 | # mac files 38 | .DS_Store 39 | 40 | # general files 41 | *.ipr 42 | *.iws 43 | *.iml 44 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Important Note! 2 | ===== 3 | This project is not mantained anymore. But this grammar has been ported to antlr4 by community and available here: 4 | 5 | 6 | About 7 | ===== 8 | 9 | This is a [almost] full parser for PL/SQL language that includes a Lexer, Parser (that optionally generates an Abstract Syntax Tree) and a TreeWalker. 10 | 11 | **Note:** This parser supports 11g version. 12 | 13 | Issue Tracking 14 | ===== 15 | 16 | 17 | 18 | Supported Version: 19 | ===== 20 | 21 | * [ANTLR v3.3](http://antlr.org) 22 | 23 | Target Language: 24 | ----- 25 | 26 | Current version is target for `Java` language, but may be easy to port it to any other target. 27 | 28 | Commercial Support 29 | ===== 30 | 31 | If you're interested in commercial support of this or any other parser, contact me . 32 | 33 | License 34 | ===== 35 | 36 | (The Apache License, Version 2.0) 37 | 38 | Copyright (c) 2010 Alexandre Porcelli [alexandre.porcelli@gmail.com] 39 | 40 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 41 | 42 | http://www.apache.org/licenses/LICENSE-2.0 43 | 44 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 45 | 46 | Legal and Trademarks 47 | ===== 48 | 49 | * Oracle is a registered trademark of Oracle Corporation. 50 | * PL/SQL is a trademark of Oracle Corporation. 51 | * Java is a trademark of Oracle Corporation. 52 | * ANTLR is a registered trademark of Terence Parr. 53 | 54 | [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/porcelli/plsql-parser/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 55 | 56 | -------------------------------------------------------------------------------- /lexer-parser-walker-composed/.gitignore: -------------------------------------------------------------------------------- 1 | #ANTLR 2 | *.g 3 | *.testsuite 4 | -------------------------------------------------------------------------------- /lexer-parser-walker-composed/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | br.com.porcelli.parser 7 | plsql 8 | 1.0-SNAPSHOT 9 | 10 | br.com.porcelli.parser.plsql 11 | lexer-parser-walker-composed 12 | 13 | 14 | org.antlr 15 | antlr 16 | 17 | 18 | org.antlr 19 | antlr-runtime 20 | 21 | 22 | 23 | 24 | 25 | org.codehaus.mojo 26 | build-helper-maven-plugin 27 | 28 | 29 | generate-sources 30 | 31 | add-source 32 | 33 | 34 | 35 | ${project.build.directory}/generated-sources/antlr3 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.codehaus.mojo 43 | exec-maven-plugin 44 | 1.1 45 | 46 | 47 | generate-sources 48 | 49 | exec 50 | 51 | 52 | 53 | 54 | java 55 | 56 | -Xmx1g 57 | -classpath 58 | 59 | org.antlr.Tool 60 | -o 61 | ${project.build.directory}/generated-sources/antlr3/br/com/porcelli/parser/plsql/ 62 | 63 | -Xmultithreaded 64 | -lib 65 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/imports/ 66 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLLexer.g 67 | 68 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLParser.g 69 | 70 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLWalker.g 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /lexer-parser-walker/.gitignore: -------------------------------------------------------------------------------- 1 | #ANTLR 2 | *.g 3 | *.testsuite 4 | -------------------------------------------------------------------------------- /lexer-parser-walker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | br.com.porcelli.parser 7 | plsql 8 | 1.0-SNAPSHOT 9 | 10 | br.com.porcelli.parser.plsql 11 | lexer-parser-walker 12 | 13 | 14 | org.antlr 15 | antlr 16 | 17 | 18 | org.antlr 19 | antlr-runtime 20 | 21 | 22 | 23 | 24 | 25 | org.codehaus.mojo 26 | build-helper-maven-plugin 27 | 28 | 29 | generate-sources 30 | 31 | add-source 32 | 33 | 34 | 35 | ${project.build.directory}/generated-sources/antlr3 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.codehaus.mojo 43 | exec-maven-plugin 44 | 1.1 45 | 46 | 47 | generate-sources 48 | 49 | exec 50 | 51 | 52 | 53 | 54 | java 55 | 56 | -Xmx1g 57 | -classpath 58 | 59 | org.antlr.Tool 60 | -o 61 | ${project.build.directory}/generated-sources/antlr3/br/com/porcelli/parser/plsql/ 62 | 63 | -Xmultithreaded 64 | -lib 65 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/imports/ 66 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLLexer.g 67 | 68 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLParser.g 69 | 70 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLWalker.g 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /lexer-parser/.gitignore: -------------------------------------------------------------------------------- 1 | #ANTLR 2 | *.g 3 | *.testsuite 4 | -------------------------------------------------------------------------------- /lexer-parser/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | br.com.porcelli.parser 7 | plsql 8 | 1.0-SNAPSHOT 9 | 10 | br.com.porcelli.parser.plsql 11 | lexer-parser 12 | 13 | 14 | org.antlr 15 | antlr 16 | 17 | 18 | org.antlr 19 | antlr-runtime 20 | 21 | 22 | 23 | 24 | 25 | org.codehaus.mojo 26 | build-helper-maven-plugin 27 | 28 | 29 | generate-sources 30 | 31 | add-source 32 | 33 | 34 | 35 | ${project.build.directory}/generated-sources/antlr3 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.codehaus.mojo 43 | exec-maven-plugin 44 | 1.1 45 | 46 | 47 | generate-sources 48 | 49 | exec 50 | 51 | 52 | 53 | 54 | java 55 | 56 | -Xmx1g 57 | -classpath 58 | 59 | org.antlr.Tool 60 | -o 61 | ${project.build.directory}/generated-sources/antlr3/br/com/porcelli/parser/plsql/ 62 | 63 | -Xmultithreaded 64 | -lib 65 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/imports/ 66 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLLexer.g 67 | 68 | ${project.basedir}/src/main/antlr3/br/com/porcelli/parser/plsql/PLSQLParser.g 69 | 70 | 71 | 72 | 73 | 74 | org.antlr 75 | maven-gunit-plugin 76 | 3.2 77 | 78 | 79 | maven-gunit-plugin 80 | test 81 | 82 | gunit 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /parsers/PLSQLCommons.g: -------------------------------------------------------------------------------- 1 | /** 2 | * Oracle(c) PL/SQL 11g Parser 3 | * 4 | * Copyright (c) 2009-2011 Alexandre Porcelli 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | parser grammar PLSQLCommons; 20 | 21 | options { 22 | output=AST; 23 | } 24 | 25 | tokens { 26 | ALIAS; 27 | EXPR; 28 | ARGUMENTS; 29 | ARGUMENT; 30 | PARAMETER_NAME; 31 | ATTRIBUTE_NAME; 32 | SAVEPOINT_NAME; 33 | ROLLBACK_SEGMENT_NAME; 34 | TABLE_VAR_NAME; 35 | SCHEMA_NAME; 36 | ROUTINE_NAME; 37 | PACKAGE_NAME; 38 | IMPLEMENTATION_TYPE_NAME; 39 | REFERENCE_MODEL_NAME; 40 | MAIN_MODEL_NAME; 41 | QUERY_NAME; 42 | CONSTRAINT_NAME; 43 | LABEL_NAME; 44 | TYPE_NAME; 45 | SEQUENCE_NAME; 46 | EXCEPTION_NAME; 47 | FUNCTION_NAME; 48 | PROCEDURE_NAME; 49 | TRIGGER_NAME; 50 | INDEX_NAME; 51 | CURSOR_NAME; 52 | RECORD_NAME; 53 | COLLECTION_NAME; 54 | LINK_NAME; 55 | COLUMN_NAME; 56 | TABLEVIEW_NAME; 57 | CHAR_SET_NAME; 58 | ID; 59 | VARIABLE_NAME; 60 | HOSTED_VARIABLE_NAME; 61 | CUSTOM_TYPE; 62 | NATIVE_DATATYPE; 63 | INTERVAL_DATATYPE; 64 | PRECISION; 65 | CASCATED_ELEMENT; 66 | HOSTED_VARIABLE_ROUTINE_CALL; 67 | HOSTED_VARIABLE; 68 | ROUTINE_CALL; 69 | ANY_ELEMENT; 70 | COST_CLASS_NAME; 71 | XML_COLUMN_NAME; 72 | } 73 | 74 | // $ ^(ALIAS id? alias_quoted_string?) 88 | | as_key 89 | ; 90 | 91 | table_alias 92 | : ( id | alias_quoted_string ) 93 | -> ^(ALIAS id? alias_quoted_string?) 94 | ; 95 | 96 | alias_quoted_string 97 | : quoted_string 98 | -> ID[$quoted_string.start] 99 | ; 100 | 101 | where_clause 102 | : where_key^ (current_of_clause|condition_wrapper) 103 | ; 104 | 105 | current_of_clause 106 | : current_key^ of_key! cursor_name 107 | ; 108 | 109 | into_clause 110 | : into_key^ variable_name (COMMA! variable_name)* 111 | | bulk_key^ collect_key! into_key! variable_name (COMMA! variable_name)* 112 | ; 113 | 114 | // $> 115 | 116 | // $ ^(XML_COLUMN_NAME id) 120 | | quoted_string -> ^(XML_COLUMN_NAME ID[$quoted_string.start]) 121 | ; 122 | 123 | cost_class_name 124 | : id 125 | -> ^(COST_CLASS_NAME id) 126 | ; 127 | 128 | attribute_name 129 | : id 130 | -> ^(ATTRIBUTE_NAME id) 131 | ; 132 | 133 | savepoint_name 134 | : id 135 | -> ^(SAVEPOINT_NAME id) 136 | ; 137 | 138 | rollback_segment_name 139 | : id 140 | -> ^(ROLLBACK_SEGMENT_NAME id) 141 | ; 142 | 143 | 144 | table_var_name 145 | : id 146 | -> ^(TABLE_VAR_NAME id) 147 | ; 148 | 149 | schema_name 150 | : id 151 | -> ^(SCHEMA_NAME id) 152 | ; 153 | 154 | routine_name 155 | : id ((PERIOD id_expression)=> PERIOD id_expression)* (AT_SIGN link_name)? 156 | -> ^(ROUTINE_NAME id id_expression* link_name?) 157 | ; 158 | 159 | package_name 160 | : id 161 | -> ^(PACKAGE_NAME id) 162 | ; 163 | 164 | implementation_type_name 165 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 166 | -> ^(IMPLEMENTATION_TYPE_NAME id id_expression?) 167 | ; 168 | 169 | parameter_name 170 | : id 171 | -> ^(PARAMETER_NAME id) 172 | ; 173 | 174 | reference_model_name 175 | : id 176 | -> ^(REFERENCE_MODEL_NAME id) 177 | ; 178 | 179 | main_model_name 180 | : id 181 | -> ^(MAIN_MODEL_NAME id) 182 | ; 183 | 184 | aggregate_function_name 185 | : id ((PERIOD id_expression)=> PERIOD id_expression)* 186 | -> ^(ROUTINE_NAME id id_expression*) 187 | ; 188 | 189 | query_name 190 | : id 191 | -> ^(QUERY_NAME id) 192 | ; 193 | 194 | constraint_name 195 | : id ((PERIOD id_expression)=> PERIOD id_expression)* (AT_SIGN link_name)? 196 | -> ^(CONSTRAINT_NAME id id_expression* link_name?) 197 | ; 198 | 199 | label_name 200 | : id_expression 201 | -> ^(LABEL_NAME id_expression) 202 | ; 203 | 204 | type_name 205 | : id_expression ((PERIOD id_expression)=> PERIOD id_expression)* 206 | -> ^(TYPE_NAME id_expression+) 207 | ; 208 | 209 | sequence_name 210 | : id_expression ((PERIOD id_expression)=> PERIOD id_expression)* 211 | -> ^(SEQUENCE_NAME id_expression+) 212 | ; 213 | 214 | exception_name 215 | : id ((PERIOD id_expression)=> PERIOD id_expression)* 216 | ->^(EXCEPTION_NAME id id_expression*) 217 | ; 218 | 219 | function_name 220 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 221 | -> ^(FUNCTION_NAME id id_expression*) 222 | ; 223 | 224 | procedure_name 225 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 226 | -> ^(PROCEDURE_NAME id id_expression*) 227 | ; 228 | 229 | trigger_name 230 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 231 | ->^(TRIGGER_NAME id id_expression*) 232 | ; 233 | 234 | variable_name 235 | : (INTRODUCER char_set_name)? 236 | id_expression ((PERIOD id_expression)=> PERIOD id_expression)? 237 | -> ^(VARIABLE_NAME char_set_name? id_expression*) 238 | | bind_variable 239 | -> ^(HOSTED_VARIABLE_NAME bind_variable) 240 | ; 241 | 242 | index_name 243 | : id 244 | -> ^(INDEX_NAME id) 245 | ; 246 | 247 | cursor_name 248 | : (id | bind_variable) 249 | -> ^(CURSOR_NAME id? bind_variable?) 250 | ; 251 | 252 | record_name 253 | : (id | bind_variable) 254 | ->^(RECORD_NAME id) 255 | ; 256 | 257 | collection_name 258 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 259 | ->^(COLLECTION_NAME id id_expression?) 260 | ; 261 | 262 | link_name 263 | : id 264 | -> ^(LINK_NAME id) 265 | ; 266 | 267 | column_name 268 | : id ((PERIOD id_expression)=> PERIOD id_expression)* 269 | -> ^(COLUMN_NAME id id_expression*) 270 | ; 271 | 272 | tableview_name 273 | : id ((PERIOD id_expression)=> PERIOD id_expression)? 274 | ( AT_SIGN link_name 275 | | {!(input.LA(2) == SQL92_RESERVED_BY)}?=> partition_extension_clause 276 | )? 277 | -> ^(TABLEVIEW_NAME id id_expression? link_name? partition_extension_clause?) 278 | ; 279 | 280 | char_set_name 281 | : id_expression ((PERIOD id_expression)=> PERIOD id_expression)* 282 | ->^(CHAR_SET_NAME id_expression+) 283 | ; 284 | 285 | // $> 286 | 287 | // $ ^(ARGUMENTS argument* keep_clause?) 304 | ; 305 | 306 | function_argument_analytic 307 | : LEFT_PAREN 308 | (argument respect_or_ignore_nulls?)? 309 | (COMMA argument respect_or_ignore_nulls? )* 310 | RIGHT_PAREN 311 | keep_clause? 312 | -> ^(ARGUMENTS argument* keep_clause?) 313 | ; 314 | 315 | function_argument_modeling 316 | : LEFT_PAREN 317 | column_name (COMMA (numeric|null_key) (COMMA (numeric|null_key) )? )? 318 | using_key 319 | ( (tableview_name PERIOD ASTERISK)=> tableview_name PERIOD ASTERISK 320 | | ASTERISK 321 | | expression column_alias? (COMMA expression column_alias?)* 322 | ) 323 | RIGHT_PAREN 324 | keep_clause? 325 | -> ^(ARGUMENTS column_name keep_clause?) 326 | ; 327 | 328 | respect_or_ignore_nulls 329 | : (respect_key | ignore_key) nulls_key 330 | ; 331 | 332 | argument 333 | @init { int mode = 0; } 334 | : ((id EQUALS_OP GREATER_THAN_OP)=> id EQUALS_OP GREATER_THAN_OP {mode = 1;})? expression_wrapper 335 | ->{mode == 1}? ^(ARGUMENT expression_wrapper ^(PARAMETER_NAME[$EQUALS_OP] id)) 336 | -> ^(ARGUMENT expression_wrapper) 337 | ; 338 | 339 | type_spec 340 | : datatype 341 | | ref_key? type_name (percent_rowtype_key|percent_type_key)? -> ^(CUSTOM_TYPE type_name ref_key? percent_rowtype_key? percent_type_key?) 342 | ; 343 | 344 | datatype 345 | : native_datatype_element 346 | precision_part? 347 | (with_key local_key? time_key zone_key)? 348 | -> ^(NATIVE_DATATYPE native_datatype_element precision_part? time_key? local_key?) 349 | | interval_key (year_key|day_key) 350 | (LEFT_PAREN expression_wrapper RIGHT_PAREN)? 351 | to_key (month_key|second_key) 352 | (LEFT_PAREN expression_wrapper RIGHT_PAREN)? 353 | -> ^(INTERVAL_DATATYPE[$interval_key.start] year_key? day_key? month_key? second_key? expression_wrapper*) 354 | ; 355 | 356 | precision_part 357 | : LEFT_PAREN numeric (COMMA numeric)? (char_key | byte_key)? RIGHT_PAREN 358 | -> ^(PRECISION numeric+ char_key? byte_key?) 359 | ; 360 | 361 | native_datatype_element 362 | : binary_integer_key 363 | | pls_integer_key 364 | | natural_key 365 | | binary_float_key 366 | | binary_double_key 367 | | naturaln_key 368 | | positive_key 369 | | positiven_key 370 | | signtype_key 371 | | simple_integer_key 372 | | nvarchar2_key 373 | | dec_key 374 | | integer_key 375 | | int_key 376 | | numeric_key 377 | | smallint_key 378 | | number_key 379 | | decimal_key 380 | | double_key precision_key? 381 | | float_key 382 | | real_key 383 | | nchar_key 384 | | long_key raw_key? 385 | | char_key 386 | | character_key 387 | | varchar2_key 388 | | varchar_key 389 | | string_key 390 | | raw_key 391 | | boolean_key 392 | | date_key 393 | | rowid_key 394 | | urowid_key 395 | | year_key 396 | | month_key 397 | | day_key 398 | | hour_key 399 | | minute_key 400 | | second_key 401 | | timezone_hour_key 402 | | timezone_minute_key 403 | | timezone_region_key 404 | | timezone_abbr_key 405 | | timestamp_key 406 | | timestamp_unconstrained_key 407 | | timestamp_tz_unconstrained_key 408 | | timestamp_ltz_unconstrained_key 409 | | yminterval_unconstrained_key 410 | | dsinterval_unconstrained_key 411 | | bfile_key 412 | | blob_key 413 | | clob_key 414 | | nclob_key 415 | | mlslabel_key 416 | ; 417 | 418 | bind_variable 419 | : ( b1=BINDVAR | COLON u1=UNSIGNED_INTEGER) 420 | ( indicator_key? (b2=BINDVAR | COLON u2=UNSIGNED_INTEGER))? 421 | ((PERIOD general_element_part)=> PERIOD general_element_part)* 422 | ->^(HOSTED_VARIABLE_NAME $b1? $u1? indicator_key? $b2? $u2? general_element_part*) 423 | ; 424 | 425 | general_element 426 | @init { boolean isCascated = true; } 427 | : general_element_part ((PERIOD general_element_part)=> PERIOD general_element_part {isCascated = true;})* 428 | ->{isCascated}? ^(CASCATED_ELEMENT general_element_part+) 429 | -> general_element_part 430 | ; 431 | 432 | general_element_part 433 | @init { boolean isRoutineCall = false; } 434 | : (INTRODUCER char_set_name)? id_expression 435 | ((PERIOD id_expression)=> PERIOD id_expression)* (function_argument {isRoutineCall = true;})? 436 | ->{isRoutineCall}? ^(ROUTINE_CALL ^(ROUTINE_NAME char_set_name? id_expression+) function_argument) 437 | -> ^(ANY_ELEMENT char_set_name? id_expression+) 438 | ; 439 | 440 | table_element 441 | : (INTRODUCER char_set_name)? id_expression (PERIOD id_expression)* 442 | -> ^(ANY_ELEMENT char_set_name? id_expression+) 443 | ; 444 | 445 | // $> 446 | 447 | // $ char_set_name? id_expression 485 | ; 486 | 487 | id_expression 488 | : REGULAR_ID -> ID[$REGULAR_ID] 489 | | DELIMITED_ID -> ID[$DELIMITED_ID] 490 | ; 491 | 492 | not_equal_op 493 | : NOT_EQUAL_OP 494 | | LESS_THAN_OP GREATER_THAN_OP 495 | | EXCLAMATION_OPERATOR_PART EQUALS_OP 496 | | CARRET_OPERATOR_PART EQUALS_OP 497 | ; 498 | 499 | greater_than_or_equals_op 500 | : GREATER_THAN_OR_EQUALS_OP 501 | | GREATER_THAN_OP EQUALS_OP 502 | ; 503 | 504 | less_than_or_equals_op 505 | : LESS_THAN_OR_EQUALS_OP 506 | | LESS_THAN_OP EQUALS_OP 507 | ; 508 | 509 | concatenation_op 510 | : CONCATENATION_OP 511 | | VERTICAL_BAR VERTICAL_BAR 512 | ; 513 | 514 | outer_join_sign 515 | : LEFT_PAREN PLUS_SIGN RIGHT_PAREN 516 | ; 517 | 518 | // $> 519 | -------------------------------------------------------------------------------- /parsers/SQLPLUSParser.g: -------------------------------------------------------------------------------- 1 | /** 2 | * Oracle(c) SQL*Plus 11g Parser 3 | * 4 | * Copyright (c) 2009-2011 Alexandre Porcelli 5 | * Tomi Pakarinen 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | parser grammar SQLPLUSParser; 20 | 21 | options { 22 | output=AST; 23 | } 24 | 25 | sql_plus_command 26 | : (SOLIDUS!|whenever_command|exit_command|prompt_command|set_command) SEMICOLON? 27 | ; 28 | 29 | whenever_command 30 | : whenever_key^ (sqlerror_key|oserror_key) (exit_key (success_key|failure_key|warning_key) (commit_key|rollback_key) | continue_key (commit_key|rollback_key|none_key)) 31 | ; 32 | 33 | set_command 34 | : set_key^ REGULAR_ID (CHAR_STRING|on_key|off_key|EXACT_NUM_LIT|REGULAR_ID) 35 | ; 36 | 37 | exit_command 38 | : exit_key 39 | ; 40 | 41 | prompt_command 42 | : PROMPT 43 | ; 44 | 45 | -------------------------------------------------------------------------------- /parsers/TestPLSQL_DML.testsuite: -------------------------------------------------------------------------------- 1 | /** 2 | * Oracle(c) PL/SQL 11g Parser 3 | * 4 | * Copyright (c) 2009-2011 Alexandre Porcelli 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | gunit PLSQL; 20 | 21 | @header { package br.com.porcelli.parser.plsql; } 22 | 23 | group_by_clause: 24 | "group by country_name,prod_name,calendar_year" OK 25 | 26 | select_statement: 27 | join01.sql OK 28 | join02.sql OK 29 | join03.sql OK 30 | join04.sql OK 31 | join05.sql OK 32 | join06.sql OK 33 | join07.sql OK 34 | join08.sql OK 35 | join09.sql OK 36 | join10.sql OK 37 | join11.sql OK 38 | join12.sql OK 39 | join13.sql OK 40 | join14.sql OK 41 | join15.sql OK 42 | join16.sql OK 43 | join17.sql OK 44 | join18.sql OK 45 | join19.sql OK 46 | join20.sql OK 47 | join21.sql OK 48 | interval01.sql OK 49 | interval02.sql OK 50 | interval03.sql OK 51 | interval04.sql OK 52 | datetime01.sql OK 53 | datetime02.sql OK 54 | datetime03.sql OK 55 | datetime04.sql OK 56 | datetime05.sql OK 57 | query_factoring01.sql OK 58 | query_factoring02.sql OK 59 | query_factoring03.sql OK 60 | query_factoring04.sql OK 61 | query_factoring05.sql OK 62 | query_factoring06.sql OK 63 | query_factoring07.sql OK 64 | query_factoring08.sql OK 65 | query_factoring09.sql OK 66 | query_factoring10.sql OK 67 | query_factoring11.sql OK 68 | condition01.sql OK 69 | condition02.sql OK 70 | condition03.sql OK 71 | condition04.sql OK 72 | condition05.sql OK 73 | condition06.sql OK 74 | condition07.sql OK 75 | condition08.sql OK 76 | condition09.sql OK 77 | condition10.sql OK 78 | condition11.sql OK 79 | condition12.sql OK 80 | condition14.sql OK 81 | condition15.sql OK 82 | condition16.sql OK 83 | like01.sql OK 84 | for_update01.sql OK 85 | for_update02.sql OK 86 | for_update03.sql OK 87 | for_update04.sql OK 88 | for_update05.sql OK 89 | for_update06.sql OK 90 | for_update07.sql OK 91 | for_update08.sql OK 92 | string01.sql OK 93 | aggregate01.sql OK 94 | analytic_query02.sql OK 95 | analytic_query03.sql OK 96 | analytic_query04.sql OK 97 | analytic_query05.sql OK 98 | analytic_query06.sql OK 99 | cast_multiset01.sql OK 100 | cast_multiset02.sql OK 101 | cast_multiset03.sql OK 102 | cast_multiset04.sql OK 103 | cast_multiset05.sql OK 104 | cast_multiset06.sql OK 105 | cast_multiset07.sql OK 106 | cast_multiset08.sql OK 107 | case_when01.sql OK 108 | case_when02.sql OK 109 | case_when03.sql OK 110 | case_when04.sql OK 111 | case_when05.sql OK 112 | lexer01.sql OK 113 | lexer02.sql OK 114 | lexer03.sql OK 115 | lexer04.sql OK 116 | lexer05.sql OK 117 | columns01.sql OK 118 | //bindvar01.sql OK insert 119 | bindvar02.sql OK 120 | bindvar03.sql OK 121 | bindvar04.sql OK 122 | bindvar05.sql OK 123 | model_clause01.sql OK 124 | model_clause02.sql OK 125 | model_clause03.sql OK 126 | model_clause04.sql OK 127 | model_clause05.sql OK 128 | union01.sql OK 129 | union02.sql OK 130 | union03.sql OK 131 | union04.sql OK 132 | union05.sql OK 133 | union06.sql OK 134 | union07.sql OK 135 | union08.sql OK 136 | union09.sql OK 137 | union10.sql OK 138 | connect_by01.sql OK 139 | connect_by02.sql OK 140 | connect_by03.sql OK 141 | connect_by04.sql OK 142 | connect_by05.sql OK 143 | groupby01.sql OK 144 | groupby02.sql OK 145 | groupby03.sql OK 146 | groupby04.sql OK 147 | groupby05.sql OK 148 | groupby06.sql OK 149 | groupby07.sql OK 150 | order_by01.sql OK 151 | order_by02.sql OK 152 | order_by03.sql OK 153 | order_by04.sql OK 154 | order_by05.sql OK 155 | order_by06.sql OK 156 | dblink01.sql OK 157 | function01.sql OK 158 | function02.sql OK 159 | function03.sql OK 160 | function04.sql OK 161 | function05.sql OK 162 | //function06.sql OK fails PL/SQL construct 163 | pivot01.sql OK 164 | pivot02.sql OK 165 | pivot03.sql OK 166 | pivot04.sql OK 167 | pivot05.sql OK 168 | pivot06.sql OK 169 | pivot07.sql OK 170 | pivot08.sql OK 171 | pivot09.sql OK 172 | pivot10.sql OK 173 | pivot11.sql OK 174 | pivot12.sql OK 175 | comment01.sql OK 176 | simple02.sql OK 177 | simple03.sql OK 178 | simple04.sql OK 179 | simple05.sql OK 180 | simple06.sql OK 181 | simple07.sql OK 182 | simple08.sql OK 183 | simple09.sql OK 184 | simple10.sql OK 185 | simple11.sql OK 186 | simple12.sql OK 187 | simple13.sql OK 188 | object_access01.sql OK 189 | sample01.sql OK 190 | numbers01.sql OK 191 | flashback01.sql OK 192 | keywordasidentifier01.sql OK 193 | keywordasidentifier02.sql OK 194 | keywordasidentifier03.sql OK 195 | keywordasidentifier04.sql OK 196 | keywordasidentifier05.sql OK 197 | //xmltable01.sql OK 198 | xmltable02.sql OK 199 | 200 | "select * from tablex, tabley" OK 201 | <> OK 212 | <> OK 220 | <> OK 234 | <> OK 244 | <> OK 252 | <> OK 261 | <> OK 267 | <> OK 289 | <> OK 307 | <> OK 316 | <> OK 323 | <> OK 331 | <> OK 340 | <> OK 349 | <> OK 358 | <> OK 367 | <> OK 375 | <> OK 382 | "select sysdate from dual" OK 383 | "select employees_seq.currval from dual" OK 384 | 385 | table_ref: 386 | "tablex" OK 387 | <> OK 389 | <> OK 391 | <> OK 393 | <> OK 396 | 397 | table_ref_list: 398 | "hr_info t1, table(t1.people) t2 " OK 399 | 400 | dml_table_expression_clause: 401 | "tablex" OK 402 | 403 | table_ref_aux: 404 | "only ( tablex ) " OK 405 | "sales partition (sales_q2_2000)" OK 406 | "orders sample (10)" OK 407 | "orders sample(10) seed (1)" OK 408 | "employees as of timestamp systimestamp" OK //TODO fix it 409 | <> OK 412 | "employees e" OK 413 | <> OK 416 | 417 | 418 | tableview_name: 419 | "tablex" OK 420 | 421 | 422 | select_statement: 423 | "select*from table_1" OK 424 | "select * from table_1, table2 where table_1.column1=table_2.column2" OK 425 | "select*from table_1 natural inner join table_2" OK 426 | "select*from table_1 inner join table_2 on table_1.column1=table_2.column2" OK 427 | "select*from table_1 left join table_2 on table_1.column1=table_2.column2" OK 428 | "select*from table_1 left outer join table_2 on table_1.column1=table_2.column2" OK 429 | "select*from table_1 full outer join table_2 on table_1.column1=table_2.column2" OK 430 | "select*from table_1 right join table_2 using (id1,id2)" OK 431 | 432 | "select*from table_1 union select*from table_2" OK 433 | "select*from table_1 union all select*from table_2" OK 434 | "select a,b,c from table_1 minus select e,f,g from table_2" OK 435 | < :"11">> OK 450 | "select * from b where a<=:frmF1_clsC1_dfDF1_instI1 --EXF4" OK 451 | "select*from c where a>aa" OK 452 | 453 | insert_statement: 454 | "insert into departments 455 | values (280, 'recreation', 121, 1700)" OK 456 | <> OK 460 | <> OK 464 | <> OK 466 | < .2 469 | log errors into errlog ('my_bad') reject limit 10>> OK 470 | <> OK 474 | <> OK 476 | <> OK 482 | <> OK 484 | <> OK 486 | <> OK 503 | < 2000000 then 509 | into large_orders 510 | select orders.* from orders>> OK 511 | <> OK 519 | < 100000 and ottl < 200000 then 524 | into medium_orders 525 | values(oid, ottl, sid, cid) 526 | when ottl > 200000 then 527 | into large_orders 528 | values(oid, ottl, sid, cid) 529 | when ottl > 290000 then 530 | into special_orders 531 | select o.* from orders o>> OK 532 | < 100000 and ottl < 200000 then 537 | into medium_orders 538 | values(oid, ottl, sid, cid) 539 | when ottl > 200000 then 540 | into large_orders 541 | values(oid, ottl, sid, cid) 542 | when ottl > 290000 then 543 | into special_orders 544 | when ottl > 200000 then 545 | into large_orders 546 | values(oid, ottl, sid, cid) 547 | select o.* from orders o>> OK 548 | 549 | delete_statement: 550 | <> OK 552 | <> OK 555 | <> OK 558 | < 3000>> OK 560 | < 1000>> OK 562 | <> OK 566 | 567 | update_statement: 568 | <> OK 571 | <> OK 574 | <> OK 577 | < 1>> OK 587 | < 1000>> OK 590 | <> OK 593 | <> OK 597 | <> OK 601 | 602 | merge_statement: 603 | merge01.sql OK 604 | merge02.sql OK 605 | merge03.sql OK 606 | merge04.sql OK 607 | 608 | lock_table_statement: 609 | <> OK 612 | <> OK 615 | <> OK 618 | <> OK 621 | <> OK 624 | <> OK 627 | <> OK 630 | <> OK 633 | <> OK 636 | <> OK 639 | 640 | explain_statement: 641 | explain01.sql OK 642 | -------------------------------------------------------------------------------- /parsers/TestPLSQL_DMLWalker.testsuite: -------------------------------------------------------------------------------- 1 | /** 2 | * Oracle(c) PL/SQL 11g Parser 3 | * 4 | * Copyright (c) 2009-2011 Alexandre Porcelli 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | gunit PLSQLWalker walks PLSQL; 20 | 21 | group_by_clause walks group_by_clause: 22 | "group by country_name,prod_name,calendar_year" OK 23 | 24 | table_ref walks table_ref: 25 | "tablex" OK 26 | <> OK 28 | <> OK 30 | <> OK 32 | <> OK 35 | 36 | dml_table_expression_clause walks dml_table_expression_clause: 37 | "tablex" OK 38 | 39 | table_ref_aux walks table_ref_aux: 40 | "only ( tablex ) " OK 41 | "sales partition (sales_q2_2000)" OK 42 | "orders sample (10)" OK 43 | "orders sample(10) seed (1)" OK 44 | "employees as of timestamp systimestamp" OK //TODO fix it 45 | <> OK 48 | "employees e" OK 49 | "employees as e" OK 50 | <> OK 53 | <> OK 56 | 57 | 58 | tableview_name walks tableview_name: 59 | "tablex" OK 60 | 61 | select_statement walks select_statement: 62 | "select * from tablex, tabley" OK 63 | <> OK 74 | <> OK 82 | <> OK 96 | <> OK 106 | <> OK 114 | <> OK 123 | <> OK 129 | <> OK 151 | <> OK 169 | <> OK 178 | <> OK 185 | <> OK 193 | <> OK 202 | <> OK 211 | <> OK 220 | <> OK 229 | <> OK 237 | <> OK 244 | "select sysdate from dual" OK 245 | "select employees_seq.currval from dual" OK 246 | "select*from table_1" OK 247 | "select * from table_1, table2 where table_1.column1=table_2.column2" OK 248 | "select*from table_1 natural inner join table_2" OK 249 | "select*from table_1 inner join table_2 on table_1.column1=table_2.column2" OK 250 | "select*from table_1 left join table_2 on table_1.column1=table_2.column2" OK 251 | "select*from table_1 left outer join table_2 on table_1.column1=table_2.column2" OK 252 | "select*from table_1 full outer join table_2 on table_1.column1=table_2.column2" OK 253 | "select*from table_1 right join table_2 using (id1,id2)" OK 254 | "select*from table_1 union select*from table_2" OK 255 | "select*from table_1 union all select*from table_2" OK 256 | "select a,b,c from table_1 minus select e,f,g from table_2" OK 257 | < 275 | 276 | update_statement 277 | : ^(SQL92_RESERVED_UPDATE general_table_ref 278 | update_set_clause 279 | where_clause? static_returning_clause? error_logging_clause? 280 | ) 281 | ; 282 | 283 | // $ 295 | 296 | delete_statement 297 | : ^(SQL92_RESERVED_DELETE general_table_ref 298 | where_clause? static_returning_clause? error_logging_clause?) 299 | ; 300 | 301 | insert_statement 302 | : ^(SQL92_RESERVED_INSERT 303 | ( single_table_insert 304 | | multi_table_insert 305 | ) 306 | ) 307 | ; 308 | 309 | // $ 344 | merge_statement 345 | : ^(MERGE_VK alias? tableview_name 346 | ^(PLSQL_NON_RESERVED_USING selected_tableview expression) 347 | merge_update_clause? merge_insert_clause? error_logging_clause?) 348 | ; 349 | 350 | // $ 373 | 374 | lock_table_statement 375 | : ^(PLSQL_RESERVED_LOCK lock_table_element+ lock_mode wait_nowait_part?) 376 | ; 377 | 378 | wait_nowait_part 379 | : ^(WAIT_VK expression) 380 | | PLSQL_RESERVED_NOWAIT 381 | ; 382 | 383 | // $ 397 | 398 | // $ 442 | 443 | // $ 558 | 559 | standard_function 560 | : ^(FUNCTION_ENABLING_OVER function_argument over_clause?) 561 | | ^(FUNCTION_ENABLING_USING function_argument using_clause?) 562 | | ^(COUNT_VK ( ASTERISK | expression ) over_clause?) 563 | | ^((CAST_VK|XMLCAST_VK) (subquery|expression) type_spec) 564 | | ^(CHR_VK expression NCHAR_CS_VK) 565 | | ^(COLLECT_VK (SQL92_RESERVED_DISTINCT|SQL92_RESERVED_UNIQUE)? column_name collect_order_by_part?) 566 | | ^(FUNCTION_ENABLING_WITHIN_OR_OVER function_argument (within_clause|over_clause)+ ) 567 | | ^(DECOMPOSE_VK expression (CANONICAL_VK|COMPATIBILITY_VK)?) 568 | | ^(EXTRACT_VK REGULAR_ID expression) 569 | | ^((FIRST_VALUE_VK|LAST_VALUE_VK) expression NULLS_VK? over_clause) 570 | | ^(PREDICTION_FUNCTION expression+ cost_matrix_clause? using_clause?) 571 | | ^(TRANSLATE_VK expression (CHAR_CS_VK|NCHAR_CS_VK)? expression*) 572 | | ^(TREAT_VK expression REF_VK? type_spec) 573 | | ^(TRIM_VK (LEADING_VK|TRAILING_VK|BOTH_VK)? expression expression?) 574 | 575 | | ^(XMLAGG_VK expression order_by_clause?) 576 | | ^((XMLCOLATTVAL_VK|XMLFOREST_VK) xml_multiuse_expression_element+) 577 | | ^(XMLEXISTS_VK expression xml_passing_clause?) 578 | | ^(XMLPARSE_VK (DOCUMENT_VK|CONTENT_VK) expression WELLFORMED_VK?) 579 | | ^(XMLQUERY_VK expression xml_passing_clause? SQL92_RESERVED_NULL?) 580 | | ^(XMLROOT_VK expression xml_param_version_part xmlroot_param_standalone_part?) 581 | | ^(XMLTABLE_VK xml_namespaces_clause? expression xml_passing_clause? xml_table_column*) 582 | | ^(XMLELEMENT_VK 583 | (ENTITYESCAPING_VK|NOENTITYESCAPING_VK)? 584 | (NAME_VK|EVALNAME_VK)? expression 585 | xml_attributes_clause? (expression alias?)* 586 | ) 587 | | ^(XMLPI_VK 588 | ( NAME_VK char_set_name? ID 589 | | EVALNAME_VK expression 590 | ) 591 | expression? 592 | ) 593 | | ^(XMLSERIALIZE_VK 594 | (DOCUMENT_VK|CONTENT_VK) 595 | expression type_spec? 596 | xmlserialize_param_enconding_part? 597 | xml_param_version_part? 598 | xmlserialize_param_ident_part? 599 | ((HIDE_VK|SHOW_VK) DEFAULTS_VK)? 600 | ) 601 | ; 602 | 603 | over_clause 604 | : ^(OVER_VK query_partition_clause? (order_by_clause windowing_clause?)?) 605 | ; 606 | 607 | windowing_clause 608 | : ^((ROWS_VK|RANGE_VK) 609 | ( ^(SQL92_RESERVED_BETWEEN windowing_elements windowing_elements) 610 | | windowing_elements+ 611 | ) 612 | ) 613 | ; 614 | 615 | windowing_elements 616 | : ^(UNBOUNDED_VK PRECEDING_VK) 617 | | ^(CURRENT_VK ROW_VK) 618 | | ^((PRECEDING_VK|FOLLOWING_VK) expression) 619 | ; 620 | 621 | using_clause 622 | : ^(PLSQL_NON_RESERVED_USING using_element+) 623 | ; 624 | 625 | using_element 626 | : ^(ELEMENT SQL92_RESERVED_IN? OUT_VK? expression alias?) 627 | | ASTERISK 628 | ; 629 | 630 | collect_order_by_part 631 | : ^(SQL92_RESERVED_ORDER expression) 632 | ; 633 | 634 | within_clause 635 | : ^(WITHIN_VK order_by_clause) 636 | ; 637 | 638 | cost_matrix_clause 639 | : ^(COST_VK 640 | ( PLSQL_NON_RESERVED_MODEL AUTO_VK? 641 | | cost_class_name+ expression_list 642 | ) 643 | ) 644 | ; 645 | 646 | xml_passing_clause 647 | : ^(PASSING_VK VALUE_VK? expression alias? (expression alias?)?) 648 | ; 649 | 650 | xml_attributes_clause 651 | : ^(XMLATTRIBUTES_VK 652 | (ENTITYESCAPING_VK|NOENTITYESCAPING_VK)? 653 | (SCHEMACHECK_VK|NOSCHEMACHECK_VK)? 654 | xml_multiuse_expression_element+ 655 | ) 656 | ; 657 | 658 | xml_namespaces_clause 659 | : ^(XMLNAMESPACES_VK 660 | (expression alias?)* xml_general_default_part? 661 | ) 662 | ; 663 | 664 | xml_table_column 665 | : ^(XML_COLUMN xml_column_name (ORDINALITY_VK|type_spec expression? xml_general_default_part?) ) 666 | ; 667 | 668 | xml_general_default_part 669 | : ^(SQL92_RESERVED_DEFAULT expression) 670 | ; 671 | 672 | xml_multiuse_expression_element 673 | : ^(XML_ELEMENT expression xml_alias?) 674 | ; 675 | 676 | xml_alias 677 | : ^(XML_ALIAS ID) 678 | | ^(XML_ALIAS ^(EVALNAME_VK expression)) 679 | ; 680 | 681 | xml_param_version_part 682 | : ^(VERSION_VK (NO_VK VALUE_VK|expression)) 683 | ; 684 | 685 | xmlroot_param_standalone_part 686 | : ^(STANDALONE_VK (YES_VK|NO_VK VALUE_VK?)) 687 | ; 688 | 689 | xmlserialize_param_enconding_part 690 | : ^(ENCODING_VK expression) 691 | ; 692 | 693 | xmlserialize_param_ident_part 694 | : NO_VK INDENT_VK 695 | | ^(INDENT_VK expression?) 696 | ; 697 | 698 | // $> 699 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | br.com.porcelli.parser 5 | plsql 6 | 1.0-SNAPSHOT 7 | pom 8 | plsql 9 | https://github.com/porcelli/plsql-parser 10 | 11 | UTF-8 12 | 13 | 14 | 15 | porcelli 16 | Alexandre Porcelli 17 | http://github.com/porcelli 18 | alexandre.porcelli@gmail.com 19 | 20 | Project Dictator 21 | Parser Developer 22 | 23 | 24 | 25 | 26 | 27 | The Apache Software License, Version 2.0 28 | http://www.apache.org/licenses/LICENSE-2.0.txt 29 | repo 30 | 31 | 32 | 33 | lexer-parser 34 | lexer-parser-walker 35 | lexer-parser-walker-composed 36 | 37 | 38 | 39 | 40 | 41 | org.antlr 42 | antlr 43 | 3.3 44 | 45 | 46 | org.antlr 47 | antlr-runtime 48 | 3.3 49 | 50 | 51 | 52 | junit 53 | junit 54 | 4.8.2 55 | 56 | 57 | com.toolazydogs.aunit 58 | aunit-junit 59 | 1.1.0-SNAPSHOT 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-compiler-plugin 68 | 2.3.2 69 | 70 | 1.6 71 | 1.6 72 | ${project.build.sourceEncoding} 73 | 74 | 75 | 76 | org.codehaus.mojo 77 | build-helper-maven-plugin 78 | 1.5 79 | 80 | 81 | org.codehaus.mojo 82 | exec-maven-plugin 83 | 1.2 84 | 85 | 86 | org.apache.maven.plugins 87 | maven-resources-plugin 88 | 2.5 89 | 90 | ${project.build.sourceEncoding} 91 | 92 | 93 | 94 | lexer-parser-copy-resources-imports 95 | validate 96 | 97 | copy-resources 98 | 99 | 100 | true 101 | ${basedir}/lexer-parser/src/main/antlr3/br/com/porcelli/parser/plsql/imports 102 | 103 | 104 | ${basedir}/parsers/no-ast/ 105 | true 106 | 107 | PLSQLCommons.g 108 | PLSQLKeys.g 109 | PLSQL_DMLParser.g 110 | SQLPLUSParser.g 111 | 112 | 113 | 114 | 115 | 116 | 117 | lexer-parser-copy-resources-parser-lexer 118 | validate 119 | 120 | copy-resources 121 | 122 | 123 | true 124 | ${basedir}/lexer-parser/src/main/antlr3/br/com/porcelli/parser/plsql 125 | 126 | 127 | ${basedir}/parsers/no-ast/ 128 | true 129 | 130 | PLSQLParser.g 131 | 132 | 133 | 134 | ${basedir}/parsers/ 135 | true 136 | 137 | PLSQLLexer.g 138 | 139 | 140 | 141 | 142 | 143 | 144 | lexer-parser-copy-resources-gunits 145 | validate 146 | 147 | copy-resources 148 | 149 | 150 | true 151 | ${basedir}/lexer-parser/src/test/gunit/br/com/porcelli/parser/plsql 152 | 153 | 154 | ${basedir}/parsers/ 155 | true 156 | 157 | TestPLSQL_DML.testsuite 158 | TestPLSQLParser.testsuite 159 | 160 | 161 | 162 | 163 | 164 | 165 | lexer-parser-copy-resources-tests 166 | validate 167 | 168 | copy-resources 169 | 170 | 171 | true 172 | ${basedir}/lexer-parser/src/test/gunit/br/com/porcelli/parser/plsql 173 | 174 | 175 | ${basedir}/tests/ 176 | true 177 | 178 | *.sql 179 | 180 | 181 | 182 | 183 | 184 | 185 | lexer-parser-walker-copy-resources-imports 186 | validate 187 | 188 | copy-resources 189 | 190 | 191 | true 192 | ${basedir}/lexer-parser-walker/src/main/antlr3/br/com/porcelli/parser/plsql/imports 193 | 194 | 195 | ${basedir}/parsers/ 196 | true 197 | 198 | PLSQLCommons.g 199 | PLSQLKeys.g 200 | PLSQL_DMLParser.g 201 | SQLPLUSParser.g 202 | 203 | 204 | 205 | 206 | 207 | 208 | lexer-parser-walker-copy-resources-parser-lexer-walker 209 | validate 210 | 211 | copy-resources 212 | 213 | 214 | true 215 | ${basedir}/lexer-parser-walker/src/main/antlr3/br/com/porcelli/parser/plsql 216 | 217 | 218 | ${basedir}/parsers/ 219 | true 220 | 221 | PLSQLLexer.g 222 | PLSQLParser.g 223 | PLSQLWalker.g 224 | 225 | 226 | 227 | 228 | 229 | 230 | lexer-parser-walker-composed-copy-resources-imports 231 | validate 232 | 233 | copy-resources 234 | 235 | 236 | true 237 | ${basedir}/lexer-parser-walker-composed/src/main/antlr3/br/com/porcelli/parser/plsql/imports 238 | 239 | 240 | ${basedir}/parsers/ 241 | true 242 | 243 | PLSQLCommons.g 244 | PLSQLKeys.g 245 | PLSQL_DMLParser.g 246 | SQLPLUSParser.g 247 | 248 | 249 | 250 | ${basedir}/parsers/walker-composed 251 | true 252 | 253 | PLSQL_DMLWalker.g 254 | PLSQLCommonsWalker.g 255 | 256 | 257 | 258 | 259 | 260 | 261 | lexer-parser-walker-composed-copy-resources-parser-lexer-walker 262 | validate 263 | 264 | copy-resources 265 | 266 | 267 | true 268 | ${basedir}/lexer-parser-walker-composed/src/main/antlr3/br/com/porcelli/parser/plsql 269 | 270 | 271 | ${basedir}/parsers/ 272 | true 273 | 274 | PLSQLLexer.g 275 | PLSQLParser.g 276 | 277 | 278 | 279 | ${basedir}/parsers/walker-composed 280 | true 281 | 282 | PLSQLWalker.g 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | -------------------------------------------------------------------------------- /tests/aggregate01.sql: -------------------------------------------------------------------------------- 1 | with 2 | codes2codelocales as 3 | ( 4 | select t6.cdl_name as cod_name, t7.cdl_name as cod_cod_name, t14.cod_oid 5 | from servicedesk.itsm_codes t14 6 | left outer join servicedesk.itsm_codes_locale t6 on (t6.cdl_cod_oid=t14.cod_oid) 7 | left outer join servicedesk.itsm_codes_locale t7 on (t7.cdl_cod_oid=t14.cod_cod_oid) 8 | ) 9 | , incident as 10 | ( 11 | select t1.*, 12 | c2cl1.cod_name as "closure code", c2cl1.cod_cod_name as "closure code parent", 13 | c2cl2.cod_name as "reason caused code", c2cl2.cod_cod_name as "reason caused code parent", 14 | t11.cdl_name "severity", t13.cdl_name "business impact", t16.cdl_name "priority", 15 | t2.rct_name "status", t12.rct_name "category", t99.rct_name "folder" 16 | from servicedesk.itsm_incidents t1 17 | join servicedesk.itsm_codes_locale t11 on (t1.inc_sev_oid=t11.cdl_cod_oid) 18 | join servicedesk.itsm_codes_locale t13 on (t1.inc_imp_oid=t13.cdl_cod_oid) 19 | join servicedesk.itsm_codes_locale t16 on (t1.inc_pri_oid=t16.cdl_cod_oid) 20 | join servicedeskrepo.rep_codes_text t2 on (t1.inc_sta_oid=t2.rct_rcd_oid) 21 | join servicedeskrepo.rep_codes_text t12 on (t1.inc_cat_oid=t12.rct_rcd_oid) 22 | join servicedeskrepo.rep_codes_text t99 on (t1.inc_poo_oid=t99.rct_rcd_oid) 23 | left outer join codes2codelocales c2cl1 on (t1.inc_clo_oid=c2cl1.cod_oid) 24 | left outer join codes2codelocales c2cl2 on (t1.inc_cla_oid=c2cl2.cod_oid) 25 | where t1."reg_created" between sysdate-1 and sysdate 26 | ) 27 | , workgrouphistory as 28 | ( 29 | select i.inc_id 30 | , max(t101.hin_subject) keep (dense_rank first order by (t101.reg_created)) as "first" 31 | , max(t101.hin_subject) keep (dense_rank last order by (t101.reg_created)) as "last" 32 | from 33 | servicedesk.itsm_historylines_incident t101 34 | join incident i on (t101.hin_inc_oid = i.inc_oid) 35 | -- from servicedesk.itsm_incidents i (t101.hin_inc_oid = i.inc_oid) 36 | where t101.hin_subject like 'to workgroup from%' 37 | -- and i."reg_created" between sysdate-1 and sysdate 38 | group by i.inc_id 39 | ) 40 | select 41 | incident.inc_id "id" 42 | ,incident."status" 43 | ,incident.inc_description "description" 44 | ,t4.wog_searchcode "workgroup" 45 | ,t5.per_searchcode "person" 46 | ,incident.inc_solution "solution" 47 | ,incident."closure code" 48 | ,incident."closure code parent" 49 | ,incident."reason caused code" 50 | ,incident."reason caused code parent" 51 | ,t10.cit_searchcode "ci" 52 | ,incident."severity" 53 | ,incident."category" 54 | ,incident."business impact" 55 | ,incident."priority" 56 | ,to_char(incident."reg_created", 'dd-mm-yy hh24:mi:ss') "registered" 57 | ,to_char(incident."inc_deadline", 'dd-mm-yy hh24:mi:ss') "deadline" 58 | ,to_char(incident."inc_actualfinish", 'dd-mm-yy hh24:mi:ss') "finish" 59 | ,t3.icf_incshorttext3 "message group" 60 | ,t3.icf_incshorttext4 "application" 61 | ,t3.icf_incshorttext2 "msg id" 62 | ,incident."folder" 63 | ,workgrouphistory."first" "first wg" 64 | ,workgrouphistory."last" "last wg" 65 | ,t102.hin_subject "frirst pri" 66 | from incident 67 | join servicedesk.itsm_inc_custom_fields t3 on (incident.inc_oid=t3.icf_inc_oid) 68 | join servicedesk.itsm_workgroups t4 on (incident.inc_assign_workgroup=t4.wog_oid) 69 | join workgrouphistory on (incident.inc_id = workgrouphistory.inc_id) 70 | left outer join servicedesk.itsm_persons t5 on (incident.inc_assign_person_to=t5.per_oid) 71 | left outer join servicedesk.itsm_configuration_items t10 on (incident.inc_cit_oid=t10.cit_oid) 72 | left outer join servicedesk.itsm_historylines_incident t102 on (incident.inc_oid = t102.hin_inc_oid and t102.hin_subject like 'priority set to%') 73 | -------------------------------------------------------------------------------- /tests/analytic_query02.sql: -------------------------------------------------------------------------------- 1 | select time_id, product 2 | , last_value(quantity ignore nulls) over (partition by product order by time_id) quantity 3 | , last_value(quantity respect nulls) over (partition by product order by time_id) quantity 4 | from ( select times.time_id, product, quantity 5 | from inventory partition by (product) 6 | right outer join times on (times.time_id = inventory.time_id) 7 | where times.time_id between to_date('01/04/01', 'dd/mm/yy') 8 | and to_date('06/04/01', 'dd/mm/yy')) 9 | order by 2,1 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/analytic_query03.sql: -------------------------------------------------------------------------------- 1 | select times.time_id, product, quantity from inventory 2 | partition by (product) 3 | right outer join times on (times.time_id = inventory.time_id) 4 | where times.time_id between to_date('01/04/01', 'dd/mm/yy') 5 | and to_date('06/04/01', 'dd/mm/yy') 6 | order by 2,1 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/analytic_query04.sql: -------------------------------------------------------------------------------- 1 | select deptno 2 | , ename 3 | , hiredate 4 | , listagg(ename, ',') within group (order by hiredate) over (partition by deptno) as employees 5 | from emp -------------------------------------------------------------------------------- /tests/analytic_query05.sql: -------------------------------------------------------------------------------- 1 | select metric_id ,bsln_guid ,timegroup ,obs_value as obs_value 2 | , cume_dist () over (partition by metric_id, bsln_guid, timegroup order by obs_value ) as cume_dist 3 | , count(1) over (partition by metric_id, bsln_guid, timegroup ) as n 4 | , row_number () over (partition by metric_id, bsln_guid, timegroup order by obs_value) as rrank 5 | , percentile_disc(:b7 ) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as mid_tail_value 6 | , max(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as max_val 7 | , min(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as min_val 8 | , avg(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as avg_val 9 | , stddev(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as sdev_val 10 | , percentile_cont(0.25) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_25 11 | , percentile_cont(0.5) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_50 12 | , percentile_cont(0.75) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_75 13 | , percentile_cont(0.90) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_90 14 | , percentile_cont(0.95) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_95 15 | , percentile_cont(0.99) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_99 16 | from timegrouped_rawdata d 17 | 18 | -------------------------------------------------------------------------------- /tests/analytic_query06.sql: -------------------------------------------------------------------------------- 1 | select trim(both ' ' from ' a ') from dual where trim(:a) is not null 2 | -------------------------------------------------------------------------------- /tests/analytic_query07.sql: -------------------------------------------------------------------------------- 1 | with 2 | clus_tab as ( 3 | select id, 4 | a.attribute_name aname, 5 | a.conditional_operator op, 6 | nvl(a.attribute_str_value, 7 | round(decode(a.attribute_name, n.col, 8 | a.attribute_num_value * n.scale + n.shift, 9 | a.attribute_num_value),4)) val, 10 | a.attribute_support support, 11 | a.attribute_confidence confidence 12 | from table(dbms_data_mining.get_model_details_km('km_sh_clus_sample')) t, 13 | table(t.rule.antecedent) a, 14 | km_sh_sample_norm n 15 | where a.attribute_name = n.col (+) and a.attribute_confidence > 0.55 16 | ), 17 | clust as ( 18 | select id, 19 | cast(collect(cattr(aname, op, to_char(val), support, confidence)) as cattrs) cl_attrs 20 | from clus_tab 21 | group by id 22 | ), 23 | custclus as ( 24 | select t.cust_id, s.cluster_id, s.probability 25 | from (select 26 | cust_id 27 | , cluster_set(km_sh_clus_sample, null, 0.2 using *) pset 28 | from km_sh_sample_apply_prepared 29 | where cust_id = 101362) t, 30 | table(t.pset) s 31 | ) 32 | select a.probability prob, a.cluster_id cl_id, 33 | b.attr, b.op, b.val, b.supp, b.conf 34 | from custclus a, 35 | (select t.id, c.* 36 | from clust t, 37 | table(t.cl_attrs) c) b 38 | where a.cluster_id = b.id 39 | order by prob desc, cl_id asc, conf desc, attr asc, val asc 40 | -------------------------------------------------------------------------------- /tests/bindvar01.sql: -------------------------------------------------------------------------------- 1 | insert into p 2 | ( 3 | a1, 4 | b2, 5 | c3, 6 | d4, 7 | e5, 8 | f6, 9 | g7, 10 | h8 11 | ) 12 | values 13 | ( :b1, :b2, :b3, :b4, :5, :6, :7, :8) 14 | 15 | -------------------------------------------------------------------------------- /tests/bindvar02.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from a 3 | where a=:3 4 | and b= : 4 5 | and c= :5and :a = :b 6 | 7 | -------------------------------------------------------------------------------- /tests/bindvar03.sql: -------------------------------------------------------------------------------- 1 | select count(*), max(scn) 2 | from 3 | ( 4 | select sp.bo#, sp.pmoptype, sp.scn, sp.flags 5 | from sumpartlog$ sp, sumdep$ sd 6 | where sd.sumobj# = :1 and sd.p_obj# = sp.bo# 7 | group by sp.bo#, sp.pmoptype, sp.scn, sp.flags 8 | minus 9 | select sp.bo#, sp.pmoptype, sp.scn, sp.flags 10 | from sumpartlog$ sp 11 | where sp.bo# not in 12 | ( 13 | select sk.detailobj# from sumkey$ sk where sk.sumobj# = :1 and sk.detailcolfunction in (2,3) 14 | ) 15 | and bitand(sp.flags, 2) != 2 and sp.pmoptype in (2,3,5,7) 16 | group by sp.bo#, sp.pmoptype, sp.scn, sp.flags 17 | ) 18 | where scn > : 2 19 | -------------------------------------------------------------------------------- /tests/bindvar04.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from 3 | ( 4 | select * 5 | from "rme" "rm" 6 | where "rm".a-interval:"sys_b_07" day(:"sys_b_08") to second(:"sys_b_09") 7 | ) 8 | -------------------------------------------------------------------------------- /tests/bindvar05.sql: -------------------------------------------------------------------------------- 1 | select object_name, object_id, 2 | decode(status, 'INVALID', 'TRUE', 'FALSE') invalid, 3 | 'TRUE' runnable, 4 | plsql_debug 5 | from sys.dba_objects o, dba_plsql_object_settings s 6 | where o.owner = :schema 7 | and s.owner = :schema 8 | and s.name = o.object_name 9 | and s.type = 'PACKAGE' 10 | and object_type = 'PACKAGE' 11 | and subobject_name is null 12 | and object_id not in ( select purge_object from recyclebin ) 13 | and upper(object_name) in upper(:name) 14 | -------------------------------------------------------------------------------- /tests/case_when01.sql: -------------------------------------------------------------------------------- 1 | select 2 | ROOT,LEV,OBJ,LinK,PaTH,cycle, 3 | case 4 | when (LEV - LEaD(LEV) over (order by orD)) < 0 then 0 5 | else 1 6 | end is_LEaF 7 | from T 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/case_when02.sql: -------------------------------------------------------------------------------- 1 | select 2 | STaLENESS, OSIZE, OBJ#, TYPE#, 3 | case 4 | when STaLENESS > .5 then 128 5 | when STaLENESS > .1 then 256 6 | else 0 7 | end + aFLaGS aFLaGS, 8 | STaTUS, 9 | SID, 10 | SERIaL#, 11 | PaRT#, 12 | BO# 13 | , 14 | case 15 | when is_FULL_EVENTS_HisTorY = 1 then SRC.Bor_LasT_STaTUS_TIME 16 | else 17 | case GREaTEST (NVL (WP.Bor_LasT_STaT_TIME, date '1900-01-01'), NVL (SRC.Bor_LasT_STaTUS_TIME, date '1900-01-01')) 18 | when date '1900-01-01' then null 19 | when WP.Bor_LasT_STaT_TIME then WP.Bor_LasT_STaT_TIME 20 | when SRC.Bor_LasT_STaTUS_TIME then SRC.Bor_LasT_STaTUS_TIME 21 | else null 22 | end 23 | end 24 | , 25 | case GREaTEST (NVL (WP.Bor_LasT_STaT_TIME, date '1900-01-01'), NVL (SRC.Bor_LasT_STaTUS_TIME, date '1900-01-01')) 26 | when date '1900-01-01' then null 27 | when WP.Bor_LasT_STaT_TIME then WP.Bor_LasT_STaT_TIME 28 | when SRC.Bor_LasT_STaTUS_TIME then SRC.Bor_LasT_STaTUS_TIME 29 | else null 30 | end 31 | from X 32 | 33 | -------------------------------------------------------------------------------- /tests/case_when03.sql: -------------------------------------------------------------------------------- 1 | select 2 | case (STaTUS) 3 | when 'N' then 1 4 | when 'B' then 2 5 | when 'a' then 3 6 | end as STaTE 7 | from VaLUE 8 | where KID=:B2 and RID=:B1 9 | 10 | -------------------------------------------------------------------------------- /tests/case_when04.sql: -------------------------------------------------------------------------------- 1 | select 2 | case when row_number() over (partition by bo# order by staleness, osize, obj#) = 1 then 32 else 0 end + 64 aflags 3 | from f 4 | -------------------------------------------------------------------------------- /tests/case_when05.sql: -------------------------------------------------------------------------------- 1 | select staleness 2 | , osize, obj# 3 | , type# 4 | , case when row_number() over (partition by bo# order by staleness, osize, obj#) = 1 then 64 else 0 end 5 | + 6 | case when row_number() over (partition by (select tcp0.bo# from tabcompart$ tcp0 where tcp0.obj#=st0.bo#) order by staleness, osize, obj#) = 1 then 32 7 | else 0 end aflags 8 | , 0 status 9 | , :b3 sid 10 | , :b2 serial# 11 | , part#, bo# 12 | from st0 -------------------------------------------------------------------------------- /tests/cast_multiset01.sql: -------------------------------------------------------------------------------- 1 | select t1.department_id, t2.* 2 | from hr_info t1, table(cast(multiset( 3 | select t3.last_name, t3.department_id, t3.salary 4 | from people t3 5 | where t3.department_id = t1.department_id) 6 | as people_tab_typ)) t2 7 | 8 | -------------------------------------------------------------------------------- /tests/cast_multiset02.sql: -------------------------------------------------------------------------------- 1 | select title 2 | from 3 | table(select courses from department where name = 'history') 4 | where name like '%etruscan%' 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/cast_multiset03.sql: -------------------------------------------------------------------------------- 1 | select 2 | 1 3 | , cursor(select 1 from dual) c1 4 | , cursor(select 2, 3 from dual) as c2 5 | from 6 | table(select 1 from dual) 7 | 8 | -------------------------------------------------------------------------------- /tests/cast_multiset04.sql: -------------------------------------------------------------------------------- 1 | select e1.last_name from employees e1 2 | where f( cursor(select e2.hire_date from employees e2 where e1.employee_id = e2.manager_id), e1.hire_date) = 1 3 | order by last_name -------------------------------------------------------------------------------- /tests/cast_multiset05.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from 3 | table 4 | ( 5 | function_name() 6 | ) 7 | -------------------------------------------------------------------------------- /tests/cast_multiset06.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast(collect(cattr(aname, op, to_char(val), support, confidence)) as cattrs) cl_attrs 3 | from a 4 | 5 | -------------------------------------------------------------------------------- /tests/cast_multiset07.sql: -------------------------------------------------------------------------------- 1 | select 2 | "a3"."r_id" "r_id" 3 | from 4 | "pe" "a3", 5 | "me" "a2" 6 | where 7 | "a3"."m_id"="a2"."m_id" 8 | and "a2"."mi_t" = 9 | any 10 | ((( 11 | select "a4"."sys$"."id" 12 | from the 13 | ( 14 | select "qa"."u_pkg"."getchartable" 15 | ( 16 | "qa"."u_pkg"."glist" 17 | ( 18 | cursor 19 | ( 20 | select "qa"."u_pkg"."glist" 21 | ( 22 | cursor 23 | ( 24 | select "a6"."mi_t" "mi_t" 25 | from "me" "a6" 26 | connect by "a6"."mi_uid"=prior "a6"."mi_id" 27 | start with "a6"."mi_t"=:b1 28 | ) 29 | ) 30 | "lst" 31 | from "sys"."dual" "a5" 32 | ) 33 | ) 34 | ) 35 | from dual 36 | ) 37 | "a4" 38 | ))) 39 | 40 | -------------------------------------------------------------------------------- /tests/cast_multiset08.sql: -------------------------------------------------------------------------------- 1 | select * from table (cast (f_int_date_varchar2() as table_int_date_varchar2)) 2 | -------------------------------------------------------------------------------- /tests/columns01.sql: -------------------------------------------------------------------------------- 1 | select a, b, 2 | a d, 3 | ddd as ddd, 4 | ddd as "dfdf", 5 | x as 6 | from dual 7 | 8 | -------------------------------------------------------------------------------- /tests/comment01.sql: -------------------------------------------------------------------------------- 1 | -- com1 2 | select * /* 3 | com2 */ 4 | from dual -- com3 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/condition01.sql: -------------------------------------------------------------------------------- 1 | select department_id, last_name, salary 2 | from employees x 3 | where salary > (select avg(salary) 4 | from employees 5 | where x.department_id = department_id) 6 | order by department_id 7 | 8 | -------------------------------------------------------------------------------- /tests/condition02.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from employees x 3 | where salary > (select avg(salary) from x) 4 | and 1 = 1 5 | and hiredate = sysdate 6 | and to_yminterval('01-00') < sysdate 7 | and to_yminterval('01-00') + x < sysdate 8 | 9 | -------------------------------------------------------------------------------- /tests/condition03.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from employees x 3 | where salary > (select avg(salary) from x) 4 | and 1 = 1 5 | and hiredate = sysdate 6 | and to_yminterval('01-00') < sysdate 7 | and to_yminterval('01-00') + x < sysdate 8 | or a=b 9 | and d=e 10 | 11 | -------------------------------------------------------------------------------- /tests/condition04.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from t 3 | where 4 | ( 5 | ( 6 | ( 7 | ( 8 | ( 9 | ( 10 | ( 11 | ( 12 | ( 13 | ( 14 | ( 15 | ( 16 | ( 17 | ( 18 | ( 19 | ( type = '2' ) or ( type = '3' ) 20 | ) and ( t.cde < 20 ) 21 | ) and ( t.se = 'xxx' ) 22 | ) and ( t.id = '000000000002' ) 23 | ) and ( ( t.attr_1 is null ) or ( t.attr_1 = '*' ) ) 24 | ) and ( ( t.attr_2 is null ) or ( t.attr_2 = '*' ) ) 25 | ) and ( ( t.attr_3 is null ) or ( t.attr_3 = '*' ) ) 26 | ) and ( ( t.attr_4 is null ) or ( t.attr_4 = '*' ) ) 27 | ) and ( ( t.attr_5 is null ) or ( t.attr_5 = '*' ) ) 28 | ) and ( ( t.itype is null ) or ( t.itype = '*' ) ) 29 | ) and ( ( t.inbr is null ) or ( t.inbr = '*' ) ) 30 | ) and ( ( t.stat = '01' ) or ( t.stat = '*' ) ) 31 | ) and ( ( t.orgn is null ) or ( t.orgn = '*' ) ) 32 | ) and ( t.mbr = '0000000000001' ) 33 | ) and ( t.nbr is null ) 34 | ) 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/condition05.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from t 3 | where 4 | ( t.type = '2' ) or ( t.type = '3' ) 5 | and t.cde < 20 6 | and t.se = 'xxx' 7 | and t.id = '000000000002' 8 | and ( ( t.sku_attr_1 is null ) or ( t.sku_attr_1 = '*' ) ) 9 | and ( ( t.sku_attr_2 is null ) or ( t.sku_attr_2 = '*' ) ) 10 | and ( ( t.sku_attr_3 is null ) or ( t.sku_attr_3 = '*' ) ) 11 | and ( ( t.sku_attr_4 is null ) or ( t.sku_attr_4 = '*' ) ) 12 | and ( ( t.sku_attr_5 is null ) or ( t.sku_attr_5 = '*' ) ) 13 | and ( ( t.itype is null ) or ( t.itype = '*' ) ) 14 | and ( ( t.bnbr is null ) or ( t.bnbr = '*' ) ) 15 | and ( ( t.stat = '01' ) or ( t.stat = '*' ) ) 16 | and ( ( t.orgn is null ) or ( t.orgn = '*' ) ) 17 | and ( t.mbr = '0000000000001' ) 18 | and ( t.nbr is null ) 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/condition06.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from t1, t2 3 | where (trunc(t1.timestamp) between to_date('110226','yymmdd') and to_date('110326','yymmdd')) 4 | and t1.code(+) = 'cn' 5 | and t1.id(+)=t2.id 6 | and t1.cid=t2.cid 7 | and t1.mid = 1245714070376993504 8 | and t1.tmst >= to_date('110226','yymmdd') 9 | -- note: this is possible too "column_spec outer_join_sign conditional_operator 10 | and shipper.alt_party_code(+) is null 11 | and t2.code(+) = 'sh' 12 | and t1.sid(+)=t2.sid 13 | and ( ( t1.scode like 'mmm' and t2.scode like 'xax' ) ) 14 | 15 | -------------------------------------------------------------------------------- /tests/condition07.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from append 3 | where 4 | -- note space between '>' and '=' 5 | (length(w.numer) > = 8) 6 | -------------------------------------------------------------------------------- /tests/condition08.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from "p" 3 | where 4 | -- note there are no parens around 231092 5 | ( ( "p"."id" in 231092 ) ) 6 | -------------------------------------------------------------------------------- /tests/condition09.sql: -------------------------------------------------------------------------------- 1 | select 2 | sum(nvl(pl.qty,0)) 3 | from 4 | oline ol, 5 | pline pl, 6 | blocation bl 7 | where 8 | ol.id = pl.id 9 | and pl.no = pl.no 10 | and bl.id = pl.id 11 | and 12 | ( 13 | (select count(*) from la.sa where pl.id like sa.bid) > 0 14 | or 15 | (select count(*) from la.sa where bl.id like sa.id) > 0 16 | ) 17 | -------------------------------------------------------------------------------- /tests/condition10.sql: -------------------------------------------------------------------------------- 1 | select department_id, last_name, salary 2 | from employees x 3 | where 4 | 1 = 1 5 | and 6 | ( 7 | ( 8 | HI 9 | ) 10 | > 11 | ( 12 | .1 * T.ROWCNT 13 | ) 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /tests/condition11.sql: -------------------------------------------------------------------------------- 1 | select distinct X 2 | from X,Y,Z 3 | where 4 | X.id = Z.id (+) 5 | and nvl(X.cid, '^') = nvl(Y.clientid (+), '^') 6 | and 0 = Lib.SKU(X.sid, nvl(Z.cid, '^')) 7 | 8 | -------------------------------------------------------------------------------- /tests/condition12.sql: -------------------------------------------------------------------------------- 1 | select * from v.e 2 | where 3 | cid <> rid 4 | and rid not in 5 | ( 6 | (select distinct rid from v.s ) 7 | union 8 | (select distinct rid from v.p ) 9 | ) 10 | and "timestamp" <= 1298505600000 11 | 12 | -------------------------------------------------------------------------------- /tests/condition14.sql: -------------------------------------------------------------------------------- 1 | select * from dual where trim(sxhnode_key) is not null 2 | 3 | -------------------------------------------------------------------------------- /tests/condition15.sql: -------------------------------------------------------------------------------- 1 | select 2 | "a3"."r_id" "r_id" 3 | from 4 | "pe" "a3", 5 | "me" "a2" 6 | where 7 | "a3"."m_id"="a2"."m_id" 8 | and "a2"."mi_t" = 9 | any 10 | ((( 11 | select "a4"."sys$"."id" 12 | from t "a4" 13 | ))) 14 | -------------------------------------------------------------------------------- /tests/condition16.sql: -------------------------------------------------------------------------------- 1 | select * from persons p 2 | where value(p) is of type(only employee_t) 3 | -------------------------------------------------------------------------------- /tests/connect_by01.sql: -------------------------------------------------------------------------------- 1 | with o as 2 | ( 3 | select 'a' obj, 'b' link from dual union all 4 | select 'a', 'c' from dual union all 5 | select 'c', 'd' from dual union all 6 | select 'd', 'c' from dual union all 7 | select 'd', 'e' from dual union all 8 | select 'e', 'e' from dual 9 | ) 10 | select 11 | connect_by_root obj root, 12 | level, 13 | obj,link, 14 | sys_connect_by_path(obj||'->'||link,','), 15 | connect_by_iscycle, 16 | connect_by_isleaf 17 | from o 18 | connect by nocycle obj=prior link 19 | start with obj='a' 20 | 21 | -------------------------------------------------------------------------------- /tests/connect_by02.sql: -------------------------------------------------------------------------------- 1 | select lpad(' ',2*(level-1)) || last_name org_chart, 2 | employee_id, manager_id, job_id 3 | from employees 4 | start with job_id = 'ad_pres' 5 | connect by prior employee_id = manager_id and level <= 2 6 | 7 | -------------------------------------------------------------------------------- /tests/connect_by03.sql: -------------------------------------------------------------------------------- 1 | select lpad(' ',2*(level-1)) || last_name org_chart, 2 | employee_id, manager_id, job_id 3 | from employees 4 | where job_id != 'fi_mgr' 5 | start with job_id = 'ad_vp' 6 | connect by prior employee_id = manager_id 7 | 8 | -------------------------------------------------------------------------------- /tests/connect_by04.sql: -------------------------------------------------------------------------------- 1 | select lpad(' ',2*(level-1)) || last_name org_chart, 2 | employee_id, manager_id, job_id 3 | from employees 4 | start with job_id = 'ad_vp' 5 | connect by prior employee_id = manager_id 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/connect_by05.sql: -------------------------------------------------------------------------------- 1 | with liste as ( 2 | select substr(:liste, instr(','||:liste||',', ',', 1, rn), 3 | instr(','||:liste||',', ',', 1, rn+1) - 4 | instr(','||:liste||',', ',', 1, rn)-1) valeur 5 | from ( 6 | select rownum rn from dual 7 | connect by level<=length(:liste) - length(replace(:liste,',',''))+1)) 8 | select trim(valeur) 9 | from liste 10 | -------------------------------------------------------------------------------- /tests/datetime01.sql: -------------------------------------------------------------------------------- 1 | select from_tz(cast(to_date('1999-12-01 11:00:00','yyyy-mm-dd hh:mi:ss') as timestamp), 'america/new_york') at time zone 'america/los_angeles' "west coast time" from dual 2 | -------------------------------------------------------------------------------- /tests/datetime02.sql: -------------------------------------------------------------------------------- 1 | select 2 | dbin.db_name, 3 | dbin.instance_name, 4 | dbin.version, 5 | case when s1.startup_time = s2.startup_time then 0 else 1 end as bounce, 6 | cast(s1.end_interval_time as date) as begin_time, 7 | cast(s2.end_interval_time as date) as end_time, 8 | round((cast( (case when s2.end_interval_time > s1.end_interval_time then s2.end_interval_time else s1.end_interval_time end) as date) 9 | - cast(s1.end_interval_time as date)) * 86400) as int_secs, 10 | case when (s1.status <> 0 or s2.status <> 0) then 1 else 0 end as err_detect, 11 | round( greatest( (extract(day from s2.flush_elapsed) * 86400) 12 | + (extract(hour from s2.flush_elapsed) * 3600) 13 | + (extract(minute from s2.flush_elapsed) * 60) 14 | + extract(second from s2.flush_elapsed), 15 | (extract(day from s1.flush_elapsed) * 86400) 16 | + (extract(hour from s1.flush_elapsed) * 3600) 17 | + (extract(minute from s1.flush_elapsed) * 60) 18 | + extract(second from s1.flush_elapsed),0 ) 19 | ) as max_flush_secs 20 | from wrm$_snapshot s1 , wrm$_database_instance dbin , wrm$_snapshot s2 21 | where s1.dbid = :dbid 22 | and s2.dbid = :dbid 23 | and s1.instance_number = :inst_num 24 | and s2.instance_number = :inst_num 25 | and s1.snap_id = :bid 26 | and s2.snap_id = :eid 27 | and dbin.dbid = s1.dbid 28 | and dbin.instance_number = s1.instance_number 29 | and dbin.startup_time = s1.startup_time 30 | 31 | -------------------------------------------------------------------------------- /tests/datetime03.sql: -------------------------------------------------------------------------------- 1 | select 2 | timestamp '2009-10-29 01:30:00' at time zone 'us/pacific'from dual 3 | 4 | -------------------------------------------------------------------------------- /tests/datetime04.sql: -------------------------------------------------------------------------------- 1 | select 2 | timestamp '2009-10-29 01:30:00' 3 | from dual 4 | 5 | -------------------------------------------------------------------------------- /tests/datetime05.sql: -------------------------------------------------------------------------------- 1 | select date '1900-01-01' from dual 2 | -------------------------------------------------------------------------------- /tests/dblink01.sql: -------------------------------------------------------------------------------- 1 | select last_name, department_name 2 | from employees@remote, departments 3 | where employees.department_id = departments.department_id 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/explain01.sql: -------------------------------------------------------------------------------- 1 | explain plan 2 | set statement_id = 'raise in tokyo' 3 | into plan_table 4 | for update employees 5 | set salary = salary * 1.10 6 | where department_id = 7 | (select department_id from departments 8 | where location_id = 1700) 9 | -------------------------------------------------------------------------------- /tests/flashback01.sql: -------------------------------------------------------------------------------- 1 | select value(p$) from "XDB"."XDB$SCHEMA" as of snapshot(:2) p$ where SYS_NC_OID$ = :1 2 | -------------------------------------------------------------------------------- /tests/for_update01.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select * from employees) 2 | for update of employee_id 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/for_update02.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/for_update03.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/for_update04.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id nowait 3 | 4 | -------------------------------------------------------------------------------- /tests/for_update05.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id wait 10 3 | 4 | -------------------------------------------------------------------------------- /tests/for_update06.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id skip locked 3 | 4 | -------------------------------------------------------------------------------- /tests/for_update07.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of a, b.c, d skip locked 3 | 4 | -------------------------------------------------------------------------------- /tests/for_update08.sql: -------------------------------------------------------------------------------- 1 | select su.ttype ,su.cid ,su.s_id ,sessiontimezone 2 | from sku su 3 | where (nvl(su.up,'n')='n' and su.ttype=:b0) 4 | for update of su.up 5 | order by su.d 6 | -------------------------------------------------------------------------------- /tests/function01.sql: -------------------------------------------------------------------------------- 1 | select decode(decode(decode( (select count(1) from dual), a, 1, 0), 0, 1), 1, 0) from dual 2 | -- select decode(decode(decode(decode(x, 0, 1) , 0, 1), 1, 0 ), 0, 1) from dual 3 | -------------------------------------------------------------------------------- /tests/function02.sql: -------------------------------------------------------------------------------- 1 | select set(x) from dual 2 | -------------------------------------------------------------------------------- /tests/function03.sql: -------------------------------------------------------------------------------- 1 | select trim(both from con.ke) 2 | from dual 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/function04.sql: -------------------------------------------------------------------------------- 1 | select lnnvl( 2 > 1) from dual 2 | -------------------------------------------------------------------------------- /tests/function05.sql: -------------------------------------------------------------------------------- 1 | select count(*) 2 | from employees 3 | where lnnvl(commission_pct >= .2) 4 | -------------------------------------------------------------------------------- /tests/function06.sql: -------------------------------------------------------------------------------- 1 | call dbms_scheduler.auto_purge ( ) 2 | -------------------------------------------------------------------------------- /tests/groupby01.sql: -------------------------------------------------------------------------------- 1 | select :b3 as l_snap_id , :b2 as p_dbid , :b1 as p_instance_number , nvl(pid, -9) pid , nvl(serial#, -9) serial# , decode(pid, null, null, max(spid)) spid , 2 | decode(pid, null, null, max(program)) program , decode(pid, null, null, max(background)) background , sum(pga_used_mem) pga_used_mem , 3 | sum(pga_alloc_mem) pga_alloc_mem , sum(pga_freeable_mem) pga_freeable_mem , max(pga_alloc_mem) max_pga_alloc_mem , max(pga_max_mem) max_pga_max_mem , 4 | decode(pid, null, avg(pga_alloc_mem), null) avg_pga_alloc_mem , decode(pid, null, stddev(pga_alloc_mem), null) stddev_pga_alloc_mem , 5 | decode(pid, null, count(pid), null) num_processes 6 | from v$process 7 | where program != 'pseudo' 8 | group by grouping sets ( (pid, serial#), () ) 9 | 10 | -------------------------------------------------------------------------------- /tests/groupby02.sql: -------------------------------------------------------------------------------- 1 | select 2 | decode(pid, null, null, max(program)) program , decode(pid, null, null, max(background)) background , sum(pga_used_mem) pga_used_mem , 3 | sum(pga_alloc_mem) pga_alloc_mem , sum(pga_freeable_mem) pga_freeable_mem , max(pga_alloc_mem) max_pga_alloc_mem , max(pga_max_mem) max_pga_max_mem , 4 | decode(pid, null, avg(pga_alloc_mem), null) avg_pga_alloc_mem , decode(pid, null, stddev(pga_alloc_mem), null) stddev_pga_alloc_mem , 5 | decode(pid, null, count(pid), null) num_processes 6 | from v$process 7 | where program != 'pseudo' 8 | group by grouping sets ( (), ((pid+1), serial#) ) 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/groupby03.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( a, 1 ) 4 | 5 | -------------------------------------------------------------------------------- /tests/groupby04.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( (a),1 ) 4 | -------------------------------------------------------------------------------- /tests/groupby05.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( ((a),b), ((a),b) ) 4 | 5 | -------------------------------------------------------------------------------- /tests/groupby06.sql: -------------------------------------------------------------------------------- 1 | select 2 | prod_category, prod_subcategory, country_id, cust_city, count(*) 3 | from products, sales, customers 4 | where sales.prod_id = products.prod_id 5 | and sales.cust_id=customers.cust_id 6 | and sales.time_id = '01-oct-00' 7 | and customers.cust_year_of_birth between 1960 and 1970 8 | group by grouping sets 9 | ( 10 | (prod_category, prod_subcategory, country_id, cust_city), 11 | (prod_category, prod_subcategory, country_id), 12 | (prod_category, prod_subcategory), 13 | country_id 14 | ) 15 | order by prod_category, prod_subcategory, country_id, cust_city 16 | -------------------------------------------------------------------------------- /tests/groupby07.sql: -------------------------------------------------------------------------------- 1 | select decode((tt || tc), '56', count(distinct cn), '57', sum(nu)) as q 2 | from t 3 | where tt='500' 4 | and tc in ('6','7') 5 | and to_char(c,'mm') = '03' 6 | having sum(nu) > 0 7 | group by tn, ui, (tt || tc) 8 | order by 1 9 | -------------------------------------------------------------------------------- /tests/interval01.sql: -------------------------------------------------------------------------------- 1 | select (systimestamp - order_date) day(9) to second from orders 2 | where order_id = 2458 3 | -------------------------------------------------------------------------------- /tests/interval02.sql: -------------------------------------------------------------------------------- 1 | select interval '42' day from dual 2 | -------------------------------------------------------------------------------- /tests/interval03.sql: -------------------------------------------------------------------------------- 1 | select 2 | interval '4 5:12:10.222' day to second(3) 3 | ,interval '4 5:12' day to minute 4 | ,interval '400 5' day(3) to hour 5 | ,interval '400' day(3) 6 | ,interval '11:12:10.2222222' hour to second(7) 7 | ,interval '11:20' hour to minute 8 | ,interval '10' hour 9 | ,interval '10:22' minute to second 10 | ,interval '10' minute 11 | ,interval '4' day 12 | ,interval '25' hour 13 | ,interval '40' minute 14 | ,interval '120' hour(3) 15 | ,interval '30.12345' second(2,4) 16 | ,interval :a day 17 | from dual 18 | -------------------------------------------------------------------------------- /tests/interval04.sql: -------------------------------------------------------------------------------- 1 | select interval'20' day - interval'240' hour from dual 2 | -------------------------------------------------------------------------------- /tests/join01.sql: -------------------------------------------------------------------------------- 1 | select d.department_id as d_dept_id, e.department_id as e_dept_id, e.last_name 2 | from departments d full outer join employees e 3 | on d.department_id = e.department_id 4 | order by d.department_id, e.last_name 5 | 6 | -------------------------------------------------------------------------------- /tests/join02.sql: -------------------------------------------------------------------------------- 1 | select department_id as d_e_dept_id, e.last_name 2 | from departments d full outer join employees e 3 | using (department_id) 4 | order by department_id, e.last_name 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/join03.sql: -------------------------------------------------------------------------------- 1 | select d.department_id, e.last_name 2 | from m.departments d right outer join n.employees e 3 | on d.department_id = e.department_id 4 | order by d.department_id, e.last_name 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/join04.sql: -------------------------------------------------------------------------------- 1 | select d.department_id, e.last_name 2 | from departments d, employees e 3 | where d.department_id = e.department_id(+) 4 | order by d.department_id, e.last_name 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/join05.sql: -------------------------------------------------------------------------------- 1 | select times.time_id, product, quantity from inventory 2 | partition by (product) 3 | right outer join times on (times.time_id = inventory.time_id) 4 | where times.time_id between to_date('01/04/01', 'dd/mm/yy') 5 | and to_date('06/04/01', 'dd/mm/yy') 6 | order by 2,1 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/join06.sql: -------------------------------------------------------------------------------- 1 | select * from dual d1 2 | join dual d2 on (d1.dummy = d2.dummy) 3 | join dual d3 on(d1.dummy = d3.dummy) 4 | join dual on(d1.dummy = dual.dummy) 5 | 6 | -------------------------------------------------------------------------------- /tests/join07.sql: -------------------------------------------------------------------------------- 1 | select * from t1 2 | join t2 tt2 using(c) 3 | join t3 tt3 using(d) 4 | join t3 using(d) 5 | 6 | -------------------------------------------------------------------------------- /tests/join08.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1 2 | join (select * from dual) tt2 using(dummy) 3 | join (select * from dual) using(dummy) 4 | join (select * from dual) d on(d.dummy=tt3.dummy) 5 | inner join (select * from dual) tt2 using(dummy) 6 | inner join (select * from dual) using(dummy) 7 | inner join (select * from dual) d on(d.dummy=t1.dummy) 8 | 9 | -------------------------------------------------------------------------------- /tests/join09.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1 2 | left outer join (select * from dual) tt2 using(dummy) 3 | left outer join (select * from dual) using(dummy) 4 | left outer join (select * from dual) d on(d.dummy=tt3.dummy) 5 | inner join (select * from dual) tt2 using(dummy) 6 | inner join (select * from dual) using(dummy) 7 | inner join (select * from dual) d on(d.dummy=t1.dummy) 8 | 9 | -------------------------------------------------------------------------------- /tests/join10.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, 2 | ( 3 | dual left outer join (select * from dual) tt2 using(dummy) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /tests/join11.sql: -------------------------------------------------------------------------------- 1 | select * from t1, ( t2 left outer join t3 using(dummy) ) 2 | -------------------------------------------------------------------------------- /tests/join12.sql: -------------------------------------------------------------------------------- 1 | select * from dual,( dual left outer join tt2 using(dummy) ) 2 | 3 | -------------------------------------------------------------------------------- /tests/join13.sql: -------------------------------------------------------------------------------- 1 | select * from t1, 2 | (((( 3 | t2 left outer join t3 using(dummy) 4 | )))) 5 | -------------------------------------------------------------------------------- /tests/join14.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, 2 | ( 3 | ( 4 | ( 5 | dual t2 join dual t3 using(dummy) ) 6 | left outer join dual t4 using(dummy) ) 7 | left outer join dual t5 using(dummy) ) 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/join15.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, ( dual t2 join dual t3 using(dummy)) left outer join dual t4 using (dummy) 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/join16.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, 2 | dual t2 join dual t3 using(dummy) 3 | left outer join dual t4 using(dummy) 4 | left outer join dual t5 using(dummy) 5 | 6 | -------------------------------------------------------------------------------- /tests/join17.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from hdr a 3 | inner join sh s 4 | inner join ca c 5 | on c.id = s.id 6 | on a.va = s.va 7 | 8 | -------------------------------------------------------------------------------- /tests/join18.sql: -------------------------------------------------------------------------------- 1 | select department_id as d_e_dept_id, e.last_name 2 | from departments 3 | full outer join employees on (a=b) 4 | left outer join employees on (a=b) 5 | right outer join employees on (a=b) 6 | join employees on (a=b) 7 | inner join employees on (a=b) 8 | cross join employees 9 | natural join employees 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/join19.sql: -------------------------------------------------------------------------------- 1 | select d1.*, d2.* from dual d1 cross join dual d2 2 | -------------------------------------------------------------------------------- /tests/join20.sql: -------------------------------------------------------------------------------- 1 | select d1.*, d2.* from dual cross join dual 2 | -------------------------------------------------------------------------------- /tests/join21.sql: -------------------------------------------------------------------------------- 1 | select * from sys.dual natural join sys.dual 2 | 3 | -------------------------------------------------------------------------------- /tests/keywordasidentifier01.sql: -------------------------------------------------------------------------------- 1 | select timestamp, avg, cume_dist from nulls 2 | -------------------------------------------------------------------------------- /tests/keywordasidentifier02.sql: -------------------------------------------------------------------------------- 1 | select m.model from model 2 | -------------------------------------------------------------------------------- /tests/keywordasidentifier03.sql: -------------------------------------------------------------------------------- 1 | select ind.index_owner,ind.index_name,ind.uniqueness 2 | , ind.status,ind.index_type,ind.temporary, ind.partitioned,ind.funcidx_status 3 | , ind.join_index,ind.columns,ie.column_expression 4 | , ind.index_name sdev_link_name,'INDEX' sdev_link_type, ind.index_owner sdev_link_owner 5 | from 6 | ( 7 | select index_owner,table_owner,index_name,uniqueness, status,index_type,temporary, partitioned,funcidx_status, join_index 8 | , max(decode(position,1 ,column_name))|| max(decode(position,2 ,', '||column_name))|| max(decode(position,3 ,', '||column_name))|| max(decode(position,4 ,', '||column_name))|| max(decode(position,5 ,', '||column_name))|| max(decode(position,6 ,', '||column_name))|| max(decode(position,7 ,', '||column_name))|| max(decode(position,8 ,', '||column_name))|| max(decode(position,9 ,', '||column_name))|| max(decode(position,10,', '||column_name)) columns 9 | 10 | from 11 | ( 12 | select di.owner index_owner,dc.table_owner,dc.index_name,di.uniqueness, di.status, di.index_type, di.temporary, di.partitioned,di.funcidx_status, di.join_index 13 | , dc.column_name,dc.column_position position 14 | from all_ind_columns dc,all_indexes di 15 | where dc.table_owner = :OBJECT_OWNER 16 | and dc.table_name = :OBJECT_NAME 17 | and dc.index_name = di.index_name 18 | and dc.index_owner = di.owner 19 | ) 20 | group by index_owner,table_owner,index_name,uniqueness, status, index_type, temporary, partitioned,funcidx_status, join_index 21 | ) ind, 22 | ALL_IND_EXPRESSIONS ie 23 | where ind.index_name = ie.index_name(+) 24 | and ind.index_owner = ie.index_owner(+) 25 | -------------------------------------------------------------------------------- /tests/keywordasidentifier04.sql: -------------------------------------------------------------------------------- 1 | select bs.keep keep, bs.keep_until keep_until 2 | from v$backup_set bs 3 | union all 4 | select null keep, null keep_until 5 | from v$backup_piece bp 6 | 7 | -------------------------------------------------------------------------------- /tests/keywordasidentifier05.sql: -------------------------------------------------------------------------------- 1 | select exception from exception -------------------------------------------------------------------------------- /tests/lexer01.sql: -------------------------------------------------------------------------------- 1 | select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2 2 | 3 | -------------------------------------------------------------------------------- /tests/lexer02.sql: -------------------------------------------------------------------------------- 1 | select 'A' | | 'B' from dual 2 | 3 | -------------------------------------------------------------------------------- /tests/lexer03.sql: -------------------------------------------------------------------------------- 1 | select :1, :X, :1 + 1, 1 + :2 from A where A=:3 and b= : 4 and c= :5and :A = :b 2 | 3 | -------------------------------------------------------------------------------- /tests/lexer04.sql: -------------------------------------------------------------------------------- 1 | select tbl$or$idx$part$num("sys"."wrh$_seg_stat",0,4,0,"rowid") as c1 from t1 2 | -------------------------------------------------------------------------------- /tests/lexer05.sql: -------------------------------------------------------------------------------- 1 | select tbl$or$idx$part$num("sys"."wrh:_seg_stat",0,4,0,"rowid") as c1 from t1 2 | -------------------------------------------------------------------------------- /tests/like01.sql: -------------------------------------------------------------------------------- 1 | select last_name 2 | from employees 3 | where last_name 4 | like '%a\_b%' escape '\' 5 | order by last_name 6 | -------------------------------------------------------------------------------- /tests/merge01.sql: -------------------------------------------------------------------------------- 1 | merge into bonuses d 2 | using (select employee_id.* from employees) s 3 | on (employee_id = a) 4 | when matched then update set d.bonus = bonus 5 | delete where (salary > 8000) 6 | when not matched then insert (d.employee_id, d.bonus) 7 | values (s.employee_id, s.salary) 8 | where (s.salary <= 8000) 9 | 10 | -------------------------------------------------------------------------------- /tests/merge02.sql: -------------------------------------------------------------------------------- 1 | merge into bonuses d 2 | using (select employee_id.* from employees) s 3 | on (employee_id = a) 4 | when not matched then insert (d.employee_id, d.bonus) 5 | values (s.employee_id, s.salary) 6 | where (s.salary <= 8000) 7 | when matched then update set d.bonus = bonus 8 | delete where (salary > 8000) 9 | 10 | -------------------------------------------------------------------------------- /tests/merge03.sql: -------------------------------------------------------------------------------- 1 | merge /*+ dynamic_sampling(mm 4) dynamic_sampling_est_cdn(mm) 2 | dynamic_sampling(m 4) dynamic_sampling_est_cdn(m) */ 3 | 4 | into sys.mon_mods_all$ mm 5 | using 6 | ( 7 | select decode(grouping_id(tp.bo#,tsp.pobj#,m.obj#),3,tp.bo#,1,tsp.pobj#,m.obj#) obj#, sum(m.inserts) inserts, sum(m.updates) updates, sum(m.deletes) deletes, 8 | decode(sum(bitand(m.flags,1)),0,0,1) +decode(sum(bitand(m.flags,2)),0,0,2) +decode(sum(bitand(m.flags,4)),0,0,4) flags, sum(m.drop_segments) drop_segments 9 | from sys.mon_mods$ m, sys.tabcompart$ tp, sys.tabsubpart$ tsp 10 | where m.obj# = tsp.obj# and tp.obj# = tsp.pobj# 11 | group by rollup(tp.bo#,tsp.pobj#,m.obj#) having grouping_id(tp.bo#,tsp.pobj#,m.obj#) < 7 12 | ) v on 13 | (mm.obj# = v.obj#) 14 | when matched then 15 | update set mm.inserts = mm.inserts + v.inserts, mm.updates = mm.updates + v.updates, mm.deletes = mm.deletes + v.deletes, 16 | mm.flags = mm.flags + v.flags - bitand(mm.flags,v.flags) , mm.drop_segments = mm.drop_segments + v.drop_segments 17 | when not matched then insert values (v.obj#, v.inserts, v.updates, v.deletes, sysdate, v.flags, v.drop_segments) 18 | -------------------------------------------------------------------------------- /tests/merge04.sql: -------------------------------------------------------------------------------- 1 | merge /*+ dynamic_sampling(mm 4) dynamic_sampling_est_cdn(mm) 2 | dynamic_sampling(m 4) dynamic_sampling_est_cdn(m) */ 3 | 4 | into sys.mon_mods_all$ mm 5 | using 6 | ( 7 | select decode(grouping_id(tp.bo#,tsp.pobj#,m.obj#),3,tp.bo#,1,tsp.pobj#,m.obj#) obj#, sum(m.inserts) inserts, sum(m.updates) updates, sum(m.deletes) deletes, 8 | decode(sum(bitand(m.flags,1)),0,0,1) +decode(sum(bitand(m.flags,2)),0,0,2) +decode(sum(bitand(m.flags,4)),0,0,4) flags, sum(m.drop_segments) drop_segments 9 | from sys.mon_mods$ m, sys.tabcompart$ tp, sys.tabsubpart$ tsp 10 | where m.obj# = tsp.obj# and tp.obj# = tsp.pobj# 11 | group by rollup(tp.bo#,tsp.pobj#,m.obj#) having grouping_id(tp.bo#,tsp.pobj#,m.obj#) < 7 12 | order by 1, 2, 3 13 | ) v on 14 | (mm.obj# = v.obj#) 15 | when matched then 16 | update set mm.inserts = mm.inserts + v.inserts, mm.updates = mm.updates + v.updates, mm.deletes = mm.deletes + v.deletes, 17 | mm.flags = mm.flags + v.flags - bitand(mm.flags,v.flags) , mm.drop_segments = mm.drop_segments + v.drop_segments 18 | when not matched then insert values (v.obj#, v.inserts, v.updates, v.deletes, sysdate, v.flags, v.drop_segments) 19 | -------------------------------------------------------------------------------- /tests/model_clause01.sql: -------------------------------------------------------------------------------- 1 | select country,prod,year,s 2 | from sales_view_ref 3 | model 4 | partition by (country) 5 | dimension by (prod, year) 6 | measures (sale s) 7 | ignore nav 8 | -- cell_reference_options 9 | unique dimension 10 | -- here starts model_rules_clause 11 | rules upsert sequential order 12 | ( 13 | s[prod='mouse pad', year=2001] = s['mouse pad', 1999] + s['mouse pad', 2000], 14 | s['standard mouse', 2002] = s['standard mouse', 2001] 15 | ) 16 | order by country, prod, year 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/model_clause02.sql: -------------------------------------------------------------------------------- 1 | select country, year, sale, csum 2 | from 3 | (select country, year, sum(sale) sale 4 | from sales_view_ref 5 | group by country, year 6 | ) 7 | model dimension by (country, year) 8 | measures (sale, 0 csum) 9 | rules (csum[any, any]= 10 | sum(sale) over (partition by country 11 | order by year 12 | rows unbounded preceding) 13 | ) 14 | order by country, year 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/model_clause03.sql: -------------------------------------------------------------------------------- 1 | select country,prod,year,s 2 | from sales_view_ref 3 | model 4 | partition by (country) 5 | dimension by (prod, year) 6 | measures (sale s) 7 | ignore nav 8 | unique dimension 9 | rules upsert sequential order 10 | ( 11 | s[prod='mouse pad'] = 1, 12 | s['standard mouse'] = 2 13 | ) 14 | order by country, prod, year 15 | 16 | -------------------------------------------------------------------------------- /tests/model_clause04.sql: -------------------------------------------------------------------------------- 1 | select country, year, sale, csum 2 | from 3 | (select country, year, salex sale 4 | from sales_view_ref 5 | group by country, year 6 | ) 7 | model dimension by (country, year) 8 | measures (sale, 0 csum) 9 | rules 10 | ( 11 | s['standard mouse'] = 2 12 | ) 13 | order by country, year 14 | 15 | -------------------------------------------------------------------------------- /tests/model_clause05.sql: -------------------------------------------------------------------------------- 1 | select country, year, sale, csum 2 | from 3 | (select country, year, salex sale 4 | from sales_view_ref 5 | group by country, year 6 | ) m 7 | model dimension by (country, year) 8 | measures (sale, 0 csum) 9 | rules 10 | ( 11 | s['standard mouse'] = 2 12 | ) 13 | order by country, year 14 | 15 | -------------------------------------------------------------------------------- /tests/numbers01.sql: -------------------------------------------------------------------------------- 1 | select 25 2 | , +6.34 3 | , 0.5 4 | , 25e-03 5 | , -1 -- Here are some valid floating-point number literals: 6 | , 25f 7 | , +6.34F 8 | , 0.5d 9 | , -1D 10 | , (sysdate -1d) -- here we substract "one" in decimal format 11 | , sysdate -1m -- here we substract "one" and "m" is column's alias 12 | , sysdate -1dm 13 | from dual 14 | 15 | -------------------------------------------------------------------------------- /tests/object_access01.sql: -------------------------------------------------------------------------------- 1 | select 2 | extractvalue(value(t), '/select_list_item/pos') + 1 pos, 3 | extractvalue(value(t), '/select_list_item/value') res, 4 | extractvalue(value(t), '/select_list_item/nonnulls') nonnulls, 5 | extractvalue(value(t), '/select_list_item/ndv') ndv, 6 | extractvalue(value(t), '/select_list_item/split') split, 7 | extractvalue(value(t), '/select_list_item/rsize') rsize, 8 | extractvalue(value(t), '/select_list_item/rowcnt') rowcnt, 9 | extract(value(t), '/select_list_item/hash_val').getclobval() hashval 10 | from 11 | table 12 | ( 13 | xmlsequence 14 | ( 15 | extract(:b1 , '/process_result/select_list_item') 16 | ) 17 | ) t 18 | 19 | -------------------------------------------------------------------------------- /tests/order_by01.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by 1 2 | -------------------------------------------------------------------------------- /tests/order_by02.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by 1 asc 2 | -------------------------------------------------------------------------------- /tests/order_by03.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by m.year, m.title, f(a) 2 | -------------------------------------------------------------------------------- /tests/order_by04.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by a nulls first, b nulls last 2 | -------------------------------------------------------------------------------- /tests/order_by05.sql: -------------------------------------------------------------------------------- 1 | select * from dual order siblings by a nulls first, b nulls last, c nulls last, d nulls last, e nulls last -------------------------------------------------------------------------------- /tests/order_by06.sql: -------------------------------------------------------------------------------- 1 | with a as (select * from dual order by 1) select * from a 2 | -------------------------------------------------------------------------------- /tests/pivot01.sql: -------------------------------------------------------------------------------- 1 | select * from pivot_table 2 | unpivot (yearly_total for order_mode in (store as 'direct', 3 | internet as 'online')) 4 | order by year, order_mode 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/pivot02.sql: -------------------------------------------------------------------------------- 1 | select * from ( 2 | select times_purchased as "puchase frequency", state_code 3 | from customers t 4 | ) 5 | pivot xml 6 | ( 7 | count(state_code) 8 | for state_code in (select state_code from preferred_states) 9 | ) 10 | order by 1 11 | 12 | -------------------------------------------------------------------------------- /tests/pivot03.sql: -------------------------------------------------------------------------------- 1 | select * from ( 2 | select times_purchased as "purchase frequency", state_code 3 | from customers t 4 | ) 5 | pivot xml 6 | ( 7 | count(state_code) 8 | for state_code in (any) 9 | ) 10 | order by 1 11 | 12 | -------------------------------------------------------------------------------- /tests/pivot04.sql: -------------------------------------------------------------------------------- 1 | select value 2 | from 3 | ( 4 | ( 5 | select 6 | 'a' v1, 7 | 'e' v2, 8 | 'i' v3, 9 | 'o' v4, 10 | 'u' v5 11 | from dual 12 | ) 13 | unpivot 14 | ( 15 | value 16 | for value_type in 17 | (v1,v2,v3,v4,v5) 18 | ) 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /tests/pivot05.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from (select customer_id, product_code, quantity 3 | from pivot_test) 4 | pivot xml (sum(quantity) as sum_quantity for (product_code) in (select distinct product_code 5 | from pivot_test)) 6 | -------------------------------------------------------------------------------- /tests/pivot06.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from (select product_code, quantity 3 | from pivot_test) 4 | pivot xml (sum(quantity) as sum_quantity for (product_code) in (select distinct product_code 5 | from pivot_test 6 | where id < 10)) -------------------------------------------------------------------------------- /tests/pivot07.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from (select customer_id, product_code, quantity 3 | from pivot_test) 4 | pivot (sum(quantity) as sum_quantity for (product_code) in ('a' as a, 'b' as b, 'c' as c)) 5 | order by customer_id 6 | -------------------------------------------------------------------------------- /tests/pivot08.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from (select product_code, quantity 3 | from pivot_test) 4 | pivot (sum(quantity) as sum_quantity for (product_code) in ('a' as a, 'b' as b, 'c' as c)) -------------------------------------------------------------------------------- /tests/pivot09.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from (s join d using(c)) 3 | pivot 4 | ( 5 | max(c_c_p) as max_ccp 6 | , max(d_c_p) max_dcp 7 | , max(d_x_p) dxp 8 | , count(1) cnt 9 | for (i, p) in 10 | ( 11 | (1,1) as one_one, 12 | (1,2) as one_two, 13 | (1,3) as one_three, 14 | (2,1) as two_one, 15 | (2,2) as two_two, 16 | (2,3) as two_three 17 | ) 18 | ) 19 | where d_t = 'p' 20 | -------------------------------------------------------------------------------- /tests/pivot10.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from s join d using(c) 3 | pivot 4 | ( 5 | max(c_c_p) as max_ccp 6 | , max(d_c_p) max_dcp 7 | , max(d_x_p) dxp 8 | , count(1) cnt 9 | for (i, p) in 10 | ( 11 | (1,1) as one_one, 12 | (1,2) as one_two, 13 | (1,3) as one_three, 14 | (2,1) as two_one, 15 | (2,2) as two_two, 16 | (2,3) as two_three 17 | ) 18 | ) 19 | where d_t = 'p' 20 | -------------------------------------------------------------------------------- /tests/pivot11.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from s 3 | pivot 4 | ( 5 | max(c_c_p) as max_ccp 6 | , max(d_c_p) max_dcp 7 | , max(d_x_p) dxp 8 | , count(1) cnt 9 | for (i, p) in 10 | ( 11 | (1,1) as one_one, 12 | (1,2) as one_two, 13 | (1,3) as one_three, 14 | (2,1) as two_one, 15 | (2,2) as two_two, 16 | (2,3) as two_three 17 | ) 18 | ) 19 | join d using(c) 20 | where d_t = 'p' 21 | -------------------------------------------------------------------------------- /tests/pivot12.sql: -------------------------------------------------------------------------------- 1 | select value from 2 | ( 3 | ( 4 | select 5 | 'a' v1, 6 | 'e' v2, 7 | 'i' v3, 8 | 'o' v4, 9 | 'u' v5 10 | from dual 11 | ) 12 | unpivot include nulls 13 | ( 14 | value 15 | for value_type in 16 | (v1, v2,v3,v4,v5) -- Also can give ANY here. 17 | ) 18 | ) -------------------------------------------------------------------------------- /tests/query_factoring01.sql: -------------------------------------------------------------------------------- 1 | with 2 | reports_to_101 (eid, emp_last, mgr_id, reportlevel) as 3 | ( 4 | select employee_id, last_name, manager_id, 0 reportlevel 5 | from employees 6 | where employee_id = 101 7 | union all 8 | select e.employee_id, e.last_name, e.manager_id, reportlevel+1 9 | from reports_to_101 r, employees e 10 | where r.eid = e.manager_id 11 | ) 12 | select eid, emp_last, mgr_id, reportlevel 13 | from reports_to_101 r, auto a 14 | where r.c1 = a.c2 15 | order by reportlevel, eid 16 | 17 | -------------------------------------------------------------------------------- /tests/query_factoring02.sql: -------------------------------------------------------------------------------- 1 | with 2 | reports_to_101 (eid, emp_last, mgr_id, reportlevel, mgr_list) 3 | as 4 | ( 5 | select employee_id, last_name, manager_id, 0 reportlevel 6 | , cast(manager_id as varchar2(2000)) 7 | from employees 8 | where employee_id = 101 9 | union all 10 | select e.employee_id, e.last_name, e.manager_id, reportlevel+1 11 | , cast(mgr_list || ',' || manager_id as varchar2(2000)) 12 | from reports_to_101 r, employees e 13 | where r.eid = e.manager_id 14 | ) 15 | select eid, emp_last, mgr_id, reportlevel, mgr_list 16 | from reports_to_101 17 | order by reportlevel, eid 18 | 19 | -------------------------------------------------------------------------------- /tests/query_factoring03.sql: -------------------------------------------------------------------------------- 1 | with 2 | reports_to_101 (eid, emp_last, mgr_id, reportlevel) as 3 | ( 4 | select employee_id, last_name, manager_id, 0 reportlevel 5 | from employees 6 | where employee_id = 101 7 | union all 8 | select e.employee_id, e.last_name, e.manager_id, reportlevel+1 9 | from reports_to_101 r, employees e 10 | where r.eid = e.manager_id 11 | ) 12 | select eid, emp_last, mgr_id, reportlevel 13 | from reports_to_101 14 | where reportlevel <= 1 15 | order by reportlevel, eid 16 | 17 | -------------------------------------------------------------------------------- /tests/query_factoring04.sql: -------------------------------------------------------------------------------- 1 | with 2 | org_chart (eid, emp_last, mgr_id, reportlevel, salary, job_id) as 3 | ( 4 | select employee_id, last_name, manager_id, 0 reportlevel, salary, job_id 5 | from employees 6 | where manager_id is null 7 | union all 8 | select e.employee_id, e.last_name, e.manager_id, 9 | r.reportlevel+1 reportlevel, e.salary, e.job_id 10 | from org_chart r, employees e 11 | where r.eid = e.manager_id 12 | ) 13 | search depth first by emp_last set order1 14 | select lpad(' ',2*reportlevel)||emp_last emp_name, eid, mgr_id, salary, job_id 15 | from org_chart 16 | order by order1 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/query_factoring05.sql: -------------------------------------------------------------------------------- 1 | with 2 | x1 as (select max(y1) from klm1), 3 | x2 as (select max(y2) from klm2), 4 | x3 as (select max(y3) from klm3), 5 | x4 as (select max(y4) from klm4) 6 | select 7 | distinct 8 | -1, 9 | +1, 10 | a + b * (a * d) as aaa, 11 | t1.region_name, 12 | t2.division_name, 13 | t1.region_name as a, 14 | t2.division_name as aaaa, 15 | a.*, 16 | sum(t3.amount), 17 | sum(count(1)) + count(*) 18 | , sum(1) + (select count(1) from ddd) a 19 | from dual, fff 20 | where a is null 21 | or b is not null 22 | and ( a like 'd') 23 | and 1 = 0 24 | and a.b is a set 25 | union 26 | select a from dual 27 | 28 | -------------------------------------------------------------------------------- /tests/query_factoring06.sql: -------------------------------------------------------------------------------- 1 | with 2 | dept_costs as ( 3 | select department_name, sum(salary) dept_total 4 | from employees e, departments d 5 | where e.department_id = d.department_id 6 | group by department_name), 7 | avg_cost as ( 8 | select sum(dept_total)/count(*) avg 9 | from dept_costs) 10 | select * from dept_costs 11 | where dept_total > 12 | (select avvg from avg_cost) 13 | order by department_name 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/query_factoring07.sql: -------------------------------------------------------------------------------- 1 | with timegrouped_rawdata 2 | as 3 | ( 4 | select /*+ leading(sn di md sh ot) cardinality(ot 1000) */ 5 | sh.metric_id as metric_id , 6 | ot.bsln_guid as bsln_guid , 7 | ot.timegroup as timegroup , 8 | sh.value as obs_value 9 | from 10 | dba_hist_snapshot sn , 11 | dba_hist_database_instance di , 12 | sys.wrh$_sysmetric_history sh , 13 | bsln_metric_defaults md , 14 | table(:b1 ) ot 15 | where sn.dbid = :b6 16 | and sn.snap_id between :b5 and :b4 17 | and di.dbid = sn.dbid 18 | and di.instance_number = sn.instance_number 19 | and di.startup_time = sn.startup_time 20 | and di.instance_name = :b3 21 | and sh.snap_id = sn.snap_id 22 | and sh.dbid = sn.dbid 23 | and sh.instance_number = sn.instance_number 24 | and sh.group_id = 2 25 | and sh.metric_id = md.metric_id 26 | and md.status = :b2 27 | and ot.obs_time = trunc(sh.end_time, 'hh24') 28 | ) 29 | ( 30 | select 31 | bsln_statistics_t 32 | ( 33 | bsln_guid ,metric_id ,:b11 ,:b10 ,timegroup ,sample_count ,average ,minimum ,maximum ,sdev , 34 | pctile_25 ,pctile_50 ,pctile_75 ,pctile_90 ,pctile_95 ,pctile_99 ,est_sample_count ,est_slope ,est_intercept , 35 | case when est_slope = 0 then 0 else greatest(0,nvl(100-(25*power((1-est_mu1/est_slope), 2)*(est_sample_count-1) ),0)) end , 36 | ln( 1000) * est_slope + est_intercept , 37 | ln(10000) * est_slope + est_intercept 38 | ) 39 | from 40 | ( 41 | select metric_id ,bsln_guid ,timegroup ,est_mu as est_slope ,est_mu * ln(alpha) + x_m as est_intercept ,to_number(null) as est_fit_quality , 42 | case when count_below_x_j > 0 then (sum_below_x_j + (n-m+1)*(x_j-x_m))/count_below_x_j - x_j else to_number(null) end as est_mu1 , 43 | est_sample_count ,n as sample_count ,average ,minimum ,maximum ,sdev ,pctile_25 ,pctile_50 ,pctile_75 ,pctile_90 ,pctile_95 ,pctile_99 44 | from 45 | ( 46 | select metric_id ,bsln_guid ,timegroup ,max(n) as n ,count(rrank) as est_sample_count , 47 | case when count(rrank) > 3 then ( sum(obs_value) + ( max(n) - max(rrank) ) * max(obs_value) - (max(n) - min(rrank) + 1) * min(obs_value) ) / (count(rrank)-1) 48 | else to_number(null) end as est_mu , 49 | (max(n) - min(rrank) + 1) / (max(n) + 1) as alpha , 50 | min(obs_value) as x_m ,max(obs_value) as x_l ,max(rrank) as l ,min(rrank) as m ,max(mid_tail_value) as x_j , 51 | sum(case when obs_value < mid_tail_value then obs_value else 0 end ) as sum_below_x_j , 52 | sum(case when cume_dist < :b7 then 1 else 0 end ) as count_below_x_j , 53 | max(max_val) as maximum ,max(min_val) as minimum ,max(avg_val) as average ,max(sdev_val) as sdev ,max(pctile_25) as pctile_25 ,max(pctile_50) as pctile_50 , 54 | max(pctile_75) as pctile_75 ,max(pctile_90) as pctile_90 ,max(pctile_95) as pctile_95 ,max(pctile_99) as pctile_99 55 | from 56 | ( 57 | select metric_id ,bsln_guid ,timegroup ,obs_value as obs_value, 58 | cume_dist () over (partition by metric_id, bsln_guid, timegroup order by obs_value ) as cume_dist , 59 | count(1) over (partition by metric_id, bsln_guid, timegroup ) as n , 60 | row_number () over (partition by metric_id, bsln_guid, timegroup order by obs_value) as rrank , 61 | percentile_disc(:b7 ) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as mid_tail_value , 62 | max(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as max_val , 63 | min(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as min_val , 64 | avg(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as avg_val , 65 | stddev(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as sdev_val , 66 | percentile_cont(0.25) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_25 , 67 | percentile_cont(0.5) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_50 , 68 | percentile_cont(0.75) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_75 , 69 | percentile_cont(0.90) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_90 , 70 | percentile_cont(0.95) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_95 , 71 | percentile_cont(0.99) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_99 72 | from timegrouped_rawdata d 73 | ) x 74 | where x.cume_dist >= :b9 and x.cume_dist <= :b8 75 | group by metric_id ,bsln_guid ,timegroup 76 | ) 77 | ) 78 | ) 79 | -------------------------------------------------------------------------------- /tests/query_factoring08.sql: -------------------------------------------------------------------------------- 1 | with -- qf 2 | x1 as ( select * from t1 ), 3 | x2 as ( select * from t2 join t3 on (t2.a2 = t3.a3)) 4 | select 5 | * 6 | from 7 | x1 8 | join x2 on (x1.a1 = x2.a2) 9 | join t4 on (x1.a1 = t4.a4) 10 | 11 | -------------------------------------------------------------------------------- /tests/query_factoring09.sql: -------------------------------------------------------------------------------- 1 | with rn as ( 2 | select rownum rn 3 | from dual 4 | connect by level <= (select max(cases) from t1)) 5 | select pname 6 | from t1, rn 7 | where rn <= cases 8 | order by pname 9 | -------------------------------------------------------------------------------- /tests/query_factoring10.sql: -------------------------------------------------------------------------------- 1 | with o(obj,link) as 2 | ( 3 | select 'a', 'b' from dual union all 4 | select 'a', 'c' from dual union all 5 | select 'c', 'd' from dual union all 6 | select 'd', 'c' from dual union all 7 | select 'd', 'e' from dual union all 8 | select 'e', 'e' from dual 9 | ), 10 | t(root,lev,obj,link,path) as ( 11 | select obj,1,obj,link,cast(obj||'->'||link 12 | as varchar2(4000)) 13 | from o 14 | where obj='a' -- start with 15 | union all 16 | select 17 | t.root,t.lev+1,o.obj,o.link, 18 | t.path||', '||o.obj|| 19 | '->' 20 | ||o.link 21 | from t, o 22 | where t.link=o.obj 23 | ) 24 | search depth first by obj set ord 25 | cycle obj set cycle to 1 default 0 26 | select root,lev,obj,link,path,cycle, 27 | case 28 | when (lev - lead(lev) over (order by ord)) < 0 29 | then 0 30 | else 1 31 | end is_leaf 32 | from t 33 | 34 | -------------------------------------------------------------------------------- /tests/query_factoring11.sql: -------------------------------------------------------------------------------- 1 | with col_generator as ( 2 | select t1.batch_id, decode(t1.action, 'sent', t1.actdate) sent, 3 | decode(t2.action,'recv', t2.actdate) received 4 | from test t1, test t2 5 | where t2.batch_id(+) = t1.batch_id) 6 | select batch_id, max(sent) sent, max(received) received 7 | from col_generator 8 | group by batch_id 9 | order by 1 10 | -------------------------------------------------------------------------------- /tests/sample01.sql: -------------------------------------------------------------------------------- 1 | select * from 2 | ( 3 | select 1 as c1 from "sys"."obj$" sample block (14.285714 , 1) seed (1) "o" 4 | ) samplesub 5 | -------------------------------------------------------------------------------- /tests/simple02.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update 3 | 4 | -------------------------------------------------------------------------------- /tests/simple03.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id 3 | 4 | -------------------------------------------------------------------------------- /tests/simple04.sql: -------------------------------------------------------------------------------- 1 | select * from 2 | ( 3 | ( 4 | select * from dual 5 | ) 6 | unpivot 7 | ( 8 | value for value_type in (dummy) 9 | ) 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /tests/simple05.sql: -------------------------------------------------------------------------------- 1 | select * from 2 | ( 3 | select * from a 4 | unpivot 5 | ( 6 | value for value_type in (dummy) 7 | ) 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /tests/simple06.sql: -------------------------------------------------------------------------------- 1 | select * from (( select * from dual)) a 2 | 3 | -------------------------------------------------------------------------------- /tests/simple07.sql: -------------------------------------------------------------------------------- 1 | select * from dual for update 2 | of dual 3 | 4 | -------------------------------------------------------------------------------- /tests/simple08.sql: -------------------------------------------------------------------------------- 1 | select a, b, c, d, e, 1, 2, f(a,b,c,1+1) from dual 2 | 3 | -------------------------------------------------------------------------------- /tests/simple09.sql: -------------------------------------------------------------------------------- 1 | select a||last_name, 2 | employee_id 3 | from employees 4 | start with job_id = 'ad_vp' 5 | connect by prior employee_id = manager_id 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/simple10.sql: -------------------------------------------------------------------------------- 1 | select a as over from over 2 | -------------------------------------------------------------------------------- /tests/simple11.sql: -------------------------------------------------------------------------------- 1 | select a.* from dual 2 | -------------------------------------------------------------------------------- /tests/simple12.sql: -------------------------------------------------------------------------------- 1 | select 2 | +1, 3 | t2.division_name as aaaa, 4 | a.*, 5 | sum(t3.amount) 6 | from dual 7 | 8 | -------------------------------------------------------------------------------- /tests/simple13.sql: -------------------------------------------------------------------------------- 1 | select * from (dual), (dual d), (dual) d 2 | -------------------------------------------------------------------------------- /tests/string01.sql: -------------------------------------------------------------------------------- 1 | select 2 | 'hello' 3 | , 'oracle.dbs' 4 | , 'jackie''s raincoat' 5 | , '09-mar-98' 6 | , '' 7 | , '''' 8 | , q'!name like '%dbms_%%'!' 9 | , q'<'so,' she said, 'it's finished.'>' 10 | , q'{select * from employees where last_name = 'smith'}' 11 | , q'"name like '['"' 12 | , n'nchar literal' 13 | from dual 14 | 15 | -------------------------------------------------------------------------------- /tests/union01.sql: -------------------------------------------------------------------------------- 1 | select 'a' obj, 'b' link from dual union all 2 | select 'a', 'c' from dual union all 3 | select 'c', 'd' from dual union all 4 | select 'd', 'c' from dual union all 5 | select 'd', 'e' from dual union all 6 | select 'e', 'e' from dual 7 | 8 | -------------------------------------------------------------------------------- /tests/union02.sql: -------------------------------------------------------------------------------- 1 | select distinct job_id from hr.jobs 2 | union all 3 | select distinct job_id from hr.job_history 4 | 5 | -------------------------------------------------------------------------------- /tests/union03.sql: -------------------------------------------------------------------------------- 1 | select distinct job_id from hr.jobs 2 | union all 3 | ( 4 | select distinct job_id from hr.job_history 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /tests/union04.sql: -------------------------------------------------------------------------------- 1 | ( 2 | select distinct job_id from hr.jobs 3 | ) 4 | union all 5 | ( 6 | select distinct job_id from hr.job_history 7 | union all 8 | (((( 9 | select distinct job_id from hr.job_history 10 | union all 11 | ( 12 | select distinct job_id from hr.job_history 13 | ) 14 | ))) 15 | union all 16 | select distinct job_id from hr.job_history 17 | ) 18 | ) 19 | union all 20 | ( 21 | select distinct job_id from hr.job_history 22 | union all 23 | ( 24 | select distinct job_id from hr.job_history 25 | union all 26 | ( 27 | select distinct job_id from hr.job_history 28 | ) 29 | ) 30 | ) 31 | union all 32 | ( 33 | select distinct job_id from hr.job_history 34 | union all 35 | select distinct job_id from hr.job_history 36 | ) 37 | union all 38 | select distinct job_id from hr.job_history 39 | union all 40 | select distinct job_id from hr.job_history 41 | union all 42 | select distinct job_id from hr.job_history 43 | union all 44 | select distinct job_id from hr.job_history 45 | 46 | -------------------------------------------------------------------------------- /tests/union05.sql: -------------------------------------------------------------------------------- 1 | select * from dual 2 | union all 3 | ( 4 | select * from dual 5 | ) 6 | union all 7 | ( 8 | select * from dual 9 | ) 10 | union all 11 | ( 12 | select * from dual 13 | ) 14 | union all 15 | ( 16 | select * from dual 17 | ) 18 | union all 19 | ( 20 | select * from dual 21 | ) 22 | union all 23 | ( 24 | select * from dual 25 | ) 26 | union all 27 | ( 28 | select * from dual 29 | ) 30 | order by 1 asc, 2 asc 31 | -------------------------------------------------------------------------------- /tests/union06.sql: -------------------------------------------------------------------------------- 1 | ( select "x"."r_no", 2 | "x"."i_id", 3 | "x"."ind", 4 | "x"."item", 5 | '0' "o" 6 | from "x" 7 | where ("x"."r_no" = :a) 8 | minus 9 | select "y"."r_no", 10 | "y"."i_id", 11 | "y"."ind", 12 | "y"."item", 13 | '0' "o" 14 | from "y" 15 | where ("y"."r_no" = :a) 16 | ) 17 | union 18 | ( select "y"."r_no", 19 | "y"."i_id", 20 | "y"."ind", 21 | "y"."item", 22 | '1' "o" 23 | from "y" 24 | where ("y"."r_no" = :a) 25 | minus 26 | select "x"."r_no", 27 | "x"."i_id", 28 | "x"."ind", 29 | "x"."item", 30 | '1' "o" 31 | from "x" 32 | where ("x"."r_no" = :a) 33 | ) 34 | order by 4,3,1 35 | 36 | -------------------------------------------------------------------------------- /tests/union07.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- note: this query was copied from the druid project 3 | -- http://code.alibabatech.com/wiki/display/druid/home 4 | -- 5 | select * from ( 6 | select row_.*, rownum rownum_ 7 | from ( 8 | select * 9 | from 10 | ( 11 | select results.*,row_number() over ( partition by results.object_id order by results.gmt_modified desc) rn 12 | from 13 | ( 14 | ( 15 | select sus.id id, sus.gmt_create gmt_create, 16 | sus.gmt_modified gmt_modified, sus.company_id company_id, 17 | sus.object_id object_id, sus.object_type object_type, 18 | sus.confirm_type confirm_type, sus.operator operator, 19 | sus.filter_type filter_type, sus.member_id member_id, 20 | sus.member_fuc_q member_fuc_q, sus.risk_type risk_type , 'y' is_draft 21 | from f_u_c_ sus , a_b_c_draft p , 22 | member m 23 | where 1=1 and p.company_id = m.company_id 24 | and m.login_id=? 25 | and p.sale_type in( ? ) 26 | and p.id=sus.object_id 27 | ) 28 | union 29 | ( 30 | select sus.id id, sus.gmt_create gmt_create, 31 | sus.gmt_modified gmt_modified, sus.company_id company_id, 32 | sus.object_id object_id, sus.object_type object_type, 33 | sus.confirm_type confirm_type, sus.operator operator, 34 | sus.filter_type filter_type, sus.member_id member_id, 35 | sus.member_fuc_q member_fuc_q, sus.risk_type risk_type , 'n' is_draft 36 | from f_u_c_ sus , a_b_c p ,member m 37 | where 1=1 38 | and p.company_id = m.company_id 39 | and m.login_id=? 40 | and p.sale_type in( ? ) 41 | and p.id=sus.object_id 42 | ) 43 | ) results 44 | ) where rn = 1 order by gmt_modified desc 45 | )row_ where rownum <= ? 46 | ) 47 | where rownum_ >= ? 48 | -------------------------------------------------------------------------------- /tests/union08.sql: -------------------------------------------------------------------------------- 1 | select * from dual where exists ( 2 | select * from dual 3 | union all 4 | select * from dual 5 | ) 6 | -------------------------------------------------------------------------------- /tests/union09.sql: -------------------------------------------------------------------------------- 1 | select * from ( 2 | select row_.* 3 | from ( 4 | select * 5 | from 6 | ( 7 | select results.*, 1 rn 8 | from 9 | ( 10 | ( 11 | select dummy 12 | from dual 13 | where 1=1 14 | ) 15 | union 16 | ( 17 | select dummy 18 | from dual 19 | where 1=1 20 | ) 21 | ) results 22 | ) 23 | where rn = 1 order by dummy desc 24 | )row_ 25 | where rownum <= 1 26 | ) 27 | where rownum >= 1 28 | -------------------------------------------------------------------------------- /tests/union10.sql: -------------------------------------------------------------------------------- 1 | select 2 | ( 3 | ( 4 | select 'y' from dual 5 | where exists ( select 1 from dual where 1 = 0 ) 6 | ) 7 | union 8 | ( 9 | select 'n' from dual 10 | where not exists ( select 1 from dual where 1 = 0 ) 11 | ) 12 | ) 13 | as yes_no 14 | from dual 15 | -------------------------------------------------------------------------------- /tests/xmltable01.sql: -------------------------------------------------------------------------------- 1 | select warehouse_name warehouse, warehouse2."water", warehouse2."rail" 2 | from warehouses, 3 | xmltable('/warehouse' 4 | passing warehouses.warehouse_spec 5 | columns 6 | "water" varchar2(6) path '/warehouse/wateraccess', 7 | "rail" varchar2(6) path '/warehouse/railaccess') 8 | warehouse2 9 | -------------------------------------------------------------------------------- /tests/xmltable02.sql: -------------------------------------------------------------------------------- 1 | select xmlelement("other_attrs", xmlelement("parsing_user_id", parsing_user_id)).getClobVal() other 2 | from f 3 | --------------------------------------------------------------------------------