├── .vscode └── settings.json ├── LICENSE ├── PlSqlLexer.g4 ├── PlSqlLexer.interp ├── PlSqlLexer.tokens ├── PlSqlParser.g4 ├── PlSqlParser.interp ├── PlSqlParser.tokens ├── README.md ├── antlr-4.13.0-complete.jar ├── build.sh ├── examples-sql-script ├── anonymous_block.sql ├── cursor-attributes-with-spaces.sql ├── delete_as_regular_id.pkb ├── deterministic_function.pks ├── e_in_out_parameters.pks ├── grants.sql ├── green_run.sql ├── green_table.sql ├── green_tools.pkb ├── green_tools.pks ├── green_tools_review.sql ├── in_out_parameters.pks ├── key_word_as_param.pkb ├── package_body_null.pkb ├── package_with_cursor.sql ├── package_with_schema.pkb ├── package_with_schema.pks ├── pipe_row.pkb ├── pltables.sql ├── pragma_autonomous_transaction.sql ├── pragma_exception_init.pks ├── proc_over_dblink_as_nvl_param.pkb ├── procedure_with_cursor_and_limit.sql ├── result_cache_function.pks ├── select_into.sql ├── show_errors.pks ├── substr_as_regular_id.pkb ├── synonym_with_database_link.sql ├── trigger_examples.sql ├── type_body_elements.sql ├── user.sql └── with_clause_in_exists_block_in_procedure.sql ├── examples ├── administer_key_management.sql ├── alter_analytic_view.sql ├── alter_attribute_dimension.sql ├── alter_audit_policy.sql ├── alter_database.sql ├── alter_dimension.sql ├── alter_diskgroup.sql ├── alter_flashback_archive.sql ├── alter_hierarchy.sql ├── alter_inmemory_join_group.sql ├── alter_java.sql ├── alter_library.sql ├── alter_lockdown_profile.sql ├── alter_materialized_zonemap.sql ├── alter_mv.sql ├── alter_mv_log.sql ├── alter_operator.sql ├── alter_outline.sql ├── alter_partition.sql ├── alter_pmem_filestore.sql ├── alter_resource_cost.sql ├── alter_role.sql ├── alter_rollback_segment.sql ├── alter_session.sql ├── alter_synonym01.sql ├── alter_table.sql ├── alter_table_inmemory.sql ├── alter_tablespace_set.sql ├── alter_tablespaces.sql ├── alter_view.sql ├── analytic_query.sql ├── analyze.sql ├── associate_statistics.sql ├── audit.sql ├── bindvar01.sql ├── bindvar02.sql ├── bindvar03.sql ├── bindvar04.sql ├── bindvar05.sql ├── bulk_collect_fetch_clause01.sql ├── call.sql ├── case_when01.sql ├── case_when02.sql ├── case_when03.sql ├── case_when04.sql ├── case_when05.sql ├── case_when06.sql ├── case_when07.sql ├── cast.sql ├── cast_multiset01.sql ├── cast_multiset02.sql ├── cast_multiset03.sql ├── cast_multiset04.sql ├── cast_multiset05.sql ├── cast_multiset06.sql ├── cast_multiset08.sql ├── cluster.sql ├── columns01.sql ├── comment_on.sql ├── comments.sql ├── commit.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 ├── context.sql ├── create_analytic_view.sql ├── create_attribute_dimension.sql ├── create_audit_policy.sql ├── create_controlfile.sql ├── create_database.sql ├── create_dimension.sql ├── create_directory.sql ├── create_diskgroup.sql ├── create_edition.sql ├── create_flashback_archive.sql ├── create_hierarchy.sql ├── create_index.sql ├── create_inmemory_join_group.sql ├── create_java.sql ├── create_library.sql ├── create_lockdown_profile.sql ├── create_materialized_zonemap.sql ├── create_operator.sql ├── create_outline.sql ├── create_package.sql ├── create_package.sql.tree ├── create_pmem_filestore.sql ├── create_procedure.sql ├── create_procedure.sql.tree ├── create_profile.sql ├── create_restore_point.sql ├── create_role.sql ├── create_rollback_segment.sql ├── create_spfile.sql ├── create_synonym01.sql ├── create_synonym02.sql ├── create_synonym03.sql ├── create_table.sql ├── create_tablespace.sql ├── create_tablespace_set.sql ├── create_type.sql ├── create_view.sql ├── ctas.sql ├── datetime01.sql ├── datetime03.sql ├── datetime04.sql ├── datetime05.sql ├── dblink.sql ├── dblink01.sql ├── directory.sql ├── disassociate_statistics.sql ├── drop_analytic_view.sql ├── drop_attribute_dimension.sql ├── drop_audit_policy.sql ├── drop_cluster.sql ├── drop_context.sql ├── drop_database.sql ├── drop_directory.sql ├── drop_diskgroup.sql ├── drop_edition.sql ├── drop_flashback_archive.sql ├── drop_hierarchy.sql ├── drop_indextype.sql ├── drop_inmemory_join_group.sql ├── drop_java.sql ├── drop_library.sql ├── drop_lockdown_profile.sql ├── drop_materialized_view.sql ├── drop_materialized_view.sql.tree ├── drop_materialized_zonemap.sql ├── drop_operator.sql ├── drop_outline.sql ├── drop_pmem_filestore.sql ├── drop_restore_point.sql ├── drop_role.sql ├── drop_rollback_segment.sql ├── drop_synonym01.sql ├── drop_table.sql ├── drop_tablespace.sql ├── drop_tablespace_set.sql ├── drop_user.sql ├── drop_view.sql ├── explain01.sql ├── external_table01.sql ├── external_table02.sql ├── fetch_clause01.sql ├── fetch_clause02.sql ├── fetch_clause03.sql ├── fetch_clause04.sql ├── flashback01.sql ├── flashback_table.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 ├── function07.sql ├── groupby01.sql ├── groupby02.sql ├── groupby03.sql ├── groupby04.sql ├── groupby05.sql ├── groupby06.sql ├── groupby07.sql ├── index.sql ├── insert_statement.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 ├── json_sql.sql ├── keywordasidentifier01.sql ├── keywordasidentifier02.sql ├── keywordasidentifier03.sql ├── keywordasidentifier04.sql ├── keywordasidentifier05.sql ├── keywordasidentifier06.sql ├── least_greatest.sql ├── lexer01.sql ├── lexer02.sql ├── lexer03.sql ├── lexer04.sql ├── lexer05.sql ├── like01.sql ├── materialized_views.sql ├── max_001.sql ├── merge01.sql ├── merge02.sql ├── merge03.sql ├── merge04.sql ├── merge05.sql ├── model_clause01.sql ├── model_clause02.sql ├── model_clause03.sql ├── model_clause04.sql ├── model_clause05.sql ├── noaudit_statement.sql ├── numbers01.sql ├── nvl_001.sql ├── object_access01.sql ├── offset_clause.sql ├── order_by01.sql ├── order_by02.sql ├── order_by03.sql ├── order_by04.sql ├── order_by05.sql ├── order_by06.sql ├── package_body.sql ├── package_body.sql.tree ├── packagebody_function.sql ├── packagespec_function.sql ├── partitioned_tables.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 ├── purge_statement.sql ├── query_factoring01.sql ├── query_factoring02.sql ├── query_factoring03.sql ├── query_factoring04.sql ├── query_factoring05.sql ├── query_factoring06.sql ├── query_factoring08.sql ├── query_factoring09.sql ├── query_factoring10.sql ├── query_factoring11.sql ├── rename_objects.sql ├── revoke_statement.sql ├── round_001.sql ├── round_decode_001.sql ├── row_number_001.sql ├── sample01.sql ├── select_all_some_any.sql ├── select_package_function.sql ├── select_time.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 ├── timing.sql ├── timing.sql.tree ├── to_binary_double.sql ├── to_binary_float.sql ├── to_char.sql ├── to_char_001.sql ├── to_char_002.sql ├── to_date.sql ├── to_dsinterval.sql ├── to_number.sql ├── to_timestamp.sql ├── to_timestamp_tz.sql ├── to_yminterval.sql ├── truncate_cluster.sql ├── truncate_table.sql ├── unified.sql ├── union01.sql ├── union02.sql ├── union03.sql ├── union04.sql ├── union05.sql ├── union06.sql ├── union07.sql ├── union08.sql ├── union09.sql ├── union10.sql ├── validate_conversion.sql ├── views.sql ├── whenever_sqlerror.sql ├── whenever_sqlerror.sql.tree ├── xml_function.sql ├── xmltable01.sql ├── xmltable02.sql └── xmltable03.sql ├── go.mod ├── go.sum ├── keywords.go ├── parser_test.go ├── plsql_lexer.go ├── plsql_lexer_base.go ├── plsql_parser.go ├── plsql_parser_base.go ├── plsqlparser_base_listener.go ├── plsqlparser_base_visitor.go ├── plsqlparser_listener.go └── plsqlparser_visitor.go /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "antlr", 4 | "PLSQL", 5 | "plsqlparser" 6 | ], 7 | "go.testTimeout": "5m", 8 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The plsql-parser is a parser for Oracle 11g/12c PL/SQL. It is based on the [ANTLR4](https://github.com/antlr/antlr4) and use the grammar from [antlr4-grammars-plsql](https://github.com/antlr/grammars-v4/tree/master/sql/plsql). 2 | 3 | ## Build 4 | 5 | Before build, you need to install the ANTLR4. 6 | 7 | requirements: 8 | - https://github.com/antlr/antlr4/blob/master/doc/getting-started.md 9 | - https://github.com/antlr/antlr4/blob/master/doc/go-target.md 10 | 11 | ```bash 12 | ./build.sh 13 | ``` 14 | 15 | ## Update grammar 16 | 17 | ### Manually change the grammar file in this project 18 | 19 | 1. Update the `PlSqlLexer.g4` and `PlSqlParser.g4` in root directory. 20 | 2. run `./build.sh` to generate the parser code. 21 | 22 | ### From antlr4-grammars-plsql 23 | 24 | 1. Clone the `PlSqlLexer.g4` and `PlSqlParser.g4` grammar files from https://github.com/antlr/grammars-v4/tree/master/sql/plsql into `parser` folder. 25 | 2. Clone the https://github.com/antlr/grammars-v4/blob/master/sql/plsql/Go/transformGrammar.py into root directory. 26 | 3. Run the `transformGrammar.py` to generate the `PlSqlLexer.g4` and `PlSqlParser.g4` in `parser` directory. 27 | 4. Copy the `PlSqlLexer.g4` and `PlSqlParser.g4` to root directory. 28 | 5. run `./build.sh` to generate the parser code. 29 | 30 | ## Test the parser 31 | 32 | Run `TestPLSQLParser` in `parser_test.go` to test the parser. 33 | 34 | ```bash 35 | go test -v 36 | ``` 37 | 38 | ## References 39 | 40 | - Oracle SQL Language Reference: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Introduction-to-Oracle-SQL.html 41 | - ANTLR4 Getting Started https://github.com/antlr/antlr4/blob/master/doc/getting-started.md 42 | - ANTLR4 Go Garget https://github.com/antlr/antlr4/blob/master/doc/go-target.md -------------------------------------------------------------------------------- /antlr-4.13.0-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytebase/plsql-parser/9fed633593d12aa460e666627e333c4bf8d84c28/antlr-4.13.0-complete.jar -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | alias antlr4='java -Xmx500M -cp "./antlr-4.13.0-complete.jar:$CLASSPATH" org.antlr.v4.Tool' 3 | antlr4 -Dlanguage=Go -package parser -visitor *.g4 -------------------------------------------------------------------------------- /examples-sql-script/anonymous_block.sql: -------------------------------------------------------------------------------- 1 | DECLARE 2 | NUX NUMBER := 1; 3 | BEGIN 4 | DBMS_OUTPUT.PUT_LINE('Hello'); 5 | EXCEPTION 6 | WHEN OTHERS THEN 7 | DBMS_OUTPUT.PUT_LINE('Something went wrong!'); 8 | END; 9 | / 10 | -------------------------------------------------------------------------------- /examples-sql-script/cursor-attributes-with-spaces.sql: -------------------------------------------------------------------------------- 1 | DROP PACKAGE TCERS.PK_GRAMMAR_TEST; 2 | 3 | CREATE OR REPLACE PACKAGE TCERS.PK_GRAMMAR_TEST AS 4 | 5 | function test return number; 6 | 7 | END PK_GRAMMAR_TEST; 8 | / 9 | DROP PACKAGE BODY TCERS.PK_GRAMMAR_TEST; 10 | 11 | CREATE OR REPLACE PACKAGE BODY TCERS.PK_GRAMMAR_TEST AS 12 | 13 | function test return number AS 14 | src_row all_source% rowtype; 15 | n pls_integer; 16 | cursor src is select * from all_source; 17 | BEGIN 18 | open src; 19 | loop 20 | fetch src into src_row; 21 | 22 | if src% notfound then 23 | exit; 24 | end if; 25 | 26 | if src% found then 27 | null; 28 | end if; 29 | 30 | end loop; 31 | 32 | if src% isopen then 33 | close src; 34 | end if; 35 | 36 | RETURN sql% rowcount; 37 | END test; 38 | 39 | END PK_GRAMMAR_TEST; 40 | / 41 | -------------------------------------------------------------------------------- /examples-sql-script/delete_as_regular_id.pkb: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PACKAGE BODY FOO 2 | AS 3 | PROCEDURE BAR(COLL COLL_TYPE) 4 | IS 5 | BEGIN 6 | COLL.DELETE; 7 | COLL.DELETE(); 8 | COLL.DELETE(42); 9 | COLL.DELETE(42, 64); 10 | END BAR; 11 | END FOO; -------------------------------------------------------------------------------- /examples-sql-script/deterministic_function.pks: -------------------------------------------------------------------------------- 1 | create or replace package deterministic_function 2 | is 3 | 4 | function fixed_value return varchar2 deterministic; 5 | 6 | end deterministic_function; 7 | / 8 | -------------------------------------------------------------------------------- /examples-sql-script/e_in_out_parameters.pks: -------------------------------------------------------------------------------- 1 | create or replace package e_in_out_parameters 2 | is 3 | 4 | procedure some_in_nocopy_procedure( p_string in nocopy varchar2 ); 5 | 6 | end e_in_out_parameters; 7 | / 8 | 9 | show errors 10 | 11 | create or replace package e_in_out_parameters 12 | is 13 | 14 | procedure some_out_in_procedure( p_string out in varchar2 ); 15 | 16 | end e_in_out_parameters; 17 | / 18 | 19 | show errors 20 | 21 | create or replace package e_in_out_parameters 22 | is 23 | 24 | procedure some_inout_procedure( p_string inout varchar2 ); 25 | 26 | end e_in_out_parameters; 27 | / 28 | 29 | show errors 30 | -------------------------------------------------------------------------------- /examples-sql-script/grants.sql: -------------------------------------------------------------------------------- 1 | -- 4 Roles for scott 2 | GRANT DEFAULT_ROLE TO scott WITH ADMIN OPTION; 3 | GRANT CONNECT TO scott; 4 | GRANT USR_DEFAULT_CONNECT TO scott WITH ADMIN OPTION; 5 | ALTER USER scott DEFAULT ROLE CONNECT; 6 | -- 3 System Privileges for scott 7 | GRANT ALTER USER TO scott; 8 | GRANT CREATE TABLE TO scott; 9 | GRANT CREATE USER TO scott; 10 | -- 6 Object Privileges for scott 11 | GRANT INSERT, SELECT ON example.green_table TO scott; 12 | GRANT ALL ON example.blue_table TO scott; 13 | -------------------------------------------------------------------------------- /examples-sql-script/green_run.sql: -------------------------------------------------------------------------------- 1 | @@green_table.sql 2 | 3 | @@green_tools.pks 4 | @@green_tools.pkb 5 | 6 | @@green_tools_review.sql 7 | -------------------------------------------------------------------------------- /examples-sql-script/green_table.sql: -------------------------------------------------------------------------------- 1 | drop table green_table; 2 | 3 | create table green_table 4 | ( 5 | green_col_one number(10) not null disable 6 | , green_col_two varchar2(64) 7 | ) 8 | tablespace "greenspace" 9 | ; 10 | 11 | Drop Table Green_Table; Create Table green_table 12 | ( 13 | green_col_one number(10) not null disable 14 | , green_col_two varchar2(64) 15 | ) 16 | Tablespace USERS 17 | ; 18 | 19 | insert into green_table (green_col_one, green_col_two) 20 | values (100021, 'green-varchar-21'); 21 | insert into green_table (green_col_one, green_col_two) 22 | values (100022, 'green-varchar-22'); 23 | insert into green_table (green_col_one, green_col_two) 24 | values (100023, 'green-varchar-23'); 25 | 26 | select * 27 | from green_table; 28 | -------------------------------------------------------------------------------- /examples-sql-script/green_tools.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body green_tools 2 | is 3 | 4 | procedure no_params_procedure 5 | is 6 | begin 7 | dbms_output.put_line('no_params_procedure : begin'); 8 | end no_params_procedure; 9 | 10 | function add_brackets( p_string in varchar2 ) return varchar2 11 | as 12 | begin 13 | return '[' || p_string || ']'; 14 | end add_brackets; 15 | 16 | procedure print_green_info( p_with_brackets in boolean ) 17 | is 18 | begin 19 | for r in ( select green_col_two 20 | from green_table ) 21 | loop 22 | if p_with_brackets then 23 | dbms_output.put_line('print_green_info : with brackets : ' || add_brackets(r.green_col_two)); 24 | else 25 | dbms_output.put_line('print_green_info : no brackets : ' || r.green_col_two); 26 | end if; 27 | end loop; 28 | end print_green_info; 29 | 30 | end green_tools; 31 | / 32 | 33 | -------------------------------------------------------------------------------- /examples-sql-script/green_tools.pks: -------------------------------------------------------------------------------- 1 | create or replace package green_tools 2 | is 3 | 4 | procedure no_params_procedure; 5 | 6 | function add_brackets( p_string in varchar2 ) return varchar2; 7 | 8 | procedure print_green_info( p_with_brackets in boolean ); 9 | 10 | end green_tools; 11 | / 12 | -------------------------------------------------------------------------------- /examples-sql-script/green_tools_review.sql: -------------------------------------------------------------------------------- 1 | set serveroutput on 2 | 3 | select green_tools.add_brackets('to-be-bracketed') as with_brackets 4 | from dual; 5 | 6 | begin 7 | green_tools.print_green_info( p_with_brackets => false ); 8 | end; 9 | / 10 | 11 | begin 12 | green_tools.print_green_info( p_with_brackets => true ); 13 | end; 14 | / 15 | -------------------------------------------------------------------------------- /examples-sql-script/in_out_parameters.pks: -------------------------------------------------------------------------------- 1 | create or replace package in_out_parameters 2 | is 3 | 4 | procedure some_procedure( p_string varchar2 ); 5 | 6 | procedure some_in_procedure( p_string in varchar2 ); 7 | 8 | procedure some_out_procedure( p_string out varchar2 ); 9 | 10 | procedure some_in_out_procedure( p_string in out varchar2 ); 11 | 12 | procedure some_in_out_nocopy_procedure( p_string in out nocopy varchar2 ); 13 | 14 | end in_out_parameters; 15 | / 16 | -------------------------------------------------------------------------------- /examples-sql-script/key_word_as_param.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body login 2 | as 3 | 4 | function fun return varchar2 5 | as 6 | raw_key2 raw(128); 7 | raw_userpass raw(128); 8 | raw_encrypted raw(2048); 9 | begin 10 | dbms_obfuscation_toolkit.desencrypt(input => raw_userpass, key => raw_key2, encrypted_data => raw_encrypted); 11 | end fun; 12 | 13 | end; -------------------------------------------------------------------------------- /examples-sql-script/package_body_null.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body pkgtest is 2 | begin 3 | null; 4 | end; 5 | / 6 | -------------------------------------------------------------------------------- /examples-sql-script/package_with_cursor.sql: -------------------------------------------------------------------------------- 1 | create or replace package pkgtest is 2 | 3 | cursor cuData is 4 | select * from dual; 5 | 6 | procedure main; 7 | end; 8 | / 9 | 10 | create or replace package body pkgtest is 11 | procedure main is 12 | sbData varchar2(100); 13 | begin 14 | open pkgtest.cuData; 15 | fetch cuData into sbData; 16 | close cuData; 17 | 18 | if cuData%isopen then 19 | dbms_output.put_line('should work'); 20 | end if; 21 | 22 | if sql%rowcount > 0 then 23 | dbms_output.put_line('should work too'); 24 | end if; 25 | end; 26 | 27 | function GETPOS_TEMPLATE_DEF_ID return VARCHAR2 is 28 | LVS_ID VARCHAR2(4000 CHAR); 29 | BEGIN 30 | LVS_ID := TRIM(BOTH SF_FORM_EXT_CONSTANTS.GETSOMETHING FROM LVS_ID); 31 | return LVS_ID; 32 | end GETPOS_TEMPLATE_DEF_ID; 33 | end; 34 | / 35 | -------------------------------------------------------------------------------- /examples-sql-script/package_with_schema.pkb: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PACKAGE BODY HR.PACK 2 | AS 3 | PROCEDURE PROC1 4 | AS 5 | BEGIN 6 | NULL; 7 | END; 8 | END; -------------------------------------------------------------------------------- /examples-sql-script/package_with_schema.pks: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PACKAGE HR.PACK 2 | AS 3 | PROCEDURE PROC1; 4 | END; -------------------------------------------------------------------------------- /examples-sql-script/pipe_row.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body pipe_row_test as 2 | 3 | function fun return t_tab pipelined 4 | as 5 | vRow t_tab_row; 6 | begin 7 | for rec in ( select Id from tbl ) 8 | loop 9 | vrow.Id := rec.Id; 10 | pipe row (vrow); 11 | end loop; 12 | 13 | end; 14 | 15 | 16 | function prodfunc(n number) return mytabletype pipelined is 17 | begin 18 | <> 19 | for i in 1 .. 5 loop 20 | pipe row (myobjectformat(n,sysdate+i,'row '||i)); 21 | end loop pipes; 22 | return; 23 | end; 24 | 25 | end; -------------------------------------------------------------------------------- /examples-sql-script/pltables.sql: -------------------------------------------------------------------------------- 1 | declare 2 | TYPE tyrcmessage IS RECORD (id number, message varchar2(100)); 3 | TYPE tytbMessages IS TABLE OF tyrcmessage INDEX BY BINARY_INTEGER; 4 | 5 | tbmessages tytbMessages; 6 | nuidx number; 7 | 8 | begin 9 | nuidx := tbmessages.first; 10 | while nuidx is not null loop 11 | nuidx := tbmessages.next(nuidx); 12 | end loop; 13 | end; 14 | / 15 | -------------------------------------------------------------------------------- /examples-sql-script/pragma_autonomous_transaction.sql: -------------------------------------------------------------------------------- 1 | declare 2 | pragma autonomous_transaction; 3 | begin 4 | commit; 5 | end; 6 | / 7 | -------------------------------------------------------------------------------- /examples-sql-script/pragma_exception_init.pks: -------------------------------------------------------------------------------- 1 | create or replace package pragma_exception_init 2 | is 3 | 4 | some_exception exception; 5 | pragma exception_init (some_exception, -20001); 6 | 7 | end pragma_exception_init; 8 | / 9 | -------------------------------------------------------------------------------- /examples-sql-script/proc_over_dblink_as_nvl_param.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body pack as 2 | 3 | procedure test(inId number) 4 | as 5 | vSum number; 6 | vPaymentsDate number; 7 | begin 8 | 9 | vSum := nvl(pack_1.getSum@dblink(inId=>inId, vPaymentsDate => pack_2.getLastDay(4, 3)), 0); 10 | 11 | end; 12 | 13 | 14 | end; -------------------------------------------------------------------------------- /examples-sql-script/procedure_with_cursor_and_limit.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE SF_JOB_CLEANUP_SHOWCASES_START (FPN_ANZ_ZUM_VERARBEITEN NUMBER DEFAULT 10000, FPN_BULK_LIMIT NUMBER DEFAULT 5000) AS 2 | 3 | TYPE T_BULK_TAB IS RECORD ( 4 | SC_ID SALESFRONT.SF_SHOWCASE.ID%TYPE, 5 | JOBLIST_ID SF_JOB_CLEANUP_SHOWCASES_SCLIST.ID%TYPE 6 | ); 7 | TYPE T_BULK_COLLECT_TAB IS TABLE OF T_BULK_TAB; 8 | 9 | LNC_ID_LIST T_BULK_COLLECT_TAB; 10 | 11 | COUNTER PLS_INTEGER := 0; 12 | LVNEXISTS PLS_INTEGER := 0; 13 | LVSERRORMSG VARCHAR2(4000); 14 | 15 | CURSOR C_DEL_SC(C_MAX_ROW NUMBER) IS 16 | SELECT SC.ID SC_ID , SL.ID JOBLIST_ID FROM SF_JOB_CLEANUP_SHOWCASES_SCLIST SL 17 | INNER JOIN SALESFRONT.SF_SHOWCASE SC ON SC.ID = SL.SF_SHOWCASE_ID 18 | WHERE SL.VERARBEITEN = 1 19 | AND VERARBEITET_AM IS NULL 20 | AND ROWNUM < C_MAX_ROW; 21 | 22 | BEGIN 23 | EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM USER_SCHEDULER_JOBS JO WHERE JOB_NAME=''SF_START_TOURENEXPORT'' AND JO.STATE = ''RUNNING''' 24 | INTO LVNEXISTS; 25 | 26 | IF LVNEXISTS = 0 THEN 27 | OPEN C_DEL_SC(FPN_ANZ_ZUM_VERARBEITEN); 28 | LOOP 29 | --IN BLÖCKEN AUS PERFORMANCE GRÜNDEN 30 | FETCH C_DEL_SC BULK COLLECT INTO LNC_ID_LIST LIMIT FPN_BULK_LIMIT; 31 | COUNTER := COUNTER + LNC_ID_LIST.COUNT; 32 | EXIT WHEN C_DEL_SC%NOTFOUND; 33 | 34 | COMMIT; 35 | END LOOP; 36 | CLOSE C_DEL_SC; 37 | END IF; 38 | 39 | EXCEPTION WHEN OTHERS THEN 40 | LVSERRORMSG := SQLERRM || ' BACKTRACE: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE; 41 | ROLLBACK; 42 | END; -------------------------------------------------------------------------------- /examples-sql-script/result_cache_function.pks: -------------------------------------------------------------------------------- 1 | create or replace package result_cache_function 2 | is 3 | 4 | function some_function( p_string in varchar2 ) return varchar2 result_cache; 5 | 6 | end result_cache_function; 7 | / 8 | -------------------------------------------------------------------------------- /examples-sql-script/select_into.sql: -------------------------------------------------------------------------------- 1 | DECLARE 2 | TYPE T2 IS RECORD (C NUMBER); 3 | TYPE T1 IS RECORD (B T2); 4 | A T1; 5 | 6 | TYPE T3 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; 7 | D T3; 8 | BEGIN 9 | SELECT 1 10 | INTO A.B.C 11 | FROM DUAL; 12 | 13 | SELECT 1 14 | INTO D(1) 15 | FROM DUAL; 16 | 17 | SELECT 1 18 | INTO :BLOCK.ITEM 19 | FROM DUAL; 20 | END; 21 | / 22 | -------------------------------------------------------------------------------- /examples-sql-script/show_errors.pks: -------------------------------------------------------------------------------- 1 | create or replace package show_errors 2 | is 3 | 4 | procedure some_procedure; 5 | 6 | end show_errors; 7 | / 8 | 9 | show errors 10 | 11 | create or replace package show_errors 12 | is 13 | 14 | procedure some_procedure; 15 | 16 | end show_errors; 17 | / 18 | 19 | show err 20 | -------------------------------------------------------------------------------- /examples-sql-script/substr_as_regular_id.pkb: -------------------------------------------------------------------------------- 1 | create or replace package body testPack as 2 | 3 | function blob_to_clob (blob_in in blob) return clob 4 | as 5 | begin 6 | utl_raw.cast_to_varchar2(dbms_lob.substr(a, b, c)); 7 | return null; 8 | end blob_to_clob; 9 | 10 | end testPack; -------------------------------------------------------------------------------- /examples-sql-script/synonym_with_database_link.sql: -------------------------------------------------------------------------------- 1 | create or replace synonym rs_customer2Prs for SCHEMANAME.CUSTOMER2PRS@SCHEMANAME.LINKNAME; -------------------------------------------------------------------------------- /examples-sql-script/trigger_examples.sql: -------------------------------------------------------------------------------- 1 | create or replace trigger trg_status_tick 2 | after insert or update or delete on status for each row 3 | declare 4 | begin 5 | if inserting then 6 | tp_ticket_util.fire('status', tp_ticket_const.cinsert, :new.id); 7 | elsif updating then 8 | tp_ticket_util.fire('status', tp_ticket_const.cupdate, :new.id); 9 | elsif deleting then 10 | tp_ticket_util.fire('status', tp_ticket_const.cdelete, :old.id); 11 | end if; 12 | end; -------------------------------------------------------------------------------- /examples-sql-script/type_body_elements.sql: -------------------------------------------------------------------------------- 1 | create or replace type type_body_elements 2 | as object 3 | ( 4 | some_string varchar2(64), 5 | member function function_one 6 | return varchar2, 7 | member function function_two 8 | return varchar2 9 | ); 10 | / 11 | 12 | create or replace type body type_body_elements 13 | is 14 | 15 | member function function_one 16 | return varchar2 17 | is 18 | begin 19 | return 'the function_one result'; 20 | end function_one; 21 | 22 | member function function_two 23 | return varchar2 24 | is 25 | begin 26 | return 'the function_two result'; 27 | end function_two; 28 | 29 | end; 30 | / 31 | create or replace TYPE CLNOBJREPORTCOLUMN force is table of varchar2(4000); 32 | / -------------------------------------------------------------------------------- /examples-sql-script/user.sql: -------------------------------------------------------------------------------- 1 | CREATE USER scott 2 | IDENTIFIED BY tiger 3 | DEFAULT TABLESPACE USERS 4 | TEMPORARY TABLESPACE TEMP 5 | PROFILE SCOTT_PROFILE 6 | ACCOUNT UNLOCK; 7 | 8 | -- 1 Tablespace Quota for scott 9 | ALTER USER scott QUOTA 5000M ON USERS; 10 | -------------------------------------------------------------------------------- /examples-sql-script/with_clause_in_exists_block_in_procedure.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE PROCESS_QUEUE(FPN_DATENQUELLE_ID NUMBER DEFAULT NULL) IS 2 | BEGIN 3 | DELETE 4 | FROM TP_TICKET_RAW DEL_T 5 | WHERE EXISTS ( 6 | WITH BASIS AS (SELECT * FROM TP_TICKET_RAW TT) 7 | SELECT NULL 8 | FROM BASIS BA 9 | WHERE EXISTS (SELECT NULL 10 | FROM BASIS BE 11 | WHERE BE.TABLE_NAME = BA.TABLE_NAME 12 | AND BE.TP_TICKET_ART_ID = BA.TP_TICKET_ART_ID 13 | AND BE.REF_ID = BA.REF_ID 14 | AND BA.CREATION_DATE > BE.CREATION_DATE) 15 | AND DEL_T.ID = BA.ID 16 | ); 17 | COMMIT; 18 | END PROCESS_QUEUE; -------------------------------------------------------------------------------- /examples/administer_key_management.sql: -------------------------------------------------------------------------------- 1 | ADMINISTER KEY MANAGEMENT MOVE KEYS 2 | TO NEW KEYSTORE '$ORACLE_BASE/admin/orcl/wallet' 3 | IDENTIFIED BY "pass" 4 | FROM FORCE KEYSTORE 5 | IDENTIFIED BY "pass" 6 | WITH IDENTIFIER IN 7 | (SELECT KEY_ID FROM V$ENCRYPTION_KEYS WHERE ROWNUM < 2); 8 | 9 | ADMINISTER KEY MANAGEMENT 10 | SWITCHOVER TO LIBRARY 'updated_fully_qualified_file_name_of_library' FOR ALL CONTAINERS; 11 | 12 | ADMINISTER KEY MANAGEMENT 13 | CREATE KEYSTORE '/etc/ORACLE/WALLETS/orcl' 14 | IDENTIFIED BY "pass"; 15 | 16 | ADMINISTER KEY MANAGEMENT 17 | CREATE AUTO_LOGIN KEYSTORE FROM KEYSTORE '/etc/ORACLE/WALLETS/orcl' 18 | IDENTIFIED BY "pass"; 19 | 20 | ADMINISTER KEY MANAGEMENT 21 | SET KEYSTORE OPEN 22 | IDENTIFIED BY "pass"; 23 | 24 | ADMINISTER KEY MANAGEMENT 25 | SET KEYSTORE OPEN 26 | IDENTIFIED BY "pass" 27 | CONTAINER = CURRENT; 28 | 29 | ADMINISTER KEY MANAGEMENT 30 | SET KEYSTORE OPEN 31 | IDENTIFIED BY "user_id:password"; 32 | 33 | ADMINISTER KEY MANAGEMENT 34 | SET KEYSTORE OPEN 35 | IDENTIFIED BY EXTERNAL STORE; 36 | 37 | ADMINISTER KEY MANAGEMENT 38 | SET KEYSTORE CLOSE 39 | IDENTIFIED BY "pass"; 40 | 41 | ADMINISTER KEY MANAGEMENT 42 | SET KEYSTORE CLOSE; 43 | 44 | ADMINISTER KEY MANAGEMENT 45 | SET KEYSTORE CLOSE 46 | IDENTIFIED BY "user_id:password"; 47 | 48 | ADMINISTER KEY MANAGEMENT 49 | SET KEYSTORE CLOSE 50 | IDENTIFIED BY EXTERNAL STORE; 51 | 52 | ADMINISTER KEY MANAGEMENT 53 | BACKUP KEYSTORE USING 'hr.emp_keystore' 54 | IDENTIFIED BY "password" 55 | TO '/etc/ORACLE/KEYSTORE/DB1/'; 56 | 57 | ADMINISTER KEY MANAGEMENT 58 | ALTER KEYSTORE PASSWORD IDENTIFIED BY "old_password" 59 | SET "new_password" WITH BACKUP USING 'pwd_change'; 60 | 61 | ADMINISTER KEY MANAGEMENT 62 | MERGE KEYSTORE '/etc/ORACLE/KEYSTORE/DB1' 63 | AND KEYSTORE '/etc/ORACLE/KEYSTORE/DB2' 64 | IDENTIFIED BY "old-pass" 65 | INTO NEW KEYSTORE '/etc/ORACLE/KEYSTORE/DB3' 66 | IDENTIFIED BY "new-pass"; 67 | 68 | ADMINISTER KEY MANAGEMENT 69 | MERGE KEYSTORE '/etc/ORACLE/KEYSTORE/DB1' 70 | INTO EXISTING KEYSTORE '/etc/ORACLE/KEYSTORE/DB2' 71 | IDENTIFIED BY "pass" 72 | WITH BACKUP; 73 | 74 | ADMINISTER KEY MANAGEMENT 75 | SET KEY USING ALGORITHM 'SEED128' 76 | IDENTIFIED BY "pass" 77 | WITH BACKUP; 78 | 79 | ADMINISTER KEY MANAGEMENT 80 | CREATE KEY USING TAG 'mykey1' 81 | IDENTIFIED BY "pass" 82 | WITH BACKUP; 83 | 84 | ADMINISTER KEY MANAGEMENT 85 | USE KEY 'ARgEtzPxpE/Nv8WdPu8LJJUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 86 | IDENTIFIED BY "pass" 87 | WITH BACKUP; 88 | 89 | ADMINISTER KEY MANAGEMENT 90 | SET TAG 'mykey2' FOR 'ARgEtzPxpE/Nv8WdPu8LJJUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' 91 | FORCE KEYSTORE 92 | IDENTIFIED BY "pass" 93 | WITH BACKUP; 94 | 95 | ADMINISTER KEY MANAGEMENT 96 | EXPORT KEYS WITH SECRET "my_secret" 97 | TO '/etc/TDE/export.exp' 98 | IDENTIFIED BY "password" 99 | WITH IDENTIFIER IN 'AdoxnJ0uH08cv7xkz83ovwsAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', 100 | 'AW5z3CoyKE/yv3cNT5CWCXUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; 101 | 102 | ADMINISTER KEY MANAGEMENT 103 | EXPORT KEYS WITH SECRET "my_secret" 104 | TO '/etc/TDE/export.exp' 105 | IDENTIFIED BY "pass" 106 | WITH IDENTIFIER IN 107 | (SELECT KEY_ID FROM V$ENCRYPTION_KEYS WHERE TAG IN ('mytag1', 'mytag2')); 108 | 109 | ADMINISTER KEY MANAGEMENT 110 | EXPORT KEYS WITH SECRET "my_secret" 111 | TO '/etc/TDE/export.exp' 112 | IDENTIFIED BY "pass"; 113 | 114 | ADMINISTER KEY MANAGEMENT 115 | IMPORT KEYS WITH SECRET "my_secret" 116 | FROM '/etc/TDE/export.exp' 117 | IDENTIFIED BY "pass" 118 | WITH BACKUP; 119 | 120 | ADMINISTER KEY MANAGEMENT 121 | SET ENCRYPTION KEY IDENTIFIED BY "software_keystore_password" 122 | REVERSE MIGRATE USING "user_id:password"; 123 | 124 | ADMINISTER KEY MANAGEMENT 125 | ADD SECRET 'secret1' FOR CLIENT 'client1' 126 | USING TAG 'My first secret' 127 | IDENTIFIED BY "pass" 128 | WITH BACKUP; 129 | 130 | ADMINISTER KEY MANAGEMENT 131 | ADD SECRET 'secret2' FOR CLIENT 'client2' 132 | USING TAG 'My second secret' 133 | IDENTIFIED BY "user_id:password"; 134 | -------------------------------------------------------------------------------- /examples/alter_analytic_view.sql: -------------------------------------------------------------------------------- 1 | ALTER ANALYTIC VIEW sales_av RENAME TO mysales_av; 2 | 3 | ALTER ANALYTIC VIEW TKHCSGL308_UNITS_AVIEW_CACHE ADD CACHE 4 | MEASURE GROUP (sales, units, cost) 5 | LEVELS (TIME.FISCAL.FISCAL_QUARTER, WAREHOUSE); 6 | -------------------------------------------------------------------------------- /examples/alter_attribute_dimension.sql: -------------------------------------------------------------------------------- 1 | ALTER ATTRIBUTE DIMENSION product_attr_dim RENAME TO my_product_attr_dim; 2 | -------------------------------------------------------------------------------- /examples/alter_audit_policy.sql: -------------------------------------------------------------------------------- 1 | ALTER AUDIT POLICY hr_audit_policy ADD ONLY TOPLEVEL; 2 | ALTER AUDIT POLICY hr_audit_policy DROP ONLY TOPLEVEL; 3 | ALTER AUDIT POLICY dml_pol 4 | ADD PRIVILEGES CREATE ANY TABLE, DROP ANY TABLE; 5 | ALTER AUDIT POLICY java_pol 6 | ADD ACTIONS CREATE JAVA, ALTER JAVA, DROP JAVA; 7 | ALTER AUDIT POLICY table_pol 8 | ADD ROLES dba; 9 | ALTER AUDIT POLICY security_pol 10 | ADD PRIVILEGES CREATE ANY LIBRARY, DROP ANY LIBRARY 11 | ACTIONS DELETE on hr.employees, 12 | INSERT on hr.employees, 13 | UPDATE on hr.employees, 14 | ALL on hr.departments 15 | ROLES dba, connect; 16 | ALTER AUDIT POLICY table_pol 17 | DROP PRIVILEGES CREATE ANY TABLE; 18 | ALTER AUDIT POLICY dml_pol 19 | DROP ACTIONS INSERT on hr.employees, 20 | UPDATE on hr.employees; 21 | ALTER AUDIT POLICY java_pol 22 | DROP ROLES java_deploy; 23 | ALTER AUDIT POLICY hr_admin_pol 24 | DROP PRIVILEGES CREATE ANY TABLE 25 | ACTIONS LOCK TABLE 26 | ROLES audit_viewer; 27 | ALTER AUDIT POLICY dp_actions_pol 28 | ADD ACTIONS COMPONENT = datapump EXPORT 29 | DROP ACTIONS COMPONENT = datapump IMPORT; 30 | ALTER AUDIT POLICY order_updates_pol 31 | CONDITION DROP; 32 | ALTER AUDIT POLICY emp_updates_pol 33 | CONDITION 'UID = 102' 34 | EVALUATE PER STATEMENT; 35 | -------------------------------------------------------------------------------- /examples/alter_database.sql: -------------------------------------------------------------------------------- 1 | ALTER DATABASE testdb 2 | DATAFILE '+dgroup_01/testdb/datafile/system.261.1' ONLINE; 3 | ALTER DATABASE OPEN READ ONLY; 4 | ALTER DATABASE 5 | RECOVER TABLESPACE tbs_03 6 | PARALLEL; 7 | ALTER DATABASE 8 | ADD LOGFILE GROUP 3 9 | ('diska:log3.log' , 10 | 'diskb:log3.log') SIZE 50K; 11 | ALTER DATABASE 12 | ADD LOGFILE THREAD 5 GROUP 4 13 | ('diska:log4.log', 14 | 'diskb:log4:log'); 15 | ALTER DATABASE 16 | ADD LOGFILE MEMBER 'diskc:log3.log' 17 | TO GROUP 3; 18 | ALTER DATABASE 19 | DROP LOGFILE MEMBER 'diskb:log3.log'; 20 | ALTER DATABASE DROP LOGFILE GROUP 3; 21 | ALTER DATABASE 22 | RENAME FILE 'diskc:log3.log' TO 'diskb:log3.log'; 23 | ALTER DATABASE 24 | SET DEFAULT BIGFILE TABLESPACE; 25 | ALTER DATABASE 26 | DEFAULT TEMPORARY TABLESPACE tbs_05; 27 | ALTER DATABASE TEMPFILE 'temp02.dbf' OFFLINE; 28 | ALTER DATABASE RENAME FILE 'temp02.dbf' TO 'temp03.dbf'; 29 | ALTER DATABASE 30 | RENAME GLOBAL_NAME TO demo.world.oracle.com; 31 | ALTER DATABASE 32 | ENABLE BLOCK CHANGE TRACKING 33 | USING FILE 'tracking_file' REUSE; 34 | ALTER DATABASE 35 | DISABLE BLOCK CHANGE TRACKING; 36 | ALTER DATABASE 37 | DATAFILE 'diskb:tbs_f5.dat' RESIZE 10 M; 38 | ALTER DATABASE 39 | CLEAR LOGFILE 'diskc:log3.log'; 40 | ALTER DATABASE 41 | RECOVER AUTOMATIC DATABASE; 42 | ALTER DATABASE 43 | RECOVER LOGFILE 'diskc:log3.log'; 44 | --TODO: fix grammar 45 | --ALTER DATABASE 46 | -- RECOVER STANDBY DATAFILE '/finance/stbs_21.f' 47 | -- UNTIL CONTROLFILE; 48 | ALTER DATABASE 49 | RECOVER MANAGED STANDBY DATABASE; 50 | -------------------------------------------------------------------------------- /examples/alter_dimension.sql: -------------------------------------------------------------------------------- 1 | ALTER DIMENSION customers_dim DROP ATTRIBUTE country; 2 | 3 | ALTER DIMENSION customers_dim 4 | ADD LEVEL zone IS customers.cust_postal_code 5 | ADD ATTRIBUTE zone DETERMINES (cust_city); -------------------------------------------------------------------------------- /examples/alter_diskgroup.sql: -------------------------------------------------------------------------------- 1 | ALTER DISKGROUP hmdg ADD FILEGROUP fgtem TEMPLATE SET 'datafile.redundancy'='unprotected'; 2 | 3 | ALTER DISKGROUP hmdg ADD FILEGROUP fgdb DATABASE NONE FROM TEMPLATE fgtem; 4 | 5 | ALTER DISKGROUP hmdg ADD FILEGROUP fgtem2 TEMPLATE 6 | CREATE TABLESPACE tbs1 datafile '+hmdg(fg$fgtem2)/dbs/tbs1.f' size 1M; 7 | 8 | ALTER DISKGROUP dgroup_01 9 | ADD DISK '/devices/disks/d100'; 10 | 11 | ALTER DISKGROUP dgroup_01 12 | DROP DISK dgroup_01_0000; 13 | 14 | ALTER DISKGROUP dgroup_01 15 | UNDROP DISKS; 16 | 17 | ALTER DISKGROUP dgroup_01 18 | RESIZE ALL 19 | SIZE 36G; 20 | 21 | ALTER DISKGROUP dgroup_01 22 | REBALANCE POWER 11 WAIT; 23 | 24 | ALTER DISKGROUP dgroup_01 25 | CHECK ALL 26 | REPAIR; 27 | 28 | ALTER DISKGROUP dgroup_01 29 | ADD TEMPLATE template_01 30 | ATTRIBUTES (UNPROTECTED COARSE); 31 | 32 | ALTER DISKGROUP dgroup_01 33 | MODIFY TEMPLATE template_01 34 | ATTRIBUTES (FINE); 35 | 36 | ALTER DISKGROUP dgroup_01 37 | DROP TEMPLATE template_01; 38 | 39 | ALTER DISKGROUP dgroup_01 40 | ADD DIRECTORY '+dgroup_01/alias_dir'; 41 | 42 | ALTER DISKGROUP dgroup_01 43 | ADD ALIAS '+dgroup_01/alias_dir/datafile.dbf' 44 | FOR '+dgroup_01.261.1'; 45 | 46 | ALTER DISKGROUP dgroup_01 47 | SCRUB REPAIR WAIT; 48 | 49 | ALTER DISKGROUP dgroup_01 50 | DISMOUNT FORCE; 51 | 52 | ALTER DISKGROUP dgroup_01 53 | MOUNT; 54 | -------------------------------------------------------------------------------- /examples/alter_flashback_archive.sql: -------------------------------------------------------------------------------- 1 | ALTER FLASHBACK ARCHIVE test_archive1 2 | MODIFY RETENTION 1 MONTH; 3 | 4 | ALTER TABLE oe.customers 5 | FLASHBACK ARCHIVE; 6 | 7 | ALTER TABLE oe.orders 8 | FLASHBACK ARCHIVE test_archive2; 9 | -------------------------------------------------------------------------------- /examples/alter_hierarchy.sql: -------------------------------------------------------------------------------- 1 | ALTER HIERARCHY product_hier RENAME TO myproduct_hier; 2 | -------------------------------------------------------------------------------- /examples/alter_inmemory_join_group.sql: -------------------------------------------------------------------------------- 1 | ALTER INMEMORY JOIN GROUP prod_id1 2 | ADD(product_descriptions(product_id)); 3 | 4 | ALTER INMEMORY JOIN GROUP prod_id1 5 | REMOVE(product_descriptions(product_id)); 6 | -------------------------------------------------------------------------------- /examples/alter_java.sql: -------------------------------------------------------------------------------- 1 | ALTER JAVA CLASS "Agent" 2 | RESOLVER (("/usr/bin/bfile_dir/*" pm)(* public)) 3 | RESOLVE; 4 | -------------------------------------------------------------------------------- /examples/alter_library.sql: -------------------------------------------------------------------------------- 1 | ALTER LIBRARY hr.my_ext_lib COMPILE; 2 | -------------------------------------------------------------------------------- /examples/alter_lockdown_profile.sql: -------------------------------------------------------------------------------- 1 | ALTER LOCKDOWN PROFILE hr_prof 2 | DISABLE FEATURE = ('NETWORK_ACCESS'); 3 | 4 | ALTER LOCKDOWN PROFILE hr_prof 5 | DISABLE FEATURE = ('LOB_FILE_ACCESS', 'TRACE_VIEW_ACCESS'); 6 | ALTER LOCKDOWN PROFILE hr_prof 7 | DISABLE FEATURE ALL EXCEPT = ('COMMON_USER_LOCAL_SCHEMA_ACCESS', 'LOCAL_USER_COMMON_SCHEMA_ACCESS'); 8 | ALTER LOCKDOWN PROFILE hr_prof 9 | DISABLE FEATURE ALL; 10 | ALTER LOCKDOWN PROFILE hr_prof 11 | ENABLE FEATURE = ('UTL_HTTP', 'UTL_SMTP', 'OS_ACCESS'); 12 | ALTER LOCKDOWN PROFILE hr_prof 13 | ENABLE FEATURE ALL EXCEPT = ('AQ_PROTOCOLS', 'CTX_PROTOCOLS'); 14 | ALTER LOCKDOWN PROFILE hr_prof 15 | ENABLE FEATURE ALL; 16 | ALTER LOCKDOWN PROFILE hr_prof 17 | DISABLE OPTION = ('DATABASE QUEUING'); 18 | ALTER LOCKDOWN PROFILE hr_prof 19 | DISABLE OPTION = ('PARTITIONING'); 20 | ALTER LOCKDOWN PROFILE hr_prof 21 | ENABLE OPTION = ('DATABASE QUEUING'); 22 | ALTER LOCKDOWN PROFILE hr_prof 23 | ENABLE OPTION ALL; 24 | ALTER LOCKDOWN PROFILE hr_prof 25 | DISABLE STATEMENT = ('ALTER DATABASE'); 26 | ALTER LOCKDOWN PROFILE hr_prof 27 | DISABLE STATEMENT = ('ALTER SYSTEM') 28 | CLAUSE = ('SUSPEND', 'RESUME'); 29 | ALTER LOCKDOWN PROFILE hr_prof 30 | DISABLE STATEMENT = ('ALTER PLUGGABLE DATABASE') 31 | CLAUSE ALL EXCEPT = ('DEFAULT TABLESPACE', 'DEFAULT TEMPORARY TABLESPACE'); 32 | ALTER LOCKDOWN PROFILE hr_prof 33 | DISABLE STATEMENT = ('ALTER SESSION') 34 | CLAUSE = ('SET') 35 | OPTION = ('COMMIT_WAIT', 'CURSOR_SHARING'); 36 | ALTER LOCKDOWN PROFILE hr_prof 37 | DISABLE STATEMENT = ('ALTER SYSTEM') 38 | CLAUSE = ('SET') 39 | OPTION = ('PDB_FILE_NAME_CONVERT') 40 | VALUE = ('cdb1_pdb0', 'cdb1_pdb1'); 41 | ALTER LOCKDOWN PROFILE hr_prof 42 | DISABLE STATEMENT = ('ALTER SYSTEM') 43 | CLAUSE = ('SET') 44 | OPTION = ('CPU_COUNT') 45 | MINVALUE = '8'; 46 | ALTER LOCKDOWN PROFILE hr_prof 47 | DISABLE STATEMENT = ('ALTER SYSTEM') 48 | CLAUSE = ('SET') 49 | OPTION = ('CPU_COUNT') 50 | MAXVALUE = '2'; 51 | ALTER LOCKDOWN PROFILE hr_prof 52 | DISABLE STATEMENT = ('ALTER SYSTEM') 53 | CLAUSE = ('SET') 54 | OPTION = ('CPU_COUNT') 55 | MINVALUE = '2' 56 | MAXVALUE = '6'; 57 | ALTER LOCKDOWN PROFILE hr_prof 58 | ENABLE STATEMENT ALL EXCEPT = ('ALTER DATABASE'); 59 | ALTER LOCKDOWN PROFILE hr_prof 60 | ENABLE STATEMENT = ('ALTER DATABASE') 61 | CLAUSE = ('MOUNT', 'OPEN'); 62 | ALTER LOCKDOWN PROFILE hr_prof 63 | ENABLE STATEMENT = ('ALTER PLUGGABLE DATABASE') 64 | CLAUSE ALL EXCEPT = ('DEFAULT TABLESPACE', 'DEFAULT TEMPORARY TABLESPACE'); 65 | ALTER LOCKDOWN PROFILE hr_prof 66 | ENABLE STATEMENT = ('ALTER SESSION') 67 | CLAUSE = ('SET') 68 | OPTION = ('COMMIT_WAIT', 'CURSOR_SHARING'); 69 | -------------------------------------------------------------------------------- /examples/alter_materialized_zonemap.sql: -------------------------------------------------------------------------------- 1 | ALTER MATERIALIZED ZONEMAP sales_zmap PCTFREE 20 PCTUSED 50 NOCACHE; 2 | ALTER MATERIALIZED ZONEMAP sales_zmap REFRESH FAST ON COMMIT; 3 | ALTER MATERIALIZED ZONEMAP sales_zmap DISABLE PRUNING; 4 | ALTER MATERIALIZED ZONEMAP sales_zmap COMPILE; 5 | ALTER MATERIALIZED ZONEMAP sales_zmap REBUILD; 6 | ALTER MATERIALIZED ZONEMAP sales_zmap UNUSABLE; -------------------------------------------------------------------------------- /examples/alter_mv.sql: -------------------------------------------------------------------------------- 1 | ALTER MATERIALIZED VIEW sales_by_month_by_state 2 | REFRESH FAST; 3 | 4 | ALTER MATERIALIZED VIEW sales_by_month_by_state 5 | REFRESH NEXT SYSDATE+7; 6 | ALTER MATERIALIZED VIEW sales_by_month_by_state CONSIDER FRESH; 7 | 8 | ALTER MATERIALIZED VIEW emp_data 9 | REFRESH COMPLETE 10 | START WITH TRUNC(SYSDATE+1) + 9/24 11 | NEXT SYSDATE+7; 12 | ALTER MATERIALIZED VIEW emp_data 13 | ENABLE QUERY REWRITE; 14 | ALTER MATERIALIZED VIEW order_data 15 | REFRESH WITH PRIMARY KEY; 16 | ALTER MATERIALIZED VIEW order_data COMPILE; 17 | -------------------------------------------------------------------------------- /examples/alter_mv_log.sql: -------------------------------------------------------------------------------- 1 | ALTER MATERIALIZED VIEW LOG ON order_items ADD ROWID; 2 | 3 | ALTER MATERIALIZED VIEW LOG ON employees 4 | ADD (commission_pct) 5 | EXCLUDING NEW VALUES; 6 | -------------------------------------------------------------------------------- /examples/alter_operator.sql: -------------------------------------------------------------------------------- 1 | ALTER OPERATOR eq_op COMPILE; 2 | -------------------------------------------------------------------------------- /examples/alter_outline.sql: -------------------------------------------------------------------------------- 1 | ALTER OUTLINE salaries REBUILD; 2 | -------------------------------------------------------------------------------- /examples/alter_partition.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLE table1 MODIFY PARTITION BY LIST(color)( 2 | partition RED VALUES ('RED'), 3 | partition BLUE VALUES ('BLUE') 4 | ); -------------------------------------------------------------------------------- /examples/alter_pmem_filestore.sql: -------------------------------------------------------------------------------- 1 | ALTER PMEM FILESTORE cloud_db_1 RESIZE 5T; 2 | 3 | ALTER PMEM FILESTORE cloud_db_1 MOUNT MOUNTPOINT '/corp/db/cloud_db_1' 4 | BACKINGFILE '/var/pmem/foo_1'; 5 | 6 | ALTER PMEM FILESTORE cloud_db_1 DISMOUNT; 7 | -------------------------------------------------------------------------------- /examples/alter_resource_cost.sql: -------------------------------------------------------------------------------- 1 | ALTER RESOURCE COST 2 | CPU_PER_SESSION 100 3 | CONNECT_TIME 1; 4 | 5 | ALTER RESOURCE COST 6 | LOGICAL_READS_PER_SESSION 2 7 | CONNECT_TIME 0; 8 | -------------------------------------------------------------------------------- /examples/alter_role.sql: -------------------------------------------------------------------------------- 1 | alter role TEST_ROLE_AAA NOT IDENTIFIED; 2 | 3 | alter role TEST_ROLE_AAA IDENTIFIED BY data; 4 | 5 | alter role TEST_ROLE_AAA IDENTIFIED EXTERNALLY; 6 | 7 | ALTER ROLE TEST_ROLE_AAA IDENTIFIED USING hr.admin; 8 | 9 | alter role TEST_ROLE_AAA IDENTIFIED GLOBALLY; 10 | 11 | 12 | ALTER ROLE dw_manager IDENTIFIED GLOBALLY AS 'domain_name_of_directory_group' ; 13 | ALTER ROLE warehouse_user NOT IDENTIFIED CONTAINER = CURRENT; 14 | ALTER ROLE warehouse_user NOT IDENTIFIED CONTAINER = ALL; 15 | -------------------------------------------------------------------------------- /examples/alter_rollback_segment.sql: -------------------------------------------------------------------------------- 1 | ALTER ROLLBACK SEGMENT rbs_one ONLINE; 2 | ALTER ROLLBACK SEGMENT rbs_one SHRINK TO 100M; -------------------------------------------------------------------------------- /examples/alter_session.sql: -------------------------------------------------------------------------------- 1 | ALTER SESSION 2 | SET QUERY_REWRITE_ENABLED = TRUE; 3 | 4 | ALTER SESSION 5 | SET NLS_SORT = XSpanish; 6 | 7 | ALTER SESSION 8 | SET NLS_LANGUAGE = FRENCH; 9 | 10 | ALTER SESSION SET NLS_CURRENCY = 'FF'; 11 | 12 | ALTER SESSION 13 | ADVISE COMMIT; 14 | 15 | ALTER SESSION ENABLE PARALLEL DML; 16 | -------------------------------------------------------------------------------- /examples/alter_synonym01.sql: -------------------------------------------------------------------------------- 1 | alter synonym emp compile; 2 | alter public synonym emp compile; 3 | alter public synonym emp noneditionable; 4 | alter public synonym sch.emp editionable; 5 | -------------------------------------------------------------------------------- /examples/alter_table.sql: -------------------------------------------------------------------------------- 1 | alter table hr.employees 2 | add constraint emp_fk foreign key (department_id) 3 | references hr.departments (department_id) 4 | on delete cascade; 5 | 6 | alter table hr.employees 7 | add foreign key (department_id) 8 | references hr.departments (department_id) 9 | on delete set null; 10 | 11 | alter table hr.employees 12 | add constraint emp_fk foreign key (department_id, employee_id) 13 | references hr.some_table (department_id, employee_id); 14 | 15 | alter table employees 16 | add primary key (employee_id); 17 | 18 | alter table hr.employees 19 | add constraint emp_complex_pk primary key (employee_id, department_id); 20 | 21 | alter table hr.employees 22 | add constraint emp_uq unique (employee_id, email); 23 | 24 | alter table employees 25 | add unique (employee_id); 26 | 27 | ALTER TABLE suppliers 28 | ADD CONSTRAINT check_supplier_name 29 | CHECK (supplier_name IN ('IBM', 'Microsoft', 'NVIDIA')); 30 | 31 | ALTER TABLE suppliers 32 | DROP CONSTRAINT check_supplier_id; 33 | 34 | ALTER TABLE suppliers 35 | ENABLE CONSTRAINT check_supplier_id; 36 | 37 | ALTER TABLE suppliers 38 | DISABLE CONSTRAINT check_supplier_id; 39 | 40 | ALTER TABLE customers 41 | PARALLEL; 42 | 43 | ALTER TABLE employees 44 | DEALLOCATE UNUSED; 45 | 46 | ALTER TABLE countries_demo INITRANS 4; 47 | 48 | ALTER TABLE employees 49 | PCTFREE 30 50 | PCTUSED 60; 51 | 52 | ALTER TABLE employees 53 | ALLOCATE EXTENT (SIZE 5K INSTANCE 4); 54 | 55 | ALTER TABLE customers 56 | ADD (online_acct_pw VARCHAR2(8) ENCRYPT 'NOMAC' NO SALT ); 57 | 58 | ALTER TABLE employees ADD (resume CLOB) 59 | LOB (resume) STORE AS resume_seg (TABLESPACE example); 60 | 61 | ALTER TABLE employees ADD (resume CLOB) 62 | LOB (resume) STORE AS SECUREFILE resume_seg (TABLESPACE auto_seg_ts); 63 | 64 | ALTER TABLE employees ADD (skills number) 65 | NESTED TABLE skills STORE AS nested_skill_table; 66 | 67 | ALTER TABLE employees 68 | ENABLE VALIDATE CONSTRAINT emp_manager_fk 69 | EXCEPTIONS INTO exceptions; 70 | 71 | ALTER TABLE print_media MODIFY NESTED TABLE ad_textdocs_ntab 72 | RETURN AS VALUE; 73 | 74 | ALTER TABLE employees 75 | ENABLE NOVALIDATE PRIMARY KEY 76 | ENABLE NOVALIDATE CONSTRAINT emp_last_name_nn; 77 | 78 | ALTER TABLE locations 79 | MODIFY PRIMARY KEY DISABLE CASCADE; 80 | 81 | ALTER TABLE employees ADD CONSTRAINT check_comp 82 | CHECK (salary + (commission_pct*salary) <= 5000) 83 | DISABLE; 84 | 85 | ALTER TABLE employees 86 | ENABLE ALL TRIGGERS; 87 | 88 | ALTER TABLE employees 89 | DEALLOCATE UNUSED; 90 | 91 | ALTER TABLE customers 92 | RENAME COLUMN credit_limit TO credit_amount; 93 | 94 | ALTER TABLE t1 DROP (pk) CASCADE CONSTRAINTS; 95 | 96 | ALTER TABLE t1 DROP (pk, fk, c1); 97 | ALTER TABLE customers 98 | MODIFY (online_acct_pw DECRYPT); 99 | 100 | ALTER TABLE departments 101 | DROP PRIMARY KEY CASCADE; 102 | 103 | ALTER TABLE employees 104 | DROP UNIQUE (email); 105 | 106 | ALTER TABLE employees MODIFY LOB (resume) (CACHE); 107 | 108 | ALTER TABLE employees MODIFY LOB (resume) (NOCACHE); 109 | 110 | ALTER TABLE employees MODIFY LOB (resume) (NOCACHE); 111 | 112 | alter TABLE employee add ( constraint employee_pk UNique ( a , b ) ) ; 113 | 114 | alter table employee 115 | add constraint emp_fk foreign key (col1, col2) references other; 116 | 117 | alter table employee 118 | add constraint emp_fk foreign key (col1, col2) references other on delete set null; 119 | 120 | alter table employee 121 | add constraint emp_fk foreign key (col1, col2) references other on delete cascade; 122 | 123 | ALTER TABLE TABLE_A 124 | ADD TABLE_B_ID NUMBER(5) 125 | ADD FOREIGN KEY (TABLE_B_ID) REFERENCES TABLE_B (ID); 126 | 127 | ALTER TABLE S.PRODUCTS 128 | DROP PARTITION 129 | FOR 101; 130 | 131 | ALTER TABLE S.PRODUCTS 132 | DROP PARTITION p0 133 | UPDATE GLOBAL INDEXES; 134 | 135 | ALTER TABLE S.PRODUCTS 136 | DROP PARTITION p0 137 | INVALIDATE GLOBAL INDEXES; 138 | 139 | ALTER TABLE S.PRODUCTS 140 | DROP PARTITION p0 141 | UPDATE INDEXES; 142 | 143 | ALTER TABLE S.PRODUCTS 144 | DROP PARTITION p0 145 | UPDATE GLOBAL INDEXES NOPARALLEL; 146 | 147 | ALTER TABLE S.PRODUCTS 148 | DROP PARTITION p0 149 | INVALIDATE GLOBAL INDEXES NOPARALLEL; 150 | 151 | ALTER TABLE S.PRODUCTS 152 | DROP PARTITION p0 153 | UPDATE INDEXES NOPARALLEL; 154 | 155 | ALTER TABLE B.EXCHANGE_LOG 156 | DROP PARTITION 157 | FOR (TIMESTAMP '2022-01-28 00:00:00') 158 | UPDATE GLOBAL INDEXES ; 159 | 160 | ALTER TABLE mesg_perf_stat 161 | TRUNCATE PARTITION SYS_P1221396 162 | DROP STORAGE CASCADE UPDATE INDEXES; 163 | 164 | ALTER TABLE employees MEMOPTIMIZE FOR READ 165 | ENABLE VALIDATE CONSTRAINT emp_manager_fk 166 | EXCEPTIONS INTO exceptions; 167 | 168 | ALTER TABLE employees NO MEMOPTIMIZE FOR READ 169 | ENABLE VALIDATE CONSTRAINT emp_manager_fk 170 | EXCEPTIONS INTO exceptions; 171 | 172 | ALTER TABLE employees MEMOPTIMIZE FOR WRITE 173 | ENABLE VALIDATE CONSTRAINT emp_manager_fk 174 | EXCEPTIONS INTO exceptions; 175 | 176 | ALTER TABLE employees NO MEMOPTIMIZE FOR WRITE 177 | ENABLE VALIDATE CONSTRAINT emp_manager_fk 178 | EXCEPTIONS INTO exceptions; 179 | 180 | -------------------------------------------------------------------------------- /examples/alter_table_inmemory.sql: -------------------------------------------------------------------------------- 1 | -- inmemory_table_clause 2 | ALTER TABLE customer INMEMORY; 3 | 4 | ALTER TABLE customer NO INMEMORY; 5 | 6 | -- inmemory_memcompress 7 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR DML; 8 | 9 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR QUERY; 10 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR QUERY LOW; 11 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR QUERY HIGH; 12 | 13 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR CAPACITY; 14 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR CAPACITY LOW; 15 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR CAPACITY HIGH; 16 | 17 | ALTER TABLE customer INMEMORY NO MEMCOMPRESS; 18 | 19 | -- inmemory_priority 20 | ALTER TABLE customer INMEMORY PRIORITY NONE; 21 | ALTER TABLE customer INMEMORY PRIORITY LOW; 22 | ALTER TABLE customer INMEMORY PRIORITY MEDIUM; 23 | ALTER TABLE customer INMEMORY PRIORITY HIGH; 24 | ALTER TABLE customer INMEMORY PRIORITY CRITICAL; 25 | 26 | -- inmemory_distribute 27 | ALTER TABLE customer INMEMORY DISTRIBUTE; 28 | ALTER TABLE customer INMEMORY DISTRIBUTE AUTO; 29 | ALTER TABLE customer INMEMORY DISTRIBUTE BY ROWID RANGE; 30 | ALTER TABLE customer INMEMORY DISTRIBUTE BY PARTITION; 31 | ALTER TABLE customer INMEMORY DISTRIBUTE BY SUBPARTITION; 32 | 33 | ALTER TABLE customer INMEMORY DISTRIBUTE FOR SERVICE DEFAULT; 34 | ALTER TABLE customer INMEMORY DISTRIBUTE FOR SERVICE ALL; 35 | ALTER TABLE customer INMEMORY DISTRIBUTE FOR SERVICE some_service; 36 | ALTER TABLE customer INMEMORY DISTRIBUTE FOR SERVICE NONE; 37 | 38 | ALTER TABLE customer INMEMORY DISTRIBUTE BY ROWID RANGE FOR SERVICE DEFAULT; 39 | 40 | -- inmemory_duplicate 41 | ALTER TABLE customer INMEMORY DUPLICATE; 42 | ALTER TABLE customer INMEMORY DUPLICATE ALL; 43 | ALTER TABLE customer INMEMORY NO DUPLICATE; 44 | 45 | -- inmemory_column_clause 46 | ALTER TABLE customer INMEMORY INMEMORY (customer_name); 47 | ALTER TABLE customer INMEMORY (customer_name, customer_id); 48 | ALTER TABLE customer INMEMORY (name) INMEMORY (customer_id); 49 | ALTER TABLE customer INMEMORY (name) NO INMEMORY (customer_id); 50 | ALTER TABLE customer INMEMORY MEMCOMPRESS FOR QUERY LOW (name) NO INMEMORY (customer_id); 51 | 52 | -- verify usage of ... as regular id 53 | CREATE TABLE vendor (SERVICE VARCHAR2(100)); 54 | -------------------------------------------------------------------------------- /examples/alter_tablespace_set.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLESPACE SET ts1 2 | FORCE LOGGING; 3 | -------------------------------------------------------------------------------- /examples/alter_tablespaces.sql: -------------------------------------------------------------------------------- 1 | ALTER TABLESPACE tbs_01 2 | BEGIN BACKUP; 3 | ALTER TABLESPACE tbs_01 4 | END BACKUP; 5 | 6 | ALTER TABLESPACE tbs_02 OFFLINE NORMAL; 7 | 8 | ALTER TABLESPACE tbs_02 9 | RENAME DATAFILE 'diskb:tbs_f5.dbf' 10 | TO 'diska:tbs_f5.dbf'; 11 | 12 | ALTER TABLESPACE tbs_02 ONLINE; 13 | 14 | ALTER TABLESPACE tbs_03 15 | ADD DATAFILE 'tbs_f04.dbf' 16 | SIZE 100K 17 | AUTOEXTEND ON 18 | NEXT 10K 19 | MAXSIZE 100K; 20 | 21 | ALTER TABLESPACE tbs_03 22 | DROP DATAFILE 'tbs_f04.dbf'; 23 | 24 | ALTER TABLESPACE temp_demo ADD TEMPFILE 'temp05.dbf' SIZE 5 AUTOEXTEND ON; 25 | 26 | ALTER TABLESPACE temp_demo DROP TEMPFILE 'temp05.dbf'; 27 | 28 | ALTER TABLESPACE temp_demo SHRINK SPACE; 29 | 30 | ALTER TABLESPACE omf_ts1 ADD DATAFILE; 31 | 32 | ALTER TABLESPACE tbs_03 NOLOGGING; 33 | ALTER TABLESPACE undots1 34 | RETENTION NOGUARANTEE; 35 | ALTER TABLESPACE undots1 36 | RETENTION GUARANTEE; 37 | -------------------------------------------------------------------------------- /examples/alter_view.sql: -------------------------------------------------------------------------------- 1 | ALTER VIEW customer_ro 2 | COMPILE; 3 | ALTER VIEW customer_ro 4 | EDITIONABLE; 5 | 6 | -------------------------------------------------------------------------------- /examples/analytic_query.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 | select times.time_id, product, quantity from inventory 12 | partition by (product) 13 | right outer join times on (times.time_id = inventory.time_id) 14 | where times.time_id between to_date('01/04/01', 'dd/mm/yy') 15 | and to_date('06/04/01', 'dd/mm/yy') 16 | order by 2,1; 17 | 18 | select deptno 19 | , ename 20 | , hiredate 21 | , listagg(ename, ',') within group (order by hiredate) over (partition by deptno) as employees 22 | from emp; 23 | 24 | select deptno 25 | , ename 26 | , hiredate 27 | , listagg(ename, ',' ON OVERFLOW ERROR) within group (order by hiredate) over (partition by deptno) as employees 28 | from emp; 29 | 30 | select deptno 31 | , ename 32 | , hiredate 33 | , listagg(ename, ',' ON OVERFLOW TRUNCATE) within group (order by hiredate) over (partition by deptno) as employees 34 | from emp; 35 | 36 | select deptno 37 | , ename 38 | , hiredate 39 | , listagg(UNIQUE ename, ',' ON OVERFLOW TRUNCATE) within group (order by hiredate) over (partition by deptno) as employees 40 | , listagg(UNIQUE edepartment, ',' ON OVERFLOW TRUNCATE) within group (order by hiredate) over (partition by deptno) as edepartments 41 | from emp; 42 | 43 | select metric_id ,bsln_guid ,timegroup ,obs_value as obs_value 44 | , cume_dist () over (partition by metric_id, bsln_guid, timegroup order by obs_value ) as cume_dist 45 | , count(1) over (partition by metric_id, bsln_guid, timegroup ) as n 46 | , row_number () over (partition by metric_id, bsln_guid, timegroup order by obs_value) as rrank 47 | , percentile_disc(:b7 ) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as mid_tail_value 48 | , max(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as max_val 49 | , min(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as min_val 50 | , avg(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as avg_val 51 | , stddev(obs_value) over (partition by metric_id, bsln_guid, timegroup ) as sdev_val 52 | , percentile_cont(0.25) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_25 53 | , percentile_cont(0.5) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_50 54 | , percentile_cont(0.75) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_75 55 | , percentile_cont(0.90) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_90 56 | , percentile_cont(0.95) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_95 57 | , percentile_cont(0.99) within group (order by obs_value asc) over (partition by metric_id, bsln_guid, timegroup) as pctile_99 58 | from timegrouped_rawdata d; 59 | 60 | select trim(both ' ' from ' a ') from dual where trim(:a) is not null; 61 | 62 | with 63 | clus_tab as ( 64 | select id, 65 | a.attribute_name aname, 66 | a.conditional_operator op, 67 | nvl(a.attribute_str_value, 68 | round(decode(a.attribute_name, n.col, 69 | a.attribute_num_value * n.scale + n.shift, 70 | a.attribute_num_value),4)) val, 71 | a.attribute_support support, 72 | a.attribute_confidence confidence 73 | from table(dbms_data_mining.get_model_details_km('km_sh_clus_sample')) t, 74 | table(t.rule.antecedent) a, 75 | km_sh_sample_norm n 76 | where a.attribute_name = n.col (+) and a.attribute_confidence > 0.55 77 | ), 78 | clust as ( 79 | select id, 80 | cast(collect(cattr(aname, op, to_char(val), support, confidence)) as cattrs) cl_attrs 81 | from clus_tab 82 | group by id 83 | ), 84 | custclus as ( 85 | select t.cust_id, s.cluster_id, s.probability 86 | from (select 87 | cust_id 88 | , cluster_set(km_sh_clus_sample, null, 0.2 using *) pset 89 | from km_sh_sample_apply_prepared 90 | where cust_id = 101362) t, 91 | table(t.pset) s 92 | ) 93 | select a.probability prob, a.cluster_id cl_id, 94 | b.attr, b.op, b.val, b.supp, b.conf 95 | from custclus a, 96 | (select t.id, c.* 97 | from clust t, 98 | table(t.cl_attrs) c) b 99 | where a.cluster_id = b.id 100 | order by prob desc, cl_id asc, conf desc, attr asc, val asc; 101 | 102 | -------------------------------------------------------------------------------- /examples/analyze.sql: -------------------------------------------------------------------------------- 1 | ANALYZE TABLE orders DELETE STATISTICS; 2 | ANALYZE INDEX inv_product_ix VALIDATE STRUCTURE; 3 | ANALYZE TABLE employees VALIDATE STRUCTURE CASCADE; 4 | ANALYZE TABLE customers VALIDATE REF UPDATE; 5 | ANALYZE TABLE customers VALIDATE STRUCTURE ONLINE; 6 | ANALYZE CLUSTER personnel 7 | VALIDATE STRUCTURE CASCADE; 8 | ANALYZE TABLE orders 9 | LIST CHAINED ROWS INTO chained_rows; 10 | -------------------------------------------------------------------------------- /examples/associate_statistics.sql: -------------------------------------------------------------------------------- 1 | ASSOCIATE STATISTICS WITH PACKAGES emp_mgmt DEFAULT SELECTIVITY 10; 2 | ASSOCIATE STATISTICS WITH INDEXES salary_index DEFAULT COST (100,5,0); 3 | -------------------------------------------------------------------------------- /examples/audit.sql: -------------------------------------------------------------------------------- 1 | AUDIT ROLE; 2 | AUDIT ROLE 3 | WHENEVER SUCCESSFUL; 4 | AUDIT ROLE 5 | WHENEVER NOT SUCCESSFUL; 6 | AUDIT SELECT TABLE, UPDATE TABLE; 7 | AUDIT SELECT TABLE, UPDATE TABLE 8 | BY hr, oe; 9 | AUDIT DELETE ANY TABLE; 10 | AUDIT CREATE ANY DIRECTORY; 11 | AUDIT DIRECTORY; 12 | AUDIT READ ON DIRECTORY bfile_dir; 13 | AUDIT SELECT 14 | ON hr.employees; 15 | AUDIT SELECT 16 | ON hr.employees 17 | WHENEVER SUCCESSFUL; 18 | AUDIT SELECT 19 | ON hr.employees 20 | WHENEVER NOT SUCCESSFUL; 21 | AUDIT INSERT, UPDATE 22 | ON oe.customers; 23 | AUDIT ALL 24 | ON hr.employees_seq; 25 | AUDIT ALTER, GRANT, INSERT, UPDATE, DELETE 26 | ON DEFAULT; 27 | 28 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/bindvar02.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from a 3 | where a=:3 4 | and b= : 4 5 | and c= :5and :a = :b 6 | 7 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/bulk_collect_fetch_clause01.sql: -------------------------------------------------------------------------------- 1 | declare 2 | cursor cur_div is 3 | select rid, code from tmp_data_item_value_euro; 4 | lvnCount number := 0; 5 | type cCurDiv_t is table of cur_div%Rowtype; 6 | lvaCurDiv cCurDiv_t; 7 | begin 8 | open cur_div; 9 | 10 | loop 11 | fetch cur_div bulk collect into lvaCurDiv limit 100000; 12 | exit when lvaCurDiv.count = 0; 13 | 14 | forall i in lvaCurDiv.first .. lvaCurDiv.last 15 | update data_item_value set unit_code = lvaCurDiv(i).code where rowid = lvaCurDiv(i).rid; 16 | 17 | commit; 18 | end loop; 19 | close cur_div; 20 | commit; 21 | end; -------------------------------------------------------------------------------- /examples/call.sql: -------------------------------------------------------------------------------- 1 | CALL my_procedure(arg1 => 3, arg2 => 4) ; 2 | 3 | CALL my_procedure(3, 4) ; 4 | 5 | CALL my_procedure(3, arg2 => 4) ; 6 | 7 | CALL emp_mgmt.remove_dept(162); 8 | 9 | CALL warehouse_typ(456, 'Warehouse 456', 2236).ret_name() INTO :x; -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 -------------------------------------------------------------------------------- /examples/case_when06.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | case 3 | when STaLENESS > .5 then 128 4 | when STaLENESS > .1 then 256 5 | else 0 6 | end aFLaGS 7 | FROM employees 8 | -------------------------------------------------------------------------------- /examples/case_when07.sql: -------------------------------------------------------------------------------- 1 | SELECT h1.CRTYPE , 2 | CASE 'month' 3 | WHEN 'week' THEN TO_CHAR(h1.DateFrom, 'YYYYIW') 4 | ELSE to_char(h1.DateFrom,'YYYYMM') 5 | END 6 | FROM CQ_CHANGEREQUESTS h1 -------------------------------------------------------------------------------- /examples/cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | cast(raw_value as date, 'YYYY-MM-DD'), 4 | cast(raw_value as date, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN'), 5 | cast(raw_value as number default null on conversion error), 6 | cast(raw_value as number default 9999 on conversion error), 7 | cast(raw_value as date default null on conversion error, 'YYYY-MM-DD'), 8 | cast(raw_value as date default null on conversion error, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN') 9 | from raw_values; -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 -------------------------------------------------------------------------------- /examples/cast_multiset05.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from 3 | table 4 | ( 5 | function_name() 6 | ) 7 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/cast_multiset08.sql: -------------------------------------------------------------------------------- 1 | select * from table (cast (f_int_date_varchar2() as table_int_date_varchar2)) 2 | -------------------------------------------------------------------------------- /examples/cluster.sql: -------------------------------------------------------------------------------- 1 | CREATE CLUSTER personnel 2 | (department NUMBER(4)) 3 | SIZE 512 4 | STORAGE (initial 100K next 50K); 5 | 6 | CREATE INDEX idx_personnel ON CLUSTER personnel; 7 | 8 | CREATE CLUSTER language (cust_language VARCHAR2(3)) 9 | SIZE 512 HASHKEYS 10 10 | STORAGE (INITIAL 100k next 50k); 11 | 12 | CREATE CLUSTER address 13 | (postal_code NUMBER, country_id CHAR(2)) 14 | HASHKEYS 20 15 | HASH IS MOD(postal_code + country_id, 101); 16 | 17 | CREATE CLUSTER cust_orders (customer_id NUMBER(6)) 18 | SIZE 512 SINGLE TABLE HASHKEYS 100; 19 | 20 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/comment_on.sql: -------------------------------------------------------------------------------- 1 | -- column 2 | 3 | comment on column employees.employee_id is 'Primary key of employees table.'; 4 | 5 | comment on column hr.employees.employee_id is 'Multiline 6 | comment on column.'; 7 | 8 | comment on column "hr"."employees"."employee_id" is 'Primary key of employees table.'; 9 | 10 | 11 | -- add example: fix when comment on column with schema, the parser is report syntax error 12 | comment on column s.a.c1 is 'comment'; 13 | 14 | -- table 15 | 16 | comment on table employees is 'employees table. Contains 107 rows.'; 17 | 18 | comment on table hr.employees is 'employees table. Contains 107 rows.'; 19 | 20 | comment on table "hr"."employees" is 'employees table. Contains 107 rows.'; 21 | 22 | comment on table "my schema"."my table" is 'Some demo table with space in its name 23 | and a multiline comment.'; 24 | 25 | COMMENT ON MATERIALIZED VIEW "MONITOR"."SQL_ALERT_LOG_ERRORS" IS 26 | 'snapshot table for snapshot MONITOR.SQL_ALERT_LOG_ERRORS'; -------------------------------------------------------------------------------- /examples/comments.sql: -------------------------------------------------------------------------------- 1 | -- com1 2 | select * /* 3 | com2 */ 4 | from dual -- com3 5 | 6 | Rem Copyright (c) All Rights Reserved. 7 | 8 | prompt . ## Hello world -------------------------------------------------------------------------------- /examples/commit.sql: -------------------------------------------------------------------------------- 1 | COMMIT; 2 | COMMIT WORK; 3 | COMMIT WRITE BATCH; 4 | COMMIT COMMENT 'TEST' WRITE NOWAIT IMMEDIATE; 5 | COMMIT WORK COMMENT 'TEXT'; 6 | COMMIT FORCE '22.57.53'; 7 | COMMIT WORK FORCE '22.57.53'; 8 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/condition07.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from append 3 | where 4 | -- note space between '>' and '=' 5 | (length(w.numer) > = 8) 6 | -------------------------------------------------------------------------------- /examples/condition08.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from "p" 3 | where 4 | -- note there are no parens around 231092 5 | ( ( "p"."id" in 231092 ) ) 6 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/condition14.sql: -------------------------------------------------------------------------------- 1 | select * from dual where trim(sxhnode_key) is not null 2 | 3 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/condition16.sql: -------------------------------------------------------------------------------- 1 | select * from persons p 2 | where value(p) is of type(only employee_t) 3 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/context.sql: -------------------------------------------------------------------------------- 1 | CREATE CONTEXT hr_context USING emp_mgmt; 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/create_analytic_view.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE ANALYTIC VIEW sales_av 2 | USING sales_fact 3 | DIMENSION BY 4 | (time_attr_dim -- An attribute dimension of time data 5 | KEY month_id REFERENCES month_id 6 | HIERARCHIES ( 7 | time_hier DEFAULT), 8 | product_attr_dim -- An attribute dimension of product data 9 | KEY category_id REFERENCES category_id 10 | HIERARCHIES ( 11 | product_hier DEFAULT), 12 | geography_attr_dim -- An attribute dimension of store data 13 | KEY state_province_id 14 | REFERENCES state_province_id HIERARCHIES ( 15 | geography_hier DEFAULT) 16 | ) 17 | MEASURES( 18 | sales FACT sales, -- A base measure 19 | units FACT units, -- A base measure 20 | -- Calculated measures 21 | sales_prior_period AS (LAG(sales) OVER (HIERARCHY time_hier OFFSET 1)), 22 | sales_year_ago AS (LAG(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL year)), 23 | chg_sales_year_ago AS (LAG_DIFF(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL year)), 24 | pct_chg_sales_year_ago AS (LAG_DIFF_PERCENT(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL year)), 25 | sales_qtr_ago AS (LAG(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL quarter)), 26 | chg_sales_qtr_ago AS (LAG_DIFF(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL quarter)), 27 | pct_chg_sales_qtr_ago AS (LAG_DIFF_PERCENT(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL quarter)) 28 | ) 29 | DEFAULT MEASURE SALES; 30 | 31 | CREATE OR REPLACE ANALYTIC VIEW sales_av 32 | USING av.sales_fact 33 | DIMENSION BY 34 | (time_attr_dim 35 | KEY month_id REFERENCES month_id 36 | HIERARCHIES ( 37 | time_hier DEFAULT), 38 | product_attr_dim 39 | KEY category_id REFERENCES category_id 40 | HIERARCHIES ( 41 | product_hier DEFAULT), 42 | geography_attr_dim 43 | KEY state_province_id 44 | REFERENCES state_province_id 45 | HIERARCHIES ( 46 | geography_hier DEFAULT) 47 | ) 48 | MEASURES 49 | (sales FACT sales, 50 | sales_year_ago AS (LAG(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL year)), 51 | sales_pct_chg_year_ago AS (ROUND(LAG_DIFF_PERCENT(sales) OVER (HIERARCHY time_hier OFFSET 1 ACROSS ANCESTOR AT LEVEL year),2)), 52 | units FACT units 53 | ) 54 | DEFAULT MEASURE SALES; 55 | 56 | CREATE OR REPLACE ANALYTIC VIEW sales_av 57 | USING av.sales_fact 58 | DIMENSION BY 59 | (time_attr_dim 60 | KEY month_id REFERENCES month_id 61 | HIERARCHIES ( 62 | time_hier DEFAULT)) 63 | MEASURES 64 | (sales FACT sales, 65 | avg_sales FACT sales AGGREGATE BY AVG, 66 | count_sales FACT sales AGGREGATE BY COUNT, 67 | max_sales FACT sales AGGREGATE BY MAX, 68 | min_sales FACT sales AGGREGATE BY MIN, 69 | stddev_sales FACT sales AGGREGATE BY STDDEV, 70 | variance_sales FACT sales AGGREGATE BY VARIANCE, 71 | units FACT units, 72 | avg_units FACT units AGGREGATE BY AVG 73 | ) 74 | DEFAULT MEASURE SALES 75 | DEFAULT AGGREGATE BY SUM; 76 | -------------------------------------------------------------------------------- /examples/create_attribute_dimension.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE ATTRIBUTE DIMENSION time_attr_dim 2 | DIMENSION TYPE TIME 3 | USING time_dim 4 | ATTRIBUTES 5 | (year_id 6 | CLASSIFICATION caption VALUE 'YEAR_ID' 7 | CLASSIFICATION description VALUE 'YEAR ID', 8 | year_name 9 | CLASSIFICATION caption VALUE 'YEAR_NAME' 10 | CLASSIFICATION description VALUE 'Year', 11 | year_end_date 12 | CLASSIFICATION caption VALUE 'YEAR_END_DATE' 13 | CLASSIFICATION description VALUE 'Year End Date', 14 | quarter_id 15 | CLASSIFICATION caption VALUE 'QUARTER_ID' 16 | CLASSIFICATION description VALUE 'QUARTER ID', 17 | quarter_name 18 | CLASSIFICATION caption VALUE 'QUARTER_NAME' 19 | CLASSIFICATION description VALUE 'Quarter', 20 | quarter_end_date 21 | CLASSIFICATION caption VALUE 'QUARTER_END_DATE' 22 | CLASSIFICATION description VALUE 'Quarter End Date', 23 | quarter_of_year 24 | CLASSIFICATION caption VALUE 'QUARTER_OF_YEAR' 25 | CLASSIFICATION description VALUE 'Quarter of Year', 26 | month_id 27 | CLASSIFICATION caption VALUE 'MONTH_ID' 28 | CLASSIFICATION description VALUE 'MONTH ID', 29 | month_name 30 | CLASSIFICATION caption VALUE 'MONTH_NAME' 31 | CLASSIFICATION description VALUE 'Month', 32 | month_long_name 33 | CLASSIFICATION caption VALUE 'MONTH_LONG_NAME' 34 | CLASSIFICATION description VALUE 'Month Long Name', 35 | month_end_date 36 | CLASSIFICATION caption VALUE 'MONTH_END_DATE' 37 | CLASSIFICATION description VALUE 'Month End Date', 38 | month_of_quarter 39 | CLASSIFICATION caption VALUE 'MONTH_OF_QUARTER' 40 | CLASSIFICATION description VALUE 'Month of Quarter', 41 | month_of_year 42 | CLASSIFICATION caption VALUE 'MONTH_OF_YEAR' 43 | CLASSIFICATION description VALUE 'Month of Year', 44 | season 45 | CLASSIFICATION caption VALUE 'SEASON' 46 | CLASSIFICATION description VALUE 'Season', 47 | season_order 48 | CLASSIFICATION caption VALUE 'SEASON_ORDER' 49 | CLASSIFICATION description VALUE 'Season Order') 50 | LEVEL month 51 | LEVEL TYPE MONTHS 52 | CLASSIFICATION caption VALUE 'MONTH' 53 | CLASSIFICATION description VALUE 'Month' 54 | KEY month_id 55 | MEMBER NAME month_name 56 | MEMBER CAPTION month_name 57 | MEMBER DESCRIPTION month_long_name 58 | ORDER BY month_end_date 59 | DETERMINES (month_end_date, 60 | quarter_id, 61 | season, 62 | season_order, 63 | month_of_year, 64 | month_of_quarter) 65 | LEVEL quarter 66 | LEVEL TYPE QUARTERS 67 | CLASSIFICATION caption VALUE 'QUARTER' 68 | CLASSIFICATION description VALUE 'Quarter' 69 | KEY quarter_id 70 | MEMBER NAME quarter_name 71 | MEMBER CAPTION quarter_name 72 | MEMBER DESCRIPTION quarter_name 73 | ORDER BY quarter_end_date 74 | DETERMINES (quarter_end_date, 75 | quarter_of_year, 76 | year_id) 77 | LEVEL year 78 | LEVEL TYPE YEARS 79 | CLASSIFICATION caption VALUE 'YEAR' 80 | CLASSIFICATION description VALUE 'Year' 81 | KEY year_id 82 | MEMBER NAME year_name 83 | MEMBER CAPTION year_name 84 | MEMBER DESCRIPTION year_name 85 | ORDER BY year_end_date 86 | DETERMINES (year_end_date) 87 | LEVEL season 88 | LEVEL TYPE QUARTERS 89 | CLASSIFICATION caption VALUE 'SEASON' 90 | CLASSIFICATION description VALUE 'Season' 91 | KEY season 92 | MEMBER NAME season 93 | MEMBER CAPTION season 94 | MEMBER DESCRIPTION season 95 | LEVEL month_of_quarter 96 | LEVEL TYPE MONTHS 97 | CLASSIFICATION caption VALUE 'MONTH_OF_QUARTER' 98 | CLASSIFICATION description VALUE 'Month of Quarter' 99 | KEY month_of_quarter; 100 | 101 | CREATE OR REPLACE ATTRIBUTE DIMENSION product_attr_dim 102 | USING product_dim 103 | ATTRIBUTES 104 | (department_id, 105 | department_name, 106 | category_id, 107 | category_name) 108 | LEVEL DEPARTMENT 109 | KEY department_id 110 | ALTERNATE KEY department_name 111 | MEMBER NAME department_name 112 | MEMBER CAPTION department_name 113 | ORDER BY department_name 114 | LEVEL CATEGORY 115 | KEY category_id 116 | ALTERNATE KEY category_name 117 | MEMBER NAME category_name 118 | MEMBER CAPTION category_name 119 | ORDER BY category_name 120 | DETERMINES(department_id) 121 | ALL MEMBER NAME 'ALL PRODUCTS'; 122 | 123 | CREATE OR REPLACE ATTRIBUTE DIMENSION geography_attr_dim 124 | USING geography_dim 125 | ATTRIBUTES 126 | (region_id, 127 | region_name, 128 | country_id, 129 | country_name, 130 | state_province_id, 131 | state_province_name) 132 | LEVEL REGION 133 | KEY region_id 134 | ALTERNATE KEY region_name 135 | MEMBER NAME region_name 136 | MEMBER CAPTION region_name 137 | ORDER BY region_name 138 | LEVEL COUNTRY 139 | KEY country_id 140 | ALTERNATE KEY country_name 141 | MEMBER NAME country_name 142 | MEMBER CAPTION country_name 143 | ORDER BY country_name 144 | DETERMINES(region_id) 145 | LEVEL STATE_PROVINCE 146 | KEY state_province_id 147 | ALTERNATE KEY state_province_name 148 | MEMBER NAME state_province_name 149 | MEMBER CAPTION state_province_name 150 | ORDER BY state_province_name 151 | DETERMINES(country_id) 152 | ALL MEMBER NAME 'ALL CUSTOMERS'; 153 | -------------------------------------------------------------------------------- /examples/create_audit_policy.sql: -------------------------------------------------------------------------------- 1 | CREATE AUDIT POLICY table_pol 2 | PRIVILEGES CREATE ANY TABLE, DROP ANY TABLE; 3 | 4 | CREATE AUDIT POLICY dml_pol 5 | ACTIONS DELETE on hr.employees, 6 | INSERT on hr.employees, 7 | UPDATE on hr.employees, 8 | ALL on hr.departments; 9 | CREATE AUDIT POLICY security_pol 10 | ACTIONS ADMINISTER KEY MANAGEMENT; 11 | 12 | CREATE AUDIT POLICY dir_pol 13 | ACTIONS READ DIRECTORY, WRITE DIRECTORY, EXECUTE DIRECTORY; 14 | 15 | CREATE AUDIT POLICY all_actions_pol 16 | ACTIONS ALL; 17 | 18 | CREATE AUDIT POLICY dp_actions_pol 19 | ACTIONS COMPONENT = datapump IMPORT; 20 | 21 | CREATE AUDIT POLICY java_pol 22 | ROLES java_admin, java_deploy; 23 | 24 | CREATE AUDIT POLICY hr_admin_pol 25 | PRIVILEGES CREATE ANY TABLE, DROP ANY TABLE 26 | ACTIONS DELETE on hr.employees, 27 | INSERT on hr.employees, 28 | UPDATE on hr.employees, 29 | ALL on hr.departments, 30 | LOCK TABLE 31 | ROLES audit_admin, audit_viewer; 32 | 33 | CREATE AUDIT POLICY order_updates_pol 34 | ACTIONS UPDATE ON oe.orders 35 | WHEN 'SYS_CONTEXT(''USERENV'', ''IDENTIFICATION_TYPE'') = ''EXTERNAL''' 36 | EVALUATE PER SESSION; 37 | 38 | CREATE AUDIT POLICY emp_updates_pol 39 | ACTIONS DELETE on hr.employees, 40 | INSERT on hr.employees, 41 | UPDATE on hr.employees 42 | WHEN 'UID NOT IN (100, 105, 107)' 43 | EVALUATE PER STATEMENT; 44 | 45 | CREATE AUDIT POLICY local_table_pol 46 | PRIVILEGES CREATE ANY TABLE, DROP ANY TABLE 47 | CONTAINER = CURRENT; 48 | 49 | CREATE AUDIT POLICY common_role1_pol 50 | ROLES c##role1 51 | CONTAINER = ALL; 52 | -------------------------------------------------------------------------------- /examples/create_controlfile.sql: -------------------------------------------------------------------------------- 1 | CREATE CONTROLFILE DATABASE "demo" 2 | LOGFILE 3 | GROUP 1 '/path/oracle/dbs/t_log1.f' SIZE 500K, 4 | GROUP 2 '/path/oracle/dbs/t_log2.f' SIZE 500K 5 | RESETLOGS 6 | datafile 7 | '/path/file' 8 | FORCE LOGGING ARCHIVELOG 9 | CHARACTER SET WE8DEC 10 | -------------------------------------------------------------------------------- /examples/create_database.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE myoracle 2 | LOGFILE GROUP 1 ('diska:log1.log', 'diskb:log1.log') SIZE 50K, 3 | GROUP 2 ('diska:log2.log', 'diskb:log2.log') SIZE 50K 4 | DATAFILE 'diskc:dbone.dbf' SIZE 30M; 5 | 6 | CREATE DATABASE sample 7 | CONTROLFILE REUSE 8 | LOGFILE 9 | GROUP 1 ('diskx:log1.log', 'disky:log1.log') SIZE 50K, 10 | GROUP 2 ('diskx:log2.log', 'disky:log2.log') SIZE 50K 11 | MAXLOGFILES 5 12 | MAXLOGHISTORY 100 13 | MAXDATAFILES 10 14 | MAXINSTANCES 2 15 | ARCHIVELOG 16 | CHARACTER SET AL32UTF8 17 | NATIONAL CHARACTER SET AL16UTF16 18 | DATAFILE 19 | 'disk1:df1.dbf' AUTOEXTEND ON, 20 | 'disk2:df2.dbf' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED 21 | DEFAULT TEMPORARY TABLESPACE temp_ts 22 | UNDO TABLESPACE undo_ts ; 23 | -------------------------------------------------------------------------------- /examples/create_dimension.sql: -------------------------------------------------------------------------------- 1 | CREATE DIMENSION customers_dim 2 | LEVEL customer IS (customers.cust_id) 3 | LEVEL city IS (customers.cust_city) 4 | LEVEL state IS (customers.cust_state_province) 5 | LEVEL country IS (countries.country_id) 6 | LEVEL subregion IS (countries.country_subregion) 7 | LEVEL region IS (countries.country_region) 8 | HIERARCHY geog_rollup ( 9 | customer CHILD OF 10 | city CHILD OF 11 | state CHILD OF 12 | country CHILD OF 13 | subregion CHILD OF 14 | region 15 | JOIN KEY (customers.country_id) REFERENCES country 16 | ) 17 | ATTRIBUTE customer DETERMINES 18 | (cust_first_name, cust_last_name, cust_gender, 19 | cust_marital_status, cust_year_of_birth, 20 | cust_income_level, cust_credit_limit) 21 | ATTRIBUTE country DETERMINES (countries.country_name) 22 | ; -------------------------------------------------------------------------------- /examples/create_directory.sql: -------------------------------------------------------------------------------- 1 | CREATE DIRECTORY mydir AS '/scratch/data/file_data'; 2 | CREATE OR REPLACE DIRECTORY bfile_dir AS '/usr/bin/bfile_dir'; 3 | CREATE OR REPLACE DIRECTORY bfile_dir SHARING = NONE AS '/usr/bin/bfile_dir'; 4 | -------------------------------------------------------------------------------- /examples/create_diskgroup.sql: -------------------------------------------------------------------------------- 1 | CREATE DISKGROUP dgroup_01 2 | EXTERNAL REDUNDANCY 3 | DISK '/devices/disks/c*'; 4 | -------------------------------------------------------------------------------- /examples/create_edition.sql: -------------------------------------------------------------------------------- 1 | CREATE EDITION test_ed; 2 | -------------------------------------------------------------------------------- /examples/create_flashback_archive.sql: -------------------------------------------------------------------------------- 1 | CREATE FLASHBACK ARCHIVE DEFAULT test_archive1 2 | TABLESPACE example 3 | QUOTA 1 M 4 | RETENTION 1 DAY; 5 | 6 | CREATE FLASHBACK ARCHIVE test_archive2 7 | TABLESPACE example 8 | QUOTA 1 M 9 | RETENTION 1 DAY; 10 | -------------------------------------------------------------------------------- /examples/create_hierarchy.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE HIERARCHY time_hier -- Hierarchy name 2 | USING time_attr_dim -- Refers to TIME_ATTR_DIM attribute dimension 3 | (month CHILD OF -- Months in the attribute dimension 4 | quarter CHILD OF 5 | year); 6 | 7 | CREATE OR REPLACE HIERARCHY product_hier 8 | USING product_attr_dim 9 | (category 10 | CHILD OF department); 11 | 12 | CREATE OR REPLACE HIERARCHY geography_hier 13 | USING geography_attr_dim 14 | (state_province 15 | CHILD OF country 16 | CHILD OF region); 17 | -------------------------------------------------------------------------------- /examples/create_index.sql: -------------------------------------------------------------------------------- 1 | CREATE INDEX "NORTHWIND"."IDX_CUSTOMERS_REGION" ON "NORTHWIND"."CUSTOMERS" ("REGION") 2 | PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 3 | STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 4 | PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 5 | BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 6 | TABLESPACE "USERS" ; 7 | 8 | CREATE INDEX INDEX_SYS_LOG_YEAR ON SYS_LOG (YEAR) 9 | GLOBAL PARTITION BY RANGE (YEAR) 10 | (PARTITION p1 VALUES LESS THAN (1970), 11 | PARTITION p2 VALUES LESS THAN (2000), 12 | PARTITION p2 VALUES LESS THAN (2030), 13 | PARTITION p3 VALUES LESS THAN (MAXVALUE)); 14 | -------------------------------------------------------------------------------- /examples/create_inmemory_join_group.sql: -------------------------------------------------------------------------------- 1 | CREATE INMEMORY JOIN GROUP prod_id1 2 | (inventories(product_id), order_items(product_id)); 3 | CREATE INMEMORY JOIN GROUP prod_id2 4 | (inventories(product_id), pm.online_media(product_id)); 5 | -------------------------------------------------------------------------------- /examples/create_java.sql: -------------------------------------------------------------------------------- 1 | CREATE JAVA CLASS USING BFILE (java_dir, 'Agent.class') 2 | ; 3 | -- requires / as a stmt delimiter 4 | -- CREATE JAVA SOURCE NAMED "Welcome" AS 5 | -- public class Welcome { 6 | -- public static String welcome() { 7 | -- return "Welcome World"; } } 8 | -- / 9 | CREATE JAVA RESOURCE NAMED "appText" 10 | USING BFILE (java_dir, 'textBundle.dat') 11 | ; 12 | -------------------------------------------------------------------------------- /examples/create_library.sql: -------------------------------------------------------------------------------- 1 | CREATE LIBRARY ext_lib AS 'ddl_1' IN ddl_dir; 2 | CREATE OR REPLACE LIBRARY ext_lib AS 'ddl_1' IN ddl_dir CREDENTIAL ddl_cred; 3 | CREATE LIBRARY ext_lib AS '/OR/lib/ext_lib.so'; 4 | CREATE OR REPLACE LIBRARY ext_lib IS '/OR/newlib/ext_lib.so'; 5 | CREATE LIBRARY app_lib as '${ORACLE_HOME}/lib/app_lib.so' AGENT 'sales.hq.example.com'; -------------------------------------------------------------------------------- /examples/create_lockdown_profile.sql: -------------------------------------------------------------------------------- 1 | CREATE LOCKDOWN PROFILE hr_prof INCLUDING PRIVATE_DBAAS; 2 | -------------------------------------------------------------------------------- /examples/create_materialized_zonemap.sql: -------------------------------------------------------------------------------- 1 | CREATE MATERIALIZED ZONEMAP sales_zmap 2 | ON sales(cust_id, prod_id); 3 | 4 | CREATE MATERIALIZED ZONEMAP sales_zmap 5 | AS SELECT SYS_OP_ZONE_ID(rowid), 6 | MIN(cust_id), MAX(cust_id), 7 | MIN(prod_id), MAX(prod_id) 8 | FROM sales 9 | GROUP BY SYS_OP_ZONE_ID(rowid); 10 | 11 | CREATE MATERIALIZED ZONEMAP sales_zmap 12 | AS SELECT SYS_OP_ZONE_ID(s.rowid), 13 | MIN(cust_state_province), MAX(cust_state_province), 14 | MIN(cust_city), MAX(cust_city) 15 | FROM sales s 16 | LEFT OUTER JOIN customers c ON s.cust_id = c.cust_id 17 | GROUP BY SYS_OP_ZONE_ID(s.rowid); 18 | 19 | CREATE MATERIALIZED ZONEMAP sales_zmap 20 | AS SELECT SYS_OP_ZONE_ID(s.rowid), 21 | MIN(prod_category), MAX(prod_category), 22 | MIN(prod_subcategory), MAX(prod_subcategory), 23 | MIN(country_id), MAX(country_id), 24 | MIN(cust_state_province), MAX(cust_state_province), 25 | MIN(cust_city), MAX(cust_city) 26 | FROM sales s 27 | LEFT OUTER JOIN products p ON s.prod_id = p.prod_id 28 | LEFT OUTER JOIN customers c ON s.cust_id = c.cust_id 29 | GROUP BY sys_op_zone_id(s.rowid); 30 | 31 | CREATE MATERIALIZED ZONEMAP sales_zmap 32 | AS SELECT SYS_OP_ZONE_ID(s.rowid), 33 | MIN(prod_category), MAX(prod_category), 34 | MIN(prod_subcategory), MAX(prod_subcategory), 35 | MIN(country_id), MAX(country_id), 36 | MIN(cust_state_province), MAX(cust_state_province), 37 | MIN(cust_city), MAX(cust_city) 38 | FROM sales s, products p, customers c 39 | WHERE s.prod_id = p.prod_id(+) AND 40 | s.cust_id = c.cust_id(+) 41 | GROUP BY sys_op_zone_id(s.rowid); 42 | 43 | -------------------------------------------------------------------------------- /examples/create_operator.sql: -------------------------------------------------------------------------------- 1 | CREATE OPERATOR eq_op 2 | BINDING (VARCHAR2, VARCHAR2) 3 | RETURN NUMBER 4 | USING eq_f; 5 | -------------------------------------------------------------------------------- /examples/create_outline.sql: -------------------------------------------------------------------------------- 1 | CREATE OUTLINE salaries FOR CATEGORY special 2 | ON SELECT last_name, salary FROM employees; 3 | CREATE OR REPLACE PRIVATE OUTLINE my_salaries 4 | FROM salaries; 5 | CREATE OR REPLACE OUTLINE public_salaries 6 | FROM PRIVATE my_salaries; 7 | -------------------------------------------------------------------------------- /examples/create_package.sql: -------------------------------------------------------------------------------- 1 | CREATE PACKAGE EMP_BONUS AS 2 | LOCAL_PARAM NUMBER; 3 | USER_EXCEPTION EXCEPTION; 4 | PROCEDURE CALC_BONUS (DATE_HIRED DATE); 5 | END EMP_BONUS; -------------------------------------------------------------------------------- /examples/create_package.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (unit_statement (create_package CREATE PACKAGE (package_name (identifier (id_expression (regular_id EMP_BONUS)))) AS (package_obj_spec (variable_declaration (identifier (id_expression (regular_id LOCAL_PARAM))) (type_spec (datatype (native_datatype_element NUMBER))) ;)) (package_obj_spec (exception_declaration (identifier (id_expression (regular_id USER_EXCEPTION))) EXCEPTION ;)) (package_obj_spec (procedure_spec PROCEDURE (identifier (id_expression (regular_id CALC_BONUS))) ( (parameter (parameter_name (identifier (id_expression (regular_id DATE_HIRED)))) (type_spec (datatype (native_datatype_element DATE)))) ) ;)) END (package_name (identifier (id_expression (regular_id EMP_BONUS)))) ;)) ) -------------------------------------------------------------------------------- /examples/create_pmem_filestore.sql: -------------------------------------------------------------------------------- 1 | CREATE PMEM FILESTORE cloud_db_1 MOUNTPOINT '/corp/db/cloud_db_1' 2 | BACKINGFILE '/var/pmem/foo_1.' SIZE 2T BLOCKSIZE 8K 3 | AUTOEXTEND ON NEXT 10G MAXSIZE 3T 4 | -------------------------------------------------------------------------------- /examples/create_procedure.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE PROC(PARAM NUMBER) 2 | IS 3 | LOCAL_PARAM NUMBER; 4 | USER_EXCEPTION EXCEPTION; 5 | BEGIN 6 | LOCAL_PARAM:=0; 7 | END; -------------------------------------------------------------------------------- /examples/create_procedure.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (unit_statement (create_procedure_body CREATE OR REPLACE PROCEDURE (procedure_name (identifier (id_expression (regular_id PROC)))) ( (parameter (parameter_name (identifier (id_expression (regular_id (non_reserved_keywords_pre12c PARAM))))) (type_spec (datatype (native_datatype_element NUMBER)))) ) IS (seq_of_declare_specs (declare_spec (variable_declaration (identifier (id_expression (regular_id LOCAL_PARAM))) (type_spec (datatype (native_datatype_element NUMBER))) ;)) (declare_spec (exception_declaration (identifier (id_expression (regular_id USER_EXCEPTION))) EXCEPTION ;))) (body BEGIN (seq_of_statements (statement (assignment_statement (general_element (general_element_part (id_expression (regular_id LOCAL_PARAM)))) := (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric 0)))))))))))))) ;) END) ;)) ) -------------------------------------------------------------------------------- /examples/create_profile.sql: -------------------------------------------------------------------------------- 1 | CREATE MANDATORY PROFILE c##cdb_profile 2 | LIMIT PASSWORD_VERIFY_FUNCTION my_mandatory_function 3 | CONTAINER = ALL; 4 | -------------------------------------------------------------------------------- /examples/create_restore_point.sql: -------------------------------------------------------------------------------- 1 | CREATE RESTORE POINT good_data; 2 | CREATE RESTORE POINT rp2 for pluggable database pdb; 3 | CREATE RESTORE POINT rp2 for pluggable database pdb preserve; 4 | -------------------------------------------------------------------------------- /examples/create_role.sql: -------------------------------------------------------------------------------- 1 | create role TEST_ROLE_AAA ; 2 | 3 | create role TEST_ROLE_BBB NOT IDENTIFIED ; 4 | 5 | create role TEST_ROLE_CCC IDENTIFIED BY TEST_ROLE_AAA; 6 | 7 | create role TEST_ROLE_DDD IDENTIFIED EXTERNALLY; 8 | 9 | create role TEST_ROLE_EEE IDENTIFIED GLOBALLY; 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/create_rollback_segment.sql: -------------------------------------------------------------------------------- 1 | CREATE ROLLBACK SEGMENT rbs_one TABLESPACE rbs_ts; 2 | 3 | CREATE ROLLBACK SEGMENT rbs_one 4 | TABLESPACE rbs_ts 5 | STORAGE 6 | ( INITIAL 10K 7 | NEXT 10K 8 | MAXEXTENTS UNLIMITED ); -------------------------------------------------------------------------------- /examples/create_spfile.sql: -------------------------------------------------------------------------------- 1 | CREATE SPFILE 2 | FROM PFILE = '$ORACLE_HOME/work/t_init1.ora'; 3 | 4 | CREATE SPFILE = 's_params.ora' 5 | FROM PFILE = '$ORACLE_HOME/work/t_init1.ora'; 6 | 7 | CREATE SPFILE = 's_params.ora' 8 | FROM PFILE = '$ORACLE_HOME/work/t_init1.ora' AS COPY; 9 | 10 | CREATE SPFILE = 's_params.ora' 11 | FROM MEMORY; 12 | -------------------------------------------------------------------------------- /examples/create_synonym01.sql: -------------------------------------------------------------------------------- 1 | create public synonym emp for hr.employees 2 | -------------------------------------------------------------------------------- /examples/create_synonym02.sql: -------------------------------------------------------------------------------- 1 | create synonym hr.chicago_employees for hr.employees@chicago_db -------------------------------------------------------------------------------- /examples/create_synonym03.sql: -------------------------------------------------------------------------------- 1 | create or replace public synonym depts for departments -------------------------------------------------------------------------------- /examples/create_tablespace.sql: -------------------------------------------------------------------------------- 1 | CREATE BIGFILE TABLESPACE bigtbs_01 2 | DATAFILE 'bigtbs_f1.dbf' 3 | SIZE 20M AUTOEXTEND ON; 4 | 5 | CREATE UNDO TABLESPACE undots1 6 | DATAFILE 'undotbs_1a.dbf' 7 | SIZE 10M AUTOEXTEND ON 8 | RETENTION GUARANTEE; 9 | 10 | CREATE TEMPORARY TABLESPACE temp_demo 11 | TEMPFILE 'temp01.dbf' SIZE 5M AUTOEXTEND ON; 12 | 13 | CREATE TEMPORARY TABLESPACE tbs_05; 14 | 15 | CREATE TEMPORARY TABLESPACE tbs_05 TABLESPACE GROUP ''; 16 | 17 | CREATE TEMPORARY TABLESPACE tbs_temp_02 18 | TEMPFILE 'temp02.dbf' SIZE 5M AUTOEXTEND ON 19 | TABLESPACE GROUP tbs_grp_01; 20 | 21 | CREATE TABLESPACE tbs_01 22 | DATAFILE 'tbs_f2.dbf' SIZE 40M 23 | ONLINE; 24 | 25 | CREATE TABLESPACE tbs_03 26 | DATAFILE 'tbs_f03.dbf' SIZE 20M 27 | LOGGING; 28 | 29 | CREATE TABLESPACE tbs_02 30 | DATAFILE 'diskb:tbs_f5.dbf' SIZE 500K REUSE 31 | AUTOEXTEND ON NEXT 500K MAXSIZE 100M; 32 | 33 | CREATE TABLESPACE tbs_02 34 | DATAFILE 'diskb:tbs_f5.dbf' SIZE 500K REUSE 35 | AUTOEXTEND ON NEXT 500K MAXSIZE 100M; 36 | 37 | CREATE TABLESPACE tbs_04 DATAFILE 'file_1.dbf' SIZE 10M 38 | EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K; 39 | 40 | CREATE TABLESPACE lmt1 DATAFILE 'lmt_file2.dbf' SIZE 100m REUSE 41 | EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M; 42 | 43 | CREATE TABLESPACE lmt2 DATAFILE 'lmt_file3.dbf' SIZE 100m REUSE 44 | EXTENT MANAGEMENT LOCAL; 45 | 46 | CREATE TABLESPACE encrypt_ts 47 | DATAFILE '$ORACLE_HOME/dbs/encrypt_df.dbf' SIZE 1M 48 | ENCRYPTION USING 'AES256' ; 49 | 50 | CREATE TABLESPACE auto_seg_ts DATAFILE 'file_2.dbf' SIZE 1M 51 | EXTENT MANAGEMENT LOCAL 52 | SEGMENT SPACE MANAGEMENT AUTO; 53 | 54 | CREATE TABLESPACE omf_ts1; 55 | 56 | CREATE TABLESPACE omf_ts2 DATAFILE AUTOEXTEND OFF; 57 | 58 | -------------------------------------------------------------------------------- /examples/create_tablespace_set.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLESPACE SET ts1 2 | IN SHARDSPACE sgr1 3 | USING TEMPLATE 4 | ( DATAFILE SIZE 100m 5 | EXTENT MANAGEMENT LOCAL 6 | SEGMENT SPACE MANAGEMENT AUTO 7 | ); 8 | -------------------------------------------------------------------------------- /examples/create_type.sql: -------------------------------------------------------------------------------- 1 | CREATE TYPE address_t AS OBJECT 2 | ( hno NUMBER, 3 | street VARCHAR2(40), 4 | city VARCHAR2(20), 5 | zip VARCHAR2(5), 6 | phone VARCHAR2(10) ); 7 | 8 | 9 | CREATE TYPE person AS OBJECT 10 | ( name VARCHAR2(40), 11 | dateofbirth DATE, 12 | homeaddress address_t, 13 | manager REF person ); 14 | ; 15 | 16 | -------------------------------------------------------------------------------- /examples/create_view.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE VIEW VIEW_TEST_ROLE AS 2 | SELECT ID, NAME || '-' ALIAS_NAME 3 | FROM TEST_ROLE 4 | WHERE ID < 6 with check option; 5 | 6 | CREATE OR REPLACE FORCE VIEW VIEW_TEST_ROLE AS 7 | SELECT ID, NAME || '-' ALIAS_NAME 8 | FROM TEST_ROLE 9 | WHERE ID < 7 with check option; 10 | 11 | CREATE OR REPLACE NO FORCE VIEW VIEW_TEST_ROLE AS 12 | SELECT ID, NAME || '-' ALIAS_NAME 13 | FROM TEST_ROLE 14 | WHERE ID < 8 with check option; 15 | 16 | CREATE VIEW warehouse_view OF XMLTYPE 17 | XMLSCHEMA "http://www.example.com/xwarehouses.xsd" 18 | ELEMENT "Warehouse" 19 | WITH OBJECT ID 20 | (extract(OBJECT_VALUE, '/Warehouse/Area/text()').getnumberval()) 21 | AS SELECT XMLELEMENT("Warehouse", 22 | XMLFOREST(WarehouseID as "Building", 23 | area as "Area", 24 | docks as "Docks", 25 | docktype as "DockType", 26 | wateraccess as "WaterAccess", 27 | railaccess as "RailAccess", 28 | parking as "Parking", 29 | VClearance as "VClearance")) 30 | FROM warehouse_table; 31 | -------------------------------------------------------------------------------- /examples/ctas.sql: -------------------------------------------------------------------------------- 1 | create table junk as select sysdate from dual; 2 | 3 | create table junk1 INITRANS 10 as select sysdate from dual; 4 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/datetime03.sql: -------------------------------------------------------------------------------- 1 | select 2 | timestamp '2009-10-29 01:30:00' at time zone 'us/pacific'from dual 3 | 4 | -------------------------------------------------------------------------------- /examples/datetime04.sql: -------------------------------------------------------------------------------- 1 | select 2 | timestamp '2009-10-29 01:30:00' 3 | from dual 4 | 5 | -------------------------------------------------------------------------------- /examples/datetime05.sql: -------------------------------------------------------------------------------- 1 | select date '1900-01-01' from dual 2 | -------------------------------------------------------------------------------- /examples/dblink.sql: -------------------------------------------------------------------------------- 1 | CREATE PUBLIC DATABASE LINK remote USING 'remote'; 2 | CREATE DATABASE LINK local CONNECT TO hr IDENTIFIED BY p4ssword USING 'local'; 3 | CREATE DATABASE LINK remote.us.example.com CONNECT TO CURRENT_USER USING 'remote'; 4 | 5 | ALTER DATABASE LINK private_link CONNECT TO hr IDENTIFIED BY hr_new_password; 6 | ALTER PUBLIC DATABASE LINK public_link CONNECT TO scott IDENTIFIED BY scott_new_password; 7 | ALTER SHARED PUBLIC DATABASE LINK shared_pub_link CONNECT TO scott IDENTIFIED BY scott_new_password AUTHENTICATED BY hr IDENTIFIED BY hr_new_password; 8 | 9 | DROP PUBLIC DATABASE LINK remote; 10 | DROP DATABASE LINK private_link_name; 11 | -------------------------------------------------------------------------------- /examples/dblink01.sql: -------------------------------------------------------------------------------- 1 | select last_name, department_name 2 | from employees@remote, departments 3 | where employees.department_id = departments.department_id; 4 | 5 | SELECT * FROM scott.emp@hq.acme.com; 6 | -------------------------------------------------------------------------------- /examples/directory.sql: -------------------------------------------------------------------------------- 1 | CREATE DIRECTORY mydir AS '/scratch/data/file_data'; 2 | 3 | CREATE OR REPLACE DIRECTORY bfile_dir AS '/usr/bin/bfile_dir'; 4 | -------------------------------------------------------------------------------- /examples/disassociate_statistics.sql: -------------------------------------------------------------------------------- 1 | DISASSOCIATE STATISTICS FROM COLUMNS hr.emp_mgmt.col1 FORCE; 2 | DISASSOCIATE STATISTICS FROM PACKAGES hr.emp_mgmt; 3 | -------------------------------------------------------------------------------- /examples/drop_analytic_view.sql: -------------------------------------------------------------------------------- 1 | DROP ANALYTIC VIEW sales_av; 2 | DROP ANALYTIC VIEW sch.sales_av; 3 | -------------------------------------------------------------------------------- /examples/drop_attribute_dimension.sql: -------------------------------------------------------------------------------- 1 | DROP ATTRIBUTE DIMENSION product_attr_dim; 2 | -------------------------------------------------------------------------------- /examples/drop_audit_policy.sql: -------------------------------------------------------------------------------- 1 | DROP AUDIT POLICY table_pol; 2 | -------------------------------------------------------------------------------- /examples/drop_cluster.sql: -------------------------------------------------------------------------------- 1 | DROP CLUSTER language; 2 | DROP CLUSTER sch.language; 3 | DROP CLUSTER personnel INCLUDING TABLES CASCADE CONSTRAINTS; -------------------------------------------------------------------------------- /examples/drop_context.sql: -------------------------------------------------------------------------------- 1 | DROP CONTEXT hr_context; -------------------------------------------------------------------------------- /examples/drop_database.sql: -------------------------------------------------------------------------------- 1 | DROP DATABASE ; 2 | DROP DATABASE INCLUDING BACKUPS NOPROMPT ; 3 | -------------------------------------------------------------------------------- /examples/drop_directory.sql: -------------------------------------------------------------------------------- 1 | DROP DIRECTORY bfile_dir; 2 | -------------------------------------------------------------------------------- /examples/drop_diskgroup.sql: -------------------------------------------------------------------------------- 1 | DROP DISKGROUP dgroup_01 INCLUDING CONTENTS; 2 | -------------------------------------------------------------------------------- /examples/drop_edition.sql: -------------------------------------------------------------------------------- 1 | DROP EDITION TEST_ED; 2 | -------------------------------------------------------------------------------- /examples/drop_flashback_archive.sql: -------------------------------------------------------------------------------- 1 | DROP FLASHBACK ARCHIVE test_archive2; 2 | -------------------------------------------------------------------------------- /examples/drop_hierarchy.sql: -------------------------------------------------------------------------------- 1 | DROP HIERARCHY product_hier; 2 | -------------------------------------------------------------------------------- /examples/drop_indextype.sql: -------------------------------------------------------------------------------- 1 | DROP INDEXTYPE position_indextype FORCE; 2 | DROP INDEXTYPE position_indextype; -------------------------------------------------------------------------------- /examples/drop_inmemory_join_group.sql: -------------------------------------------------------------------------------- 1 | DROP INMEMORY JOIN GROUP prod_id1; 2 | -------------------------------------------------------------------------------- /examples/drop_java.sql: -------------------------------------------------------------------------------- 1 | DROP JAVA CLASS "Agent"; 2 | -------------------------------------------------------------------------------- /examples/drop_library.sql: -------------------------------------------------------------------------------- 1 | DROP LIBRARY ext_lib; -------------------------------------------------------------------------------- /examples/drop_lockdown_profile.sql: -------------------------------------------------------------------------------- 1 | DROP LOCKDOWN PROFILE hr_prof; 2 | -------------------------------------------------------------------------------- /examples/drop_materialized_view.sql: -------------------------------------------------------------------------------- 1 | DROP MATERIALIZED VIEW mv1; 2 | 3 | DROP MATERIALIZED VIEW mv2 PRESERVE TABLE; 4 | -------------------------------------------------------------------------------- /examples/drop_materialized_view.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (unit_statement (drop_materialized_view DROP MATERIALIZED VIEW (tableview_name (identifier (id_expression (regular_id mv1)))) ;)) (unit_statement (drop_materialized_view DROP MATERIALIZED VIEW (tableview_name (identifier (id_expression (regular_id mv2)))) PRESERVE TABLE ;)) ) -------------------------------------------------------------------------------- /examples/drop_materialized_zonemap.sql: -------------------------------------------------------------------------------- 1 | DROP MATERIALIZED ZONEMAP sales_zmap; -------------------------------------------------------------------------------- /examples/drop_operator.sql: -------------------------------------------------------------------------------- 1 | DROP OPERATOR eq_op; 2 | -------------------------------------------------------------------------------- /examples/drop_outline.sql: -------------------------------------------------------------------------------- 1 | DROP OUTLINE salaries; 2 | -------------------------------------------------------------------------------- /examples/drop_pmem_filestore.sql: -------------------------------------------------------------------------------- 1 | DROP PMEM FILESTORE cloud_db_1 EXCLUDING CONTENTS; 2 | -------------------------------------------------------------------------------- /examples/drop_restore_point.sql: -------------------------------------------------------------------------------- 1 | DROP RESTORE POINT good_data; 2 | DROP RESTORE POINT rp for pluggable database pdb; 3 | -------------------------------------------------------------------------------- /examples/drop_role.sql: -------------------------------------------------------------------------------- 1 | drop role TEST_ROLE_AAA; 2 | -------------------------------------------------------------------------------- /examples/drop_rollback_segment.sql: -------------------------------------------------------------------------------- 1 | DROP ROLLBACK SEGMENT rbs_one; -------------------------------------------------------------------------------- /examples/drop_synonym01.sql: -------------------------------------------------------------------------------- 1 | drop synonym emp ; 2 | drop public synonym emp ; 3 | drop public synonym emp force; 4 | drop public synonym sch.emp force; 5 | -------------------------------------------------------------------------------- /examples/drop_table.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE employee; 2 | DROP TABLE employee PURGE; 3 | DROP TABLE employee CASCADE CONSTRAINTS; 4 | DROP TABLE employee CASCADE CONSTRAINTS PURGE; -------------------------------------------------------------------------------- /examples/drop_tablespace.sql: -------------------------------------------------------------------------------- 1 | DROP TABLESPACE tbs_01 2 | INCLUDING CONTENTS 3 | CASCADE CONSTRAINTS; 4 | DROP TABLESPACE tbs_02 5 | INCLUDING CONTENTS AND DATAFILES; 6 | -------------------------------------------------------------------------------- /examples/drop_tablespace_set.sql: -------------------------------------------------------------------------------- 1 | DROP TABLESPACE SET ts1; 2 | -------------------------------------------------------------------------------- /examples/drop_user.sql: -------------------------------------------------------------------------------- 1 | DROP USER sidney; 2 | DROP USER sidney CASCADE; -------------------------------------------------------------------------------- /examples/drop_view.sql: -------------------------------------------------------------------------------- 1 | DROP VIEW employee; 2 | DROP VIEW employee CASCADE CONSTRAINT; 3 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/external_table01.sql: -------------------------------------------------------------------------------- 1 | create table AAAAAAAAA.BBBBBBBBBBBBBBBBBB 2 | ( 3 | id NUMBER, 4 | xys_sbxno VARCHAR2(50), 5 | xys_sbxno VARCHAR2(50), 6 | xys_sbxvin VARCHAR2(50), 7 | xys_sbxmanufacturer VARCHAR2(64), 8 | xys_sbxid VARCHAR2(40), 9 | xys_sbxname VARCHAR2(128), 10 | xys_sbxid VARCHAR2(40), 11 | xys_sbxname VARCHAR2(128), 12 | xys_sbxid VARCHAR2(64), 13 | xys_sbxname VARCHAR2(256), 14 | xys_sbxprice NUMBER, 15 | xys_sbxprice NUMBER, 16 | xys_sbxclass VARCHAR2(64), 17 | xys_sbxtype VARCHAR2(64), 18 | xys_sbxno VARCHAR2(200), 19 | xys_sbxcolor VARCHAR2(40), 20 | xys_sbxdate DATE, 21 | xys_sbxdate DATE, 22 | xys_sbxby VARCHAR2(50), 23 | xys_sbxtime DATE, 24 | xys_sbxby VARCHAR2(50), 25 | xys_sbxtime DATE, 26 | xys_sbxflag CHAR(1), 27 | xys_sbxinternet VARCHAR2(2), 28 | xys_sbxgreen VARCHAR2(64), 29 | xys_sbxnum NUMBER, 30 | configure VARCHAR2(200), 31 | xys_sbxstyle VARCHAR2(20), 32 | driver VARCHAR2(80), 33 | blowoff VARCHAR2(64), 34 | xys_sbxmain VARCHAR2(80), 35 | xys_sbxdetail VARCHAR2(80), 36 | xys_sbxtime DATE, 37 | xys_sbxage VARCHAR2(20), 38 | version NUMBER, 39 | xys_sbxbusiness VARCHAR2(10), 40 | xys_sbxnum VARCHAR2(80), 41 | xys_sbxcertified VARCHAR2(20), 42 | xys_sbxprice NUMBER, 43 | xys_sbxtime DATE, 44 | wight NUMBER, 45 | xys_sbxflag VARCHAR2(20), 46 | xys_sbxtype VARCHAR2(40), 47 | xys_sbxparallel VARCHAR2(20), 48 | xys_sbxstatus VARCHAR2(20), 49 | xys_sbxlength NUMBER, 50 | xys_sbxbase NUMBER, 51 | xys_sbxvin VARCHAR2(50), 52 | engine VARCHAR2(200), 53 | xys_sbxdrive VARCHAR2(200), 54 | xys_sbxlength NUMBER, 55 | xys_sbxform VARCHAR2(200), 56 | xys_sbxmodel VARCHAR2(200) 57 | ) 58 | organization external 59 | ( 60 | type ORACLE_LOADER 61 | default directory EXTERNAL_NEW_SP 62 | access parameters 63 | ( 64 | records delimited by newline 65 | characterset UTF8 66 | nobadfile 67 | nodiscardfile 68 | nologfile 69 | fields terminated by '<>' 70 | MISSING FIELD VALUES ARE NULL 71 | ( 72 | id , 73 | xys_sbxno , 74 | xys_sbxno , 75 | xys_sbxvin, 76 | xys_sbxmanufacturer , 77 | xys_sbxId , 78 | xys_sbxname, 79 | xys_sbxid , 80 | xys_sbxname , 81 | xys_sbxid , 82 | xys_sbxname , 83 | xys_sbxprice , 84 | xys_sbxpassenger, 85 | mileage , 86 | xys_sbxprice , 87 | xys_sbxbelongs , 88 | xys_sbxno , 89 | xys_sbxaddress, 90 | xys_sbxplate , 91 | xys_sbxappraiser , 92 | xys_sbxprice , 93 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS", 94 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS", 95 | xys_sbxlicense , 96 | xys_sbxprovince , 97 | xys_sbxcity , 98 | xys_sbxaddress , 99 | xys_sbxid , 100 | xys_sbxid , 101 | xys_sbxname , 102 | xys_sbxphone , 103 | xys_sbxprovince , 104 | xys_sbxcity , 105 | xys_sbxcounty , 106 | xys_sbxstreet , 107 | xys_sbxaddress , 108 | xys_sbxprovince , 109 | xys_sbxcity , 110 | xys_sbxnum , 111 | xys_sbxnums , 112 | xys_sbxtrans , 113 | xys_sbxmortgage , 114 | xys_sbxnum , 115 | xys_sbxkind , 116 | xys_sbxuse , 117 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 118 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS", 119 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 120 | xys_sbxby , 121 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 122 | xys_sbxby , 123 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 124 | xys_sbxflag , 125 | xys_sbxmain , 126 | xys_sbxdetail , 127 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 128 | xys_sbxage , 129 | version , 130 | xys_sbxbusiness , 131 | xys_sbxnum , 132 | xys_sbxcertified , 133 | xys_sbxprice , 134 | xys_sbx CHAR (19) DATE_FORMAT DATE MASK "YYYY-MM-DD HH24:MI:SS" , 135 | wight , 136 | xys_sbxflag , 137 | xys_sbxtype , 138 | xys_sbxparallel , 139 | xys_sbxstatus , 140 | xys_sbxlength, 141 | xys_sbxtype , 142 | xys_sbxtype , 143 | xys_sbxphone , 144 | xys_sbxtype , 145 | xys_sbxplate , 146 | xys_sbxprovince , 147 | xys_sbxcity , 148 | xys_sbxdate , 149 | xys_sbxprovince 150 | ) 151 | ) 152 | location (EXTERNAL_NEW_SP:'APPLY_CAR_DETAILS.csv') 153 | ) 154 | reject limit UNLIMITED; 155 | -------------------------------------------------------------------------------- /examples/external_table02.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE T1_EXT1 ( 2 | ID NUMBER(10), 3 | NAME VARCHAR2(50), 4 | DEPTNO NUMBER(2) 5 | ) 6 | ORGANIZATION EXTERNAL ( 7 | TYPE ORACLE_LOADER 8 | DEFAULT DIRECTORY EXTERNAL_DIR 9 | ACCESS PARAMETERS ( 10 | RECORDS DELIMITED BY NEWLINE 11 | FIELDS TERMINATED BY "," 12 | ( 13 | ID, 14 | NAME, 15 | DEPTNO 16 | ) 17 | ) 18 | LOCATION (EXTERNAL_DIR:'t1_data.csv') 19 | ) 20 | REJECT LIMIT UNLIMITED; 21 | -------------------------------------------------------------------------------- /examples/fetch_clause01.sql: -------------------------------------------------------------------------------- 1 | Select * 2 | fROM green_table 3 | offset 1 rows 4 | fetch FIRST 1 ROWS ONLY; 5 | -------------------------------------------------------------------------------- /examples/fetch_clause02.sql: -------------------------------------------------------------------------------- 1 | Select * 2 | fROM green_table 3 | offset 1 rows 4 | fetch NEXT 20 percent ROW ONLY 5 | -------------------------------------------------------------------------------- /examples/fetch_clause03.sql: -------------------------------------------------------------------------------- 1 | select color, favorite 2 | FROM green_table 3 | order by color, favorite 4 | offset 1 rows 5 | fetch NEXT 20 ROW WITH TIES; 6 | -------------------------------------------------------------------------------- /examples/fetch_clause04.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | (SELECT ID_ FROM TP_STUFF WHERE TEST='1' FETCH FIRST ROW ONLY) AS MWST_ID 3 | FROM ETL_MD_RAW_ADM ADM 4 | WHERE ADM.STATUS_ART_ID = 0; -------------------------------------------------------------------------------- /examples/flashback01.sql: -------------------------------------------------------------------------------- 1 | select value(p$) from "XDB"."XDB$SCHEMA" as of snapshot(:2) p$ where SYS_NC_OID$ = :1 2 | -------------------------------------------------------------------------------- /examples/flashback_table.sql: -------------------------------------------------------------------------------- 1 | FLASHBACK TABLE hr.employees TO TIMESTAMP TO_TIMESTAMP('29-DEC-20 01.26.29.000000000 PM'); -------------------------------------------------------------------------------- /examples/for_update01.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select * from employees) 2 | for update of employee_id 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/for_update02.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/function02.sql: -------------------------------------------------------------------------------- 1 | select set(x) from dual 2 | -------------------------------------------------------------------------------- /examples/function03.sql: -------------------------------------------------------------------------------- 1 | select trim(both from con.ke) 2 | from dual 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/function04.sql: -------------------------------------------------------------------------------- 1 | select lnnvl( 2 > 1) from dual 2 | -------------------------------------------------------------------------------- /examples/function05.sql: -------------------------------------------------------------------------------- 1 | select count(*) 2 | from employees 3 | where lnnvl(commission_pct >= .2) 4 | -------------------------------------------------------------------------------- /examples/function06.sql: -------------------------------------------------------------------------------- 1 | call dbms_scheduler.auto_purge ( ) 2 | -------------------------------------------------------------------------------- /examples/function07.sql: -------------------------------------------------------------------------------- 1 | create or replace function budget(job varchar2) return varchar2 SQL_MACRO is 2 | begin 3 | return q'{ 4 | select deptno, sum(sal) budget 5 | from emp 6 | where job = budget.job 7 | group by deptno 8 | }'; 9 | end; 10 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/groupby03.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( a, 1 ) 4 | 5 | -------------------------------------------------------------------------------- /examples/groupby04.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( (a),1 ) 4 | -------------------------------------------------------------------------------- /examples/groupby05.sql: -------------------------------------------------------------------------------- 1 | select * from x 2 | group by grouping sets 3 | ( ((a),b), ((a),b) ) 4 | 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/index.sql: -------------------------------------------------------------------------------- 1 | create index IDX on OBJ (CODE, DOCUMENT); 2 | 3 | ALTER INDEX supplier_idx 4 | RENAME TO supplier_index_name; 5 | 6 | DROP INDEX index_name; 7 | 8 | 9 | CREATE INDEX ord_customer_ix 10 | ON orders (customer_id); 11 | 12 | CREATE INDEX ord_customer_ix_demo 13 | ON orders (customer_id, sales_rep_id) 14 | COMPRESS 1; 15 | 16 | CREATE INDEX ord_customer_ix_demo 17 | ON orders (order_mode) 18 | NOSORT 19 | NOLOGGING; 20 | 21 | CREATE INDEX idx_emp_dept_id ON emp(department_id) PARALLEL 6 ONLINE; 22 | 23 | CREATE INDEX sales_local_idx ON SALES(product_id) LOCAL; 24 | 25 | CREATE INDEX idx_personnel ON CLUSTER personnel; 26 | 27 | CREATE INDEX upper_ix ON employees (UPPER(last_name)); 28 | 29 | CREATE INDEX income_ix 30 | ON employees(salary + (salary*commission_pct)); 31 | 32 | CREATE INDEX src_idx ON print_media(text_length(ad_sourcetext)); 33 | 34 | CREATE INDEX area_idx ON rect_tab x (x.area()); 35 | 36 | CREATE INDEX cust_last_name_ix ON customers (cust_last_name) 37 | GLOBAL PARTITION BY HASH (cust_last_name) 38 | PARTITIONS 4; 39 | 40 | CREATE INDEX prod_idx ON hash_products(category_id) LOCAL 41 | STORE IN (tbs_01, tbs_02); 42 | 43 | CREATE BITMAP INDEX product_bm_ix 44 | ON hash_products(list_price) 45 | TABLESPACE tbs_04; 46 | 47 | CREATE UNIQUE INDEX nested_tab_ix 48 | ON textdocs_nestedtab(NESTED_TABLE_ID, document_typ); 49 | 50 | ALTER INDEX ord_customer_ix REBUILD REVERSE; 51 | 52 | ALTER INDEX ord_customer_ix REBUILD PARALLEL; 53 | 54 | ALTER INDEX oe.cust_lname_ix 55 | INITRANS 5; 56 | 57 | ALTER INDEX upper_ix PARALLEL; 58 | 59 | ALTER INDEX upper_ix RENAME TO upper_name_ix; 60 | 61 | ALTER INDEX cost_ix 62 | MODIFY PARTITION p2 UNUSABLE; 63 | 64 | ALTER INDEX cost_ix UNUSABLE; 65 | 66 | ALTER INDEX cost_ix 67 | REBUILD PARTITION p2; 68 | 69 | ALTER INDEX cost_ix 70 | REBUILD PARTITION p3 NOLOGGING; 71 | 72 | ALTER INDEX cost_ix MODIFY PARTITION p3 73 | STORAGE(MAXEXTENTS 30) LOGGING; 74 | 75 | ALTER INDEX cost_ix 76 | RENAME PARTITION p3 TO p3_Q3; 77 | 78 | ALTER INDEX cost_ix 79 | SPLIT PARTITION p2 AT (1500) 80 | INTO ( PARTITION p2a TABLESPACE tbs_01 LOGGING, 81 | PARTITION p2b TABLESPACE tbs_02); 82 | 83 | ALTER INDEX cost_ix 84 | DROP PARTITION p1; 85 | 86 | ALTER INDEX prod_idx 87 | MODIFY DEFAULT ATTRIBUTES INITRANS 5; 88 | -------------------------------------------------------------------------------- /examples/insert_statement.sql: -------------------------------------------------------------------------------- 1 | DECLARE 2 | V_RECORD EVENT%ROWTYPE; 3 | BEGIN 4 | SELECT * INTO V_RECORD FROM EVENT WHERE ROWNUM=1; 5 | INSERT INTO TMP_EVENT VALUES V_RECORD; 6 | END; -------------------------------------------------------------------------------- /examples/interval01.sql: -------------------------------------------------------------------------------- 1 | select (systimestamp - order_date) day(9) to second from orders 2 | where order_id = 2458 3 | -------------------------------------------------------------------------------- /examples/interval02.sql: -------------------------------------------------------------------------------- 1 | select interval '42' day from dual 2 | -------------------------------------------------------------------------------- /examples/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 | 18 | ,interval '1' year 19 | ,interval '1' month 20 | 21 | from dual 22 | -------------------------------------------------------------------------------- /examples/interval04.sql: -------------------------------------------------------------------------------- 1 | select interval'20' day - interval'240' hour from dual 2 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/join10.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, 2 | ( 3 | dual left outer join (select * from dual) tt2 using(dummy) 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /examples/join11.sql: -------------------------------------------------------------------------------- 1 | select * from t1, ( t2 left outer join t3 using(dummy) ) 2 | -------------------------------------------------------------------------------- /examples/join12.sql: -------------------------------------------------------------------------------- 1 | select * from dual,( dual left outer join tt2 using(dummy) ) 2 | 3 | -------------------------------------------------------------------------------- /examples/join13.sql: -------------------------------------------------------------------------------- 1 | select * from t1, 2 | (((( 3 | t2 left outer join t3 using(dummy) 4 | )))) 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/join15.sql: -------------------------------------------------------------------------------- 1 | select * from dual t1, ( dual t2 join dual t3 using(dummy)) left outer join dual t4 using (dummy) 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/join19.sql: -------------------------------------------------------------------------------- 1 | select d1.*, d2.* from dual d1 cross join dual d2 2 | -------------------------------------------------------------------------------- /examples/join20.sql: -------------------------------------------------------------------------------- 1 | select d1.*, d2.* from dual cross join dual 2 | -------------------------------------------------------------------------------- /examples/join21.sql: -------------------------------------------------------------------------------- 1 | select * from sys.dual natural join sys.dual 2 | 3 | -------------------------------------------------------------------------------- /examples/json_sql.sql: -------------------------------------------------------------------------------- 1 | select 'A' | | 'B' from dual; 2 | 3 | SELECT JSON_OBJECT ( 4 | KEY 'deptno' IS d.department_id, 5 | KEY 'deptname' IS d.department_name 6 | ) "Department Objects" 7 | FROM departments d 8 | ORDER BY d.department_id; 9 | 10 | SELECT JSON_OBJECT(KEY 'VALUE' VALUE COL), t.* FROM T t; 11 | 12 | SELECT JSON_ARRAY ( 13 | JSON_OBJECT('percentage' VALUE .50), 14 | JSON_ARRAY(1,2,3), 15 | 100, 16 | 'California', 17 | null 18 | NULL ON NULL 19 | ) "JSON Array Example" 20 | FROM DUAL; 21 | 22 | SELECT JSON_ARRAYAGG(id ORDER BY id RETURNING VARCHAR2(100)) ID_NUMBERS 23 | FROM id_table; 24 | 25 | SELECT JSON_OBJECTAGG(KEY department_name VALUE department_id) "Department Numbers" 26 | FROM departments 27 | WHERE department_id <= 30; 28 | 29 | SELECT JSON_QUERY('{a:100, b:200, c:300}', '$') AS value 30 | FROM DUAL; 31 | 32 | SELECT JSON_SERIALIZE ('{a:[1,2,3,4]}' RETURNING VARCHAR2(3) TRUNCATE ERROR ON ERROR) from dual; 33 | 34 | SELECT JSON_VALUE('{a:100}', '$.a') AS value FROM DUAL; 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /examples/keywordasidentifier01.sql: -------------------------------------------------------------------------------- 1 | select timestamp, avg, cume_dist from nulls 2 | -------------------------------------------------------------------------------- /examples/keywordasidentifier02.sql: -------------------------------------------------------------------------------- 1 | select m.model from model 2 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/keywordasidentifier05.sql: -------------------------------------------------------------------------------- 1 | select exception from exception -------------------------------------------------------------------------------- /examples/keywordasidentifier06.sql: -------------------------------------------------------------------------------- 1 | SELECT * FROM PERIOD; 2 | CREATE PROCEDURE TEST AS 3 | BEGIN 4 | IF A.EXISTS() THEN 5 | NULL; 6 | END IF; 7 | END; 8 | -------------------------------------------------------------------------------- /examples/least_greatest.sql: -------------------------------------------------------------------------------- 1 | SELECT LEAST(1), LEAST(1, 2), LEAST(1, 2, 3), GREATES(1), GREATEST(1, 2), GREATEST(1, 2, 3) FROM DUAL -------------------------------------------------------------------------------- /examples/lexer01.sql: -------------------------------------------------------------------------------- 1 | select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2 2 | 3 | -------------------------------------------------------------------------------- /examples/lexer02.sql: -------------------------------------------------------------------------------- 1 | select 'A' | | 'B' from dual 2 | 3 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/lexer04.sql: -------------------------------------------------------------------------------- 1 | select tbl$or$idx$part$num("sys"."wrh$_seg_stat",0,4,0,"rowid") as c1 from t1 2 | -------------------------------------------------------------------------------- /examples/lexer05.sql: -------------------------------------------------------------------------------- 1 | select tbl$or$idx$part$num("sys"."wrh:_seg_stat",0,4,0,"rowid") as c1 from t1 2 | -------------------------------------------------------------------------------- /examples/like01.sql: -------------------------------------------------------------------------------- 1 | select last_name 2 | from employees 3 | where last_name 4 | like '%a\_b%' escape '\' 5 | order by last_name 6 | -------------------------------------------------------------------------------- /examples/materialized_views.sql: -------------------------------------------------------------------------------- 1 | CREATE MATERIALIZED VIEW foreign_customers FOR UPDATE 2 | AS SELECT * FROM sh.customers@remote cu 3 | WHERE EXISTS 4 | (SELECT * FROM sh.countries@remote co 5 | WHERE co.country_id = cu.country_id); 6 | CREATE MATERIALIZED VIEW sales_mv 7 | BUILD IMMEDIATE 8 | REFRESH FAST ON COMMIT 9 | AS SELECT t.calendar_year, p.prod_id, 10 | SUM(s.amount_sold) AS sum_sales 11 | FROM times t, products p, sales s 12 | WHERE t.time_id = s.time_id AND p.prod_id = s.prod_id 13 | GROUP BY t.calendar_year, p.prod_id; 14 | 15 | CREATE MATERIALIZED VIEW sales_by_month_by_state 16 | TABLESPACE example 17 | PARALLEL 4 18 | BUILD IMMEDIATE 19 | REFRESH COMPLETE 20 | ENABLE QUERY REWRITE 21 | AS SELECT t.calendar_month_desc, c.cust_state_province, 22 | SUM(s.amount_sold) AS sum_sales 23 | FROM times t, sales s, customers c 24 | WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id 25 | GROUP BY t.calendar_month_desc, c.cust_state_province; 26 | 27 | CREATE MATERIALIZED VIEW sales_sum_table 28 | ON PREBUILT TABLE WITH REDUCED PRECISION 29 | ENABLE QUERY REWRITE 30 | AS SELECT t.calendar_month_desc AS month, 31 | c.cust_state_province AS state, 32 | SUM(s.amount_sold) AS sales 33 | FROM times t, customers c, sales s 34 | WHERE s.time_id = t.time_id AND s.cust_id = c.cust_id 35 | GROUP BY t.calendar_month_desc, c.cust_state_province; 36 | 37 | CREATE MATERIALIZED VIEW order_data REFRESH WITH ROWID 38 | AS SELECT * FROM orders; 39 | 40 | CREATE MATERIALIZED VIEW warranty_orders REFRESH FAST AS 41 | SELECT order_id, line_item_id, product_id FROM order_items o 42 | WHERE EXISTS 43 | (SELECT * FROM inventories i WHERE o.product_id = i.product_id 44 | AND i.quantity_on_hand IS NOT NULL) 45 | UNION 46 | SELECT order_id, line_item_id, product_id FROM order_items 47 | WHERE quantity > 5; 48 | 49 | CREATE MATERIALIZED VIEW my_warranty_orders 50 | AS SELECT w.order_id, w.line_item_id, o.order_date 51 | FROM warranty_orders w, orders o 52 | WHERE o.order_id = o.order_id 53 | AND o.sales_rep_id = 165; 54 | 55 | CREATE MATERIALIZED VIEW LOG ON customers 56 | PCTFREE 5 57 | TABLESPACE example 58 | STORAGE (INITIAL 10K); 59 | 60 | CREATE MATERIALIZED VIEW LOG ON customers WITH PRIMARY KEY, ROWID; 61 | 62 | CREATE MATERIALIZED VIEW LOG ON sales 63 | WITH ROWID, SEQUENCE(amount_sold, time_id, prod_id) 64 | INCLUDING NEW VALUES; 65 | 66 | CREATE MATERIALIZED VIEW LOG ON order_items WITH (product_id); 67 | 68 | CREATE MATERIALIZED VIEW products_mv 69 | REFRESH FAST ON COMMIT 70 | AS SELECT SUM(list_price - min_price), category_id 71 | FROM product_information 72 | GROUP BY category_id; 73 | 74 | CREATE MATERIALIZED VIEW TEST 75 | AS 76 | WITH TESTCTE AS ( 77 | SELECT 1 ONE FROM DUAL 78 | ) 79 | SELECT 'A', 'B', 'C' 80 | FROM DUAL 81 | JOIN TESTCTE; 82 | 83 | -- tests for column aliases 84 | CREATE MATERIALIZED VIEW sales_mv (year, "prod") 85 | BUILD IMMEDIATE 86 | REFRESH FAST ON COMMIT 87 | AS SELECT t.calendar_year, p.prod_id, 88 | SUM(s.amount_sold) AS sum_sales 89 | FROM times t, products p, sales s 90 | WHERE t.time_id = s.time_id AND p.prod_id = s.prod_id 91 | GROUP BY t.calendar_year, p.prod_id; 92 | 93 | CREATE MATERIALIZED VIEW sales_mv (year ENCRYPT, prod) 94 | BUILD IMMEDIATE 95 | REFRESH FAST ON COMMIT 96 | AS SELECT t.calendar_year, p.prod_id, 97 | SUM(s.amount_sold) AS sum_sales 98 | FROM times t, products p, sales s 99 | WHERE t.time_id = s.time_id AND p.prod_id = s.prod_id 100 | GROUP BY t.calendar_year, p.prod_id; 101 | 102 | CREATE MATERIALIZED VIEW sales_mv (year ENCRYPT, prod ENCRYPT USING 'some_algorithm' IDENTIFIED BY pass 'int_algorithm' NO SALT) 103 | BUILD IMMEDIATE 104 | REFRESH FAST ON COMMIT 105 | AS SELECT t.calendar_year, p.prod_id, 106 | SUM(s.amount_sold) AS sum_sales 107 | FROM times t, products p, sales s 108 | WHERE t.time_id = s.time_id AND p.prod_id = s.prod_id 109 | GROUP BY t.calendar_year, p.prod_id; 110 | 111 | -- tests for scoped table ref constraints 112 | CREATE MATERIALIZED VIEW sales_mv (year ENCRYPT, prod ENCRYPT, SCOPE FOR (ref_col) IS schema.table_or_alias) 113 | BUILD IMMEDIATE 114 | REFRESH FAST ON COMMIT 115 | AS SELECT t.calendar_year, p.prod_id, 116 | SUM(s.amount_sold) AS sum_sales 117 | FROM times t, products p, sales s 118 | WHERE t.time_id = s.time_id AND p.prod_id = s.prod_id 119 | GROUP BY t.calendar_year, p.prod_id; 120 | -------------------------------------------------------------------------------- /examples/max_001.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | 3 | MAX (DISTINCT miles), 4 | MAX (ALL miles) 5 | 6 | FROM Flights -------------------------------------------------------------------------------- /examples/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 | merge into (select * from bonuses) d 11 | using (select employee_id.* from employees) s 12 | on (employee_id = a) 13 | when matched then update set d.bonus = bonus 14 | delete where (salary > 8000) 15 | when not matched then insert (d.employee_id, d.bonus) 16 | values (s.employee_id, s.salary) 17 | where (s.salary <= 8000); -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/merge05.sql: -------------------------------------------------------------------------------- 1 | -- MERGE INTO with a rowtype variable as "insert values" parameter 2 | MERGE INTO salesfront.SF_FORM_REFERENCE_CHOICES_DEF target 3 | USING (select null from dual) 4 | ON (recChoicesDef.id = target.id) 5 | WHEN MATCHED THEN 6 | UPDATE SET target.source_id = recChoicesDef.source_id 7 | WHEN NOT MATCHED THEN 8 | INSERT VALUES recChoicesDef; -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/noaudit_statement.sql: -------------------------------------------------------------------------------- 1 | NOAUDIT ROLE; 2 | NOAUDIT SELECT TABLE BY hr; 3 | NOAUDIT DELETE ANY TABLE; 4 | NOAUDIT SELECT 5 | ON hr.employees; 6 | NOAUDIT SELECT 7 | ON hr.employees 8 | WHENEVER SUCCESSFUL; 9 | -------------------------------------------------------------------------------- /examples/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 subtract "one" in decimal format 11 | , sysdate -1m -- here we subtract "one" and "m" is column's alias 12 | , sysdate -1dm 13 | from dual 14 | -------------------------------------------------------------------------------- /examples/nvl_001.sql: -------------------------------------------------------------------------------- 1 | SELECT last_name, 2 | NVL(TO_CHAR(commission_pct), 'Not Applicable') "COMMISSION" FROM employees 3 | WHERE last_name LIKE 'B%' 4 | ORDER BY last_name -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/offset_clause.sql: -------------------------------------------------------------------------------- 1 | Select * 2 | fROM green_table 3 | offset 1 row; 4 | -------------------------------------------------------------------------------- /examples/order_by01.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by 1 2 | -------------------------------------------------------------------------------- /examples/order_by02.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by 1 asc 2 | -------------------------------------------------------------------------------- /examples/order_by03.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by m.year, m.title, f(a) 2 | -------------------------------------------------------------------------------- /examples/order_by04.sql: -------------------------------------------------------------------------------- 1 | select * from dual order by a nulls first, b nulls last 2 | -------------------------------------------------------------------------------- /examples/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 -------------------------------------------------------------------------------- /examples/order_by06.sql: -------------------------------------------------------------------------------- 1 | with a as (select * from dual order by 1) select * from a 2 | -------------------------------------------------------------------------------- /examples/package_body.sql: -------------------------------------------------------------------------------- 1 | CREATE PACKAGE BODY EMP_BONUS AS 2 | LOCAL_PARAM NUMBER; 3 | USER_EXCEPTION EXCEPTION; 4 | PROCEDURE CALC_BONUS (DATE_HIRED DATE) IS 5 | BEGIN 6 | LOCAL_PARAM:=0; 7 | END; 8 | END EMP_BONUS; -------------------------------------------------------------------------------- /examples/package_body.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (unit_statement (create_package_body CREATE PACKAGE BODY (package_name (identifier (id_expression (regular_id EMP_BONUS)))) AS (package_obj_body (variable_declaration (identifier (id_expression (regular_id LOCAL_PARAM))) (type_spec (datatype (native_datatype_element NUMBER))) ;)) (package_obj_body (exception_declaration (identifier (id_expression (regular_id USER_EXCEPTION))) EXCEPTION ;)) (package_obj_body (procedure_body PROCEDURE (identifier (id_expression (regular_id CALC_BONUS))) ( (parameter (parameter_name (identifier (id_expression (regular_id DATE_HIRED)))) (type_spec (datatype (native_datatype_element DATE)))) ) IS (body BEGIN (seq_of_statements (statement (assignment_statement (general_element (general_element_part (id_expression (regular_id LOCAL_PARAM)))) := (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (numeric 0)))))))))))))) ;) END) ;)) END (package_name (identifier (id_expression (regular_id EMP_BONUS)))) ;)) ) -------------------------------------------------------------------------------- /examples/packagebody_function.sql: -------------------------------------------------------------------------------- 1 | -- Test for ignoring the order of DETERMINISTIC and PIPELINED keywords in function bodies 2 | CREATE OR REPLACE PACKAGE BODY TEST AS 3 | FUNCTION TEST_FUNC RETURN NUMBER PIPELINED DETERMINISTIC AS 4 | BEGIN 5 | RETURN NULL; 6 | END TEST_FUNC; 7 | 8 | FUNCTION TEST_FUNC2 RETURN NUMBER DETERMINISTIC PIPELINED AS 9 | BEGIN 10 | RETURN NULL; 11 | END TEST_FUNC2; 12 | END TEST; 13 | -------------------------------------------------------------------------------- /examples/packagespec_function.sql: -------------------------------------------------------------------------------- 1 | -- Adding pipelined and deterministic keyword in one function spec 2 | CREATE OR REPLACE PACKAGE TEST IS 3 | FUNCTION TEST_FUNC RETURN NUMBER PIPELINED DETERMINISTIC; 4 | END TEST; 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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)) -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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)) -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | ) -------------------------------------------------------------------------------- /examples/purge_statement.sql: -------------------------------------------------------------------------------- 1 | PURGE TABLE test; 2 | PURGE TABLE RB$$33750$TABLE$0; 3 | PURGE RECYCLEBIN; 4 | PURGE TABLESPACE ts USER U; 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/rename_objects.sql: -------------------------------------------------------------------------------- 1 | -- Test for RENAME statement of unit_statement (f.e. renaming Oracle jobs) 2 | RENAME FOO TO BAR; 3 | -------------------------------------------------------------------------------- /examples/revoke_statement.sql: -------------------------------------------------------------------------------- 1 | REVOKE DROP ANY TABLE 2 | FROM hr, oe; 3 | REVOKE dw_manager 4 | FROM sh; 5 | REVOKE CREATE TABLESPACE 6 | FROM dw_manager; 7 | REVOKE dw_user 8 | FROM dw_manager; 9 | REVOKE DELETE 10 | ON orders FROM hr; 11 | REVOKE UPDATE 12 | ON emp_details_view FROM public; 13 | REVOKE INHERIT PRIVILEGES ON USER sh FROM hr; 14 | REVOKE SELECT 15 | ON hr.departments_seq FROM oe; 16 | REVOKE REFERENCES 17 | ON hr.employees 18 | FROM oe 19 | CASCADE CONSTRAINTS; 20 | REVOKE READ ON DIRECTORY bfile_dir FROM hr; 21 | -------------------------------------------------------------------------------- /examples/round_001.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | round( 3 | decode( 4 | a.attribute_name, n.col, 5 | a.attribute_num_value * n.scale + n.shift, 6 | a.attribute_num_value), 4 7 | ) 8 | FROM employees -------------------------------------------------------------------------------- /examples/round_decode_001.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | nvl( 3 | a.attribute_str_value, 4 | round( 5 | decode( 6 | a.attribute_name, n.col, 7 | a.attribute_num_value * n.scale + n.shift, 8 | a.attribute_num_value), 4 9 | ) 10 | ) val 11 | from employees -------------------------------------------------------------------------------- /examples/row_number_001.sql: -------------------------------------------------------------------------------- 1 | SELECT department_id, last_name, employee_id, 2 | ROW_NUMBER() 3 | OVER (PARTITION BY department_id ORDER BY employee_id) AS emp_id 4 | FROM employees 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/select_all_some_any.sql: -------------------------------------------------------------------------------- 1 | 2 | select * from "CW_ROLE" where role_id = some(1,5); 3 | select * from "T_ROLE" where role_id = any(1,5); 4 | select * from "T_ROLE" where role_id = all(1,5); 5 | 6 | select u.name, u.sex, u.age from sys.user u; 7 | -------------------------------------------------------------------------------- /examples/select_package_function.sql: -------------------------------------------------------------------------------- 1 | SELECT DBMS_LOB.SUBSTR(FIELD_1,4000,1) AS FIELD_1, 'ABC' AS FIELD_2 FROM TABLE_1 -------------------------------------------------------------------------------- /examples/select_time.sql: -------------------------------------------------------------------------------- 1 | SELECT TIME '19:00:00'+INTERVAL '9' HOUR, TIME '19:00:00'-INTERVAL '9' HOUR from dual; 2 | SELECT TIME '19:00:00'+INTERVAL '9' DAY, TIME '19:00:00'-INTERVAL '9' DAY from dual; 3 | SELECT TIME '19:00:00'+INTERVAL '9' SECOND, TIME '19:00:00'-INTERVAL '9' SECOND from dual; 4 | -------------------------------------------------------------------------------- /examples/simple02.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update 3 | 4 | -------------------------------------------------------------------------------- /examples/simple03.sql: -------------------------------------------------------------------------------- 1 | select employee_id from (select employee_id+1 as employee_id from employees) 2 | for update of employee_id 3 | 4 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/simple05.sql: -------------------------------------------------------------------------------- 1 | select * from 2 | ( 3 | select * from a 4 | unpivot 5 | ( 6 | value for value_type in (dummy) 7 | ) 8 | ) 9 | 10 | -------------------------------------------------------------------------------- /examples/simple06.sql: -------------------------------------------------------------------------------- 1 | select * from (( select * from dual)) a 2 | 3 | -------------------------------------------------------------------------------- /examples/simple07.sql: -------------------------------------------------------------------------------- 1 | select * from dual for update 2 | of dual 3 | 4 | -------------------------------------------------------------------------------- /examples/simple08.sql: -------------------------------------------------------------------------------- 1 | select a, b, c, d, e, 1, 2, f(a,b,c,1+1) from dual 2 | 3 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/simple10.sql: -------------------------------------------------------------------------------- 1 | select a as over from over 2 | -------------------------------------------------------------------------------- /examples/simple11.sql: -------------------------------------------------------------------------------- 1 | select a.* from dual 2 | -------------------------------------------------------------------------------- /examples/simple12.sql: -------------------------------------------------------------------------------- 1 | select 2 | +1, 3 | t2.division_name as aaaa, 4 | a.*, 5 | sum(t3.amount) 6 | from dual 7 | 8 | -------------------------------------------------------------------------------- /examples/simple13.sql: -------------------------------------------------------------------------------- 1 | select * from (dual), (dual d), (dual) d 2 | -------------------------------------------------------------------------------- /examples/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 | , q'#name like #smth #' 13 | , q''name like 'smth '' 14 | , q'(name like )) )' 15 | , n'nchar literal' 16 | from dual 17 | 18 | -------------------------------------------------------------------------------- /examples/timing.sql: -------------------------------------------------------------------------------- 1 | TIMING 2 | 3 | TIMING START 4 | TIMING START one_word 5 | TIMING START more than one word 6 | 7 | TIMING SHOW 8 | 9 | TIMING STOP 10 | 11 | -- verify that selecting a column named TIMING still work 12 | SELECT timing FROM some_table; 13 | -------------------------------------------------------------------------------- /examples/timing.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (sql_plus_command (timing_command TIMING)) (sql_plus_command (timing_command TIMING START)) (sql_plus_command (timing_command TIMING START (id_expression (regular_id one_word)))) (sql_plus_command (timing_command TIMING START (id_expression (regular_id more)) (id_expression (regular_id (non_reserved_keywords_pre12c than))) (id_expression (regular_id (non_reserved_keywords_in_12c one))) (id_expression (regular_id word)) (id_expression (regular_id (non_reserved_keywords_pre12c TIMING))) (id_expression (regular_id (non_reserved_keywords_pre12c SHOW))) (id_expression (regular_id (non_reserved_keywords_pre12c TIMING))) (id_expression (regular_id (non_reserved_keywords_pre12c STOP))))) (unit_statement (data_manipulation_language_statements (select_statement (select_only_statement (subquery (subquery_basic_elements (query_block SELECT (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (variable_name (id_expression (regular_id (non_reserved_keywords_pre12c timing)))))))))))))))))) (from_clause FROM (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id some_table))))))))))))))))) ; ) -------------------------------------------------------------------------------- /examples/to_binary_double.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | to_binary_double(raw_value), 4 | to_binary_double(raw_value, '9990.9999'), 5 | to_binary_double(raw_value, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN'), 6 | to_binary_double(raw_value default 0 on conversion error), 7 | to_binary_double(raw_value default 0 on conversion error, '9990.9999'), 8 | to_binary_double(raw_value default 0 on conversion error, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN') 9 | from raw_values; -------------------------------------------------------------------------------- /examples/to_binary_float.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | to_binary_float(raw_value), 4 | to_binary_float(raw_value, '9990.9999'), 5 | to_binary_float(raw_value, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN'), 6 | to_binary_float(raw_value default 0 on conversion error), 7 | to_binary_float(raw_value default 0 on conversion error, '9990.9999'), 8 | to_binary_float(raw_value default 0 on conversion error, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN') 9 | from raw_values; -------------------------------------------------------------------------------- /examples/to_char.sql: -------------------------------------------------------------------------------- 1 | SELECT TO_CHAR(SYSDATE), TO_CHAR(SYSDATE, 'D'), TO_CHAR(SYSDATE, 'D', 'NLS_DATE_LANGUAGE = RUSSIAN') FROM DUAL -------------------------------------------------------------------------------- /examples/to_char_001.sql: -------------------------------------------------------------------------------- 1 | SELECT TO_CHAR("date", 'YYYY-MM') || '-01' as "month" FROM employes -------------------------------------------------------------------------------- /examples/to_char_002.sql: -------------------------------------------------------------------------------- 1 | select TO_CHAR(commission_pct) as "commission" from employees -------------------------------------------------------------------------------- /examples/to_date.sql: -------------------------------------------------------------------------------- 1 | SELECT TO_DATE('01.01.2012') FROM DUAL 2 | SELECT TO_DATE('01.01.2012', 'dd.mm.yyyy') FROM DUAL 3 | SELECT TO_DATE('01' || '.01.2012', 'dd.mm.yyyy') FROM DUAL 4 | SELECT TO_DATE('01.' || (NQUATER*3 - 2) || '.' || NRYEAR, 'DD.MM.YYYY') FROM DUAL 5 | SELECT LAST_DAY(TO_DATE('01.' || (NQUATER*3 - 2) || '.' || NRYEAR, 'DD.MM.YYYY')) FROM DUAL 6 | SELECT TO_CHAR(LAST_DAY(TO_DATE('01.' || (NQUATER*3 - 2) || '.' || NRYEAR, 'DD.MM.YYYY')),'DD') FROM DUAL 7 | SELECT TO_DATE("CHAR_COLUMN") FROM EMPLOYES 8 | SELECT TO_DATE("CHAR_COLUMN",'DD.MM.YYYY') FROM EMPLOYES 9 | SELECT TO_DATE(E."CHAR_COLUMN",'DD.MM.YYYY') FROM EMPLOYES E 10 | SELECT TO_DATE('01.01.2012' DEFAULT NULL ON CONVERSION ERROR) FROM DUAL 11 | SELECT TO_DATE('01.01.2012' DEFAULT NULL ON CONVERSION ERROR, 'dd.mm.yyyy') FROM DUAL 12 | SELECT TO_DATE('01.01.2012' DEFAULT NULL ON CONVERSION ERROR, 'dd.mm.yyyy', 'NLS_DATE_LANGUAGE = RUSSIAN') FROM DUAL 13 | SELECT TO_DATE('01.01.2012' DEFAULT '01.01.1970' ON CONVERSION ERROR) FROM DUAL 14 | SELECT TO_DATE('01.01.2012' DEFAULT '01.01.1970' ON CONVERSION ERROR, 'dd.mm.yyyy') FROM DUAL 15 | SELECT TO_DATE('01.01.2012' DEFAULT '01.01.1970' ON CONVERSION ERROR, 'dd.mm.yyyy', 'NLS_DATE_LANGUAGE = RUSSIAN') FROM DUAL 16 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT NULL ON CONVERSION ERROR) FROM DUAL 17 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT NULL ON CONVERSION ERROR, 'dd.mm.yyyy') FROM DUAL 18 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT NULL ON CONVERSION ERROR, 'dd.mm.yyyy', 'NLS_DATE_LANGUAGE = RUSSIAN') FROM DUAL 19 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT '01.01.1970' ON CONVERSION ERROR) FROM DUAL 20 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT '01.01.1970' ON CONVERSION ERROR, 'dd.mm.yyyy') FROM DUAL 21 | SELECT TO_DATE("CHAR_COLUMN" DEFAULT '01.01.1970' ON CONVERSION ERROR, 'dd.mm.yyyy', 'NLS_DATE_LANGUAGE = RUSSIAN') FROM DUAL -------------------------------------------------------------------------------- /examples/to_dsinterval.sql: -------------------------------------------------------------------------------- 1 | select 2 | to_dsinterval('10 1:02:10'), 3 | to_dsinterval('1o 1:02:10' default '10 8:00:00' on conversion error), 4 | to_dsinterval(raw_value), 5 | to_dsinterval(raw_value default '10 8:00:00' on conversion error), 6 | to_dsinterval("RAW_VALUE" default '10 8:00:00' on conversion error) 7 | from raw_values; -------------------------------------------------------------------------------- /examples/to_number.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | to_number(raw_value), 4 | to_number(raw_value, '9990.9999'), 5 | to_number(raw_value, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN'), 6 | to_number(raw_value default 0 on conversion error), 7 | to_number(raw_value default 0 on conversion error, '9990.9999'), 8 | to_number(raw_value default 0 on conversion error, '9990.9999', 'NLS_DATE_LANGUAGE = RUSSIAN') 9 | from raw_values; -------------------------------------------------------------------------------- /examples/to_timestamp.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | to_timestamp(raw_value), 4 | to_timestamp(raw_value, 'YYYY-MM-DD'), 5 | to_timestamp(raw_value, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN'), 6 | to_timestamp(raw_value default '1970-01-01' on conversion error, 'YYYY-MM-DD'), 7 | to_timestamp(raw_value default '1970-01-01' on conversion error, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN'), 8 | to_timestamp(raw_value default null on conversion error), 9 | to_timestamp(raw_value default null on conversion error, 'YYYY-MM-DD'), 10 | to_timestamp(raw_value default null on conversion error, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN') 11 | from raw_values; -------------------------------------------------------------------------------- /examples/to_timestamp_tz.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | to_timestamp_tz(raw_value), 4 | to_timestamp_tz(raw_value, 'YYYY-MM-DD'), 5 | to_timestamp_tz(raw_value, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN'), 6 | to_timestamp_tz(raw_value default '1970-01-01' on conversion error, 'YYYY-MM-DD'), 7 | to_timestamp_tz(raw_value default '1970-01-01' on conversion error, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN'), 8 | to_timestamp_tz(raw_value default null on conversion error), 9 | to_timestamp_tz(raw_value default null on conversion error, 'YYYY-MM-DD'), 10 | to_timestamp_tz(raw_value default null on conversion error, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN') 11 | from raw_values; -------------------------------------------------------------------------------- /examples/to_yminterval.sql: -------------------------------------------------------------------------------- 1 | select 2 | to_dsinterval('10-02'), 3 | to_dsinterval('1x-02' default '00-00' on conversion error), 4 | to_dsinterval(raw_value), 5 | to_dsinterval(raw_value default '00-00' on conversion error), 6 | to_dsinterval("RAW_VALUE" default '00-00' on conversion error) 7 | from raw_values; -------------------------------------------------------------------------------- /examples/truncate_cluster.sql: -------------------------------------------------------------------------------- 1 | TRUNCATE CLUSTER personnel REUSE STORAGE; 2 | -------------------------------------------------------------------------------- /examples/truncate_table.sql: -------------------------------------------------------------------------------- 1 | truncate table test; -------------------------------------------------------------------------------- /examples/unified.sql: -------------------------------------------------------------------------------- 1 | AUDIT POLICY table_pol; 2 | AUDIT POLICY dml_pol BY hr, sh; 3 | 4 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/union02.sql: -------------------------------------------------------------------------------- 1 | select distinct job_id from hr.jobs 2 | union all 3 | select distinct job_id from hr.job_history 4 | 5 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/union08.sql: -------------------------------------------------------------------------------- 1 | select * from dual where exists ( 2 | select * from dual 3 | union all 4 | select * from dual 5 | ) 6 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/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 | -------------------------------------------------------------------------------- /examples/validate_conversion.sql: -------------------------------------------------------------------------------- 1 | select 2 | raw_value, 3 | validate_conversion(raw_value as number), 4 | validate_conversion(raw_value as date, 'YYYY-MM-DD'), 5 | validate_conversion(raw_value as date, 'YYYY-MM-DD', 'NLS_DATE_LANGUAGE = RUSSIAN') 6 | from raw_values; -------------------------------------------------------------------------------- /examples/views.sql: -------------------------------------------------------------------------------- 1 | CREATE VIEW emp_view AS 2 | SELECT last_name, salary*12 annual_salary 3 | FROM employees 4 | WHERE department_id = 20; 5 | 6 | CREATE EDITIONING VIEW ed_orders_view (o_id, o_date, o_status) 7 | AS SELECT order_id, order_date, order_status FROM orders 8 | WITH READ ONLY; 9 | 10 | CREATE VIEW emp_sal (emp_id, last_name, 11 | email UNIQUE RELY DISABLE NOVALIDATE, 12 | CONSTRAINT id_pk PRIMARY KEY (emp_id) RELY DISABLE NOVALIDATE) 13 | AS SELECT employee_id, last_name, email FROM employees; 14 | 15 | CREATE VIEW clerk AS 16 | SELECT employee_id, last_name, department_id, job_id 17 | FROM employees 18 | WHERE job_id = 'PU_CLERK' 19 | or job_id = 'SH_CLERK' 20 | or job_id = 'STA_CLERK'; 21 | 22 | CREATE VIEW clerk AS 23 | SELECT employee_id, last_name, department_id, job_id 24 | FROM employees 25 | WHERE job_id = 'PU_CLERK' 26 | or job_id = 'SH_CLERK' 27 | or job_id = 'ST_CLERK' 28 | WITH CHECK OPTION; 29 | 30 | CREATE VIEW locations_view AS 31 | SELECT d.department_id, d.department_name, l.location_id, l.city 32 | FROM departments d, locations l 33 | WHERE d.location_id = l.location_id; 34 | 35 | CREATE VIEW customer_ro (name, language, credit) 36 | AS SELECT cust_last_name, nls_language, credit_limit 37 | FROM customers 38 | WITH READ ONLY; 39 | 40 | CREATE OR REPLACE VIEW oc_inventories OF inventory_typ 41 | WITH OBJECT ID (product_id) 42 | AS SELECT i.product_id, 43 | warehouse_typ(w.warehouse_id, w.warehouse_name, w.location_id), 44 | i.quantity_on_hand 45 | FROM inventories i, warehouses w 46 | WHERE i.warehouse_id=w.warehouse_id; 47 | 48 | CREATE EDITIONABLE VIEW TEST (A, B, C) 49 | AS SELECT 'A', 'B', 'C' 50 | FROM DUAL; 51 | 52 | CREATE VIEW TEST (A, B, C) 53 | AS 54 | WITH TESTCTE AS ( 55 | SELECT 1 ONE FROM DUAL 56 | ) 57 | SELECT 'A', 'B', 'C' 58 | FROM DUAL 59 | JOIN TESTCTE; 60 | -------------------------------------------------------------------------------- /examples/whenever_sqlerror.sql: -------------------------------------------------------------------------------- 1 | WHENEVER SQLERROR CONTINUE; 2 | WHENEVER SQLERROR CONTINUE COMMIT; 3 | WHENEVER SQLERROR CONTINUE ROLLBACK; 4 | WHENEVER SQLERROR CONTINUE NONE; 5 | 6 | WHENEVER SQLERROR EXIT SQL.SQLCODE; 7 | WHENEVER SQLERROR EXIT SQL.SQLCODE COMMIT; 8 | WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK; 9 | 10 | WHENEVER SQLERROR EXIT 1; 11 | -------------------------------------------------------------------------------- /examples/whenever_sqlerror.sql.tree: -------------------------------------------------------------------------------- 1 | (sql_script (sql_plus_command (whenever_command WHENEVER SQLERROR CONTINUE)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR CONTINUE COMMIT)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR CONTINUE ROLLBACK)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR CONTINUE NONE)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR EXIT (variable_name (id_expression (regular_id (non_reserved_keywords_pre12c SQL))) . (id_expression (regular_id SQLCODE))))) ; (sql_plus_command (whenever_command WHENEVER SQLERROR EXIT (variable_name (id_expression (regular_id (non_reserved_keywords_pre12c SQL))) . (id_expression (regular_id SQLCODE))) COMMIT)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR EXIT (variable_name (id_expression (regular_id (non_reserved_keywords_pre12c SQL))) . (id_expression (regular_id SQLCODE))) ROLLBACK)) ; (sql_plus_command (whenever_command WHENEVER SQLERROR EXIT (numeric 1))) ; ) -------------------------------------------------------------------------------- /examples/xml_function.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | XMLAGG(XMLELEMENT(X,first_name, ',') 3 | ORDER BY FIRST_NAME).extract('//text()').getClobVal() AS "NAMES" 4 | FROM STUDENTS; 5 | 6 | SELECT 7 | XMLCOLATTVAL(first_name,first_name, first_name).extract('//text()').getClobVal() 8 | FROM STUDENTS; 9 | 10 | SELECT 11 | XMLFOREST(first_name,first_name, first_name).extract('//text()').getClobVal() 12 | FROM STUDENTS; 13 | 14 | SELECT 15 | XMLELEMENT(TEST,first_name , ',').extract('//text()').getClobVal() 16 | FROM STUDENTS; 17 | 18 | SELECT XMLPARSE(CONTENT '124 19 | Acme Enterprises 20 | 32987457 21 | ' 22 | WELLFORMED).extract('//text()').getClobVal() AS PO FROM DUAL; 23 | 24 | SELECT XMLPI(NAME "Order analysisComp", 'imported, reconfigured, disassembled').extract('//text()').getClobVal() 25 | AS "XMLPI" FROM DUAL; 26 | 27 | SELECT warehouse_name, 28 | EXTRACTVALUE(warehouse_spec, '/Warehouse/Area'), 29 | XMLQuery( 30 | 'for $i in /Warehouse 31 | where $i/Area > 50000 32 | return
33 | 34 | 35 | { 36 | if ($i/RailAccess = "Y") then "true" else "false" 37 | } 38 | 39 |
' PASSING warehouse_spec RETURNING CONTENT).extract('//text()').getClobVal() "Big_warehouses" 40 | FROM warehouses; 41 | 42 | SELECT XMLROOT ( XMLType('143598'), VERSION '1.0', STANDALONE YES).extract('//text()').getClobVal() 43 | AS "XMLROOT" FROM DUAL; 44 | -------------------------------------------------------------------------------- /examples/xmltable01.sql: -------------------------------------------------------------------------------- 1 | -- See https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions228.htm 2 | 3 | SELECT warehouse_name warehouse, 4 | warehouse2."Water", warehouse2."Rail", warehouse2."Box" 5 | FROM warehouses, 6 | XMLTABLE(xmlnamespaces ('http://www.example.com/xml/path' AS "a"), 7 | '/Warehouse' 8 | PASSING warehouses.warehouse_spec 9 | COLUMNS 10 | "Water" varchar2(6) PATH '/Warehouse/WaterAccess', 11 | "Rail" varchar2(6) PATH '/Warehouse/RailAccess', 12 | "Box" varchar2(6) PATH '/Warehouse/BoxAccess') 13 | warehouse2; -------------------------------------------------------------------------------- /examples/xmltable02.sql: -------------------------------------------------------------------------------- 1 | select xmlelement("other_attrs", xmlelement("parsing_user_id", parsing_user_id)).getClobVal() other 2 | from f 3 | -------------------------------------------------------------------------------- /examples/xmltable03.sql: -------------------------------------------------------------------------------- 1 | -- XMLTable and outer join methods: http://anononxml.blogspot.com/2011/06/xmltable-and-outer-join-methods.html 2 | 3 | select master_id 4 | ,details_id 5 | ,sub_details_id 6 | from demo4 s 7 | ,XMLTable('master' 8 | passing (s.xml) 9 | columns master_id varchar2 (20) path 'id' 10 | ,details XMLType path 'details/detail') mstr 11 | ,XMLTable('detail' 12 | passing (mstr.details) 13 | columns details_id varchar2 (20) path 'id' 14 | ,sub_details XMLType path 'sub_details/sub_detail')(+) dtl 15 | ,XMLTable('sub_detail' 16 | passing (dtl.sub_details) 17 | columns sub_details_id varchar2 (20) path 'id')(+) sub_dtl; -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bytebase/plsql-parser 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/antlr4-go/antlr/v4 v4.13.0 7 | github.com/stretchr/testify v1.8.2 8 | ) 9 | 10 | require ( 11 | github.com/davecgh/go-spew v1.1.1 // indirect 12 | github.com/pmezard/go-difflib v1.0.0 // indirect 13 | golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect 14 | gopkg.in/yaml.v3 v3.0.1 // indirect 15 | ) 16 | 17 | replace github.com/antlr4-go/antlr/v4 => github.com/bytebase/antlr/v4 v4.0.0-20231103101006-5fe1a93b199f 18 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/bytebase/antlr/v4 v4.0.0-20231103101006-5fe1a93b199f h1:5O8DZOEloYvnAZIdHb31MT9L1Xn163rWlZqRsKqTEFM= 2 | github.com/bytebase/antlr/v4 v4.0.0-20231103101006-5fe1a93b199f/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= 3 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 5 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 7 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 8 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 9 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 10 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 11 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 12 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 13 | github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= 14 | github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 15 | golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= 16 | golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 21 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 22 | -------------------------------------------------------------------------------- /parser_test.go: -------------------------------------------------------------------------------- 1 | package parser_test 2 | 3 | import ( 4 | "os" 5 | "path" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/antlr4-go/antlr/v4" 10 | plsqlparser "github.com/bytebase/plsql-parser" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | type CustomErrorListener struct { 15 | errors int 16 | } 17 | 18 | func NewCustomErrorListener() *CustomErrorListener { 19 | return new(CustomErrorListener) 20 | } 21 | 22 | func (l *CustomErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { 23 | l.errors += 1 24 | antlr.ConsoleErrorListenerINSTANCE.SyntaxError(recognizer, offendingSymbol, line, column, msg, e) 25 | } 26 | 27 | func (l *CustomErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs *antlr.ATNConfigSet) { 28 | antlr.ConsoleErrorListenerINSTANCE.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) 29 | } 30 | 31 | func (l *CustomErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs *antlr.ATNConfigSet) { 32 | antlr.ConsoleErrorListenerINSTANCE.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) 33 | } 34 | 35 | func (l *CustomErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs *antlr.ATNConfigSet) { 36 | antlr.ConsoleErrorListenerINSTANCE.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) 37 | } 38 | 39 | func TestPLSQLParser(t *testing.T) { 40 | examples, err := os.ReadDir("examples") 41 | require.NoError(t, err) 42 | 43 | examplesSQLScript, err := os.ReadDir("examples-sql-script") 44 | require.NoError(t, err) 45 | 46 | files := append(examples, examplesSQLScript...) 47 | 48 | for i, file := range files { 49 | if strings.HasSuffix(file.Name(), ".sql.tree") { 50 | continue 51 | } 52 | var filePath string 53 | if i < len(examples) { 54 | filePath = path.Join("examples", file.Name()) 55 | } else { 56 | filePath = path.Join("examples-sql-script", file.Name()) 57 | } 58 | t.Run(filePath, func(t *testing.T) { 59 | t.Parallel() 60 | input, err := antlr.NewFileStream(filePath) 61 | require.NoError(t, err) 62 | 63 | lexer := plsqlparser.NewPlSqlLexer(input) 64 | 65 | stream := antlr.NewCommonTokenStream(lexer, 0) 66 | p := plsqlparser.NewPlSqlParser(stream) 67 | p.SetVersion12(true) 68 | 69 | lexerErrors := &CustomErrorListener{} 70 | lexer.RemoveErrorListeners() 71 | lexer.AddErrorListener(lexerErrors) 72 | 73 | parserErrors := &CustomErrorListener{} 74 | p.RemoveErrorListeners() 75 | p.AddErrorListener(parserErrors) 76 | 77 | p.BuildParseTrees = true 78 | _ = p.Sql_script() 79 | 80 | require.Equal(t, 0, lexerErrors.errors) 81 | require.Equal(t, 0, parserErrors.errors) 82 | }) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /plsql_parser_base.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "github.com/antlr4-go/antlr/v4" 5 | ) 6 | 7 | // PlSqlParserBase implementation. 8 | type PlSqlParserBase struct { 9 | *antlr.BaseParser 10 | _isVersion12 bool 11 | _isVersion10 bool 12 | } 13 | 14 | func (p *PlSqlParserBase) IsTableAlias() bool { 15 | return p.GetCurrentToken().GetTokenType() != PlSqlLexerJOIN 16 | } 17 | 18 | func (p *PlSqlParserBase) isVersion12() bool { 19 | return p._isVersion12 20 | } 21 | 22 | func (p *PlSqlParserBase) SetVersion12(value bool) { 23 | p._isVersion12 = value 24 | } 25 | 26 | func (p *PlSqlParserBase) isVersion10() bool { 27 | return p._isVersion10 28 | } 29 | 30 | func (p *PlSqlParserBase) SetVersion10(value bool) { 31 | p._isVersion10 = value 32 | } 33 | --------------------------------------------------------------------------------