SQL92 Grammar

The following SQL grammars are currently available:

SQL A simple subset of the SQL language
SQL92 The full SQL92 grammar, based on ISO standard SQL2 (shown below)
TSQL A Beta version of the TSQL grammar
PL/SQL A Beta version of the Oracle 9i PL/SQL grammar

The grammar definition shown below describes the syntax for the SQL92 language.


// =================================================================
// ProGrammar Grammar Definition File
// -----------------------------------------------------------------
//  
//  SQL2.GDL  -  Based on ISO standard SQL2 (also called SQL92)
//
//  This example is intended for demonstration purposes only.
//
//  Copyright (c) 2001 NorKen Technologies, Inc.
//
// ==================================================================
//
// Abbreviations used in rule's names
// 
//    author authorization
//    char   character
//    dec    declaration
//    def    defined
//    def    definition
//    diag   diagnostics
//    dyn    dynamic
//    embdd  embedded
//    exec   executable
//    exp    expression
//    fct    function
//    frac   fractional
//    id     identifier
//    implt  implementation
//    lit    literal
//    num    numeric
//    op     operator
//    pos    positionned
//    ref    referential
//    rep    repertoire
//    spec   specification
//    std    standard
//    stmt   statement
//    univ   universal 
//
// =====================================================================
//
//   REVISION DATE:    01/10/02
//

grammar SQL2 <IGNORECASE, 
          SPACE = space_symbol, 
          HIDELITERALS,
          NOBACKTRACK>
{
start ::= 
    {direct_sql_stmt [";"] };

direct_sql_stmt ::= 
        direct_sql_data_stmt 
      | SQL_schema_stmt 
      | SQL_transaction_stmt 
      | SQL_connection_stmt 
      | SQL_session_stmt 
    ;

direct_sql_data_stmt ::= 
        delete_stmt_searched 
      | direct_select_stmt_n_rows 
      | insert_stmt 
      | update_stmt_searched 
      | temporary_table_decl ;

direct_select_stmt_n_rows ::= 
      query_exp [order_by_clause] ;


SQL_schema_stmt ::= 
        SQL_schema_def_stmt 
      | SQL_schema_manipulation_stmt ;

SQL_schema_def_stmt ::= 
        schema_def 
      | table_def 
      | view_def 
      | grant_stmt 
      | domain_def 
      | char_set_def 
      | collation_def 
      | translation_def 
      | assertion_def ;

SQL_schema_manipulation_stmt ::= 
        drop_schema_stmt 
      | alter_table_stmt 
      | drop_table_stmt 
      | drop_view_stmt 
      | revoke_stmt 
      | alter_domain_stmt 
      | drop_domain_stmt 
      | drop_char_set_stmt 
      | drop_collation_stmt 
      | drop_translation_stmt 
      | drop_assertion_stmt ;

SQL_transaction_stmt ::= 
        set_transaction_stmt 
      | set_constraints_mode_stmt 
      | commit_stmt 
      | rollback_stmt ;

SQL_connection_stmt ::= 
        connect_stmt 
      | set_connection_stmt 
      | disconnect_stmt ;

SQL_session_stmt ::= 
        set_catalog_stmt 
      | set_schema_stmt 
      | set_names_stmt 
      | set_session_auth_ident_stmt 
      | set_local_time_zone_stmt ;

action ::= 
      delete_action
    | usage_action
    | select_action
    | insert_action
    | update_action
    | references_action
    ;

delete_action ::= 
    "delete";

usage_action ::=
    "usage" ;

select_action ::=
    "select" ["(" privilege_column_list ")"];

insert_action ::=
    "insert" ["(" privilege_column_list ")"];

update_action ::=
    "update" ["(" privilege_column_list ")"];

references_action ::=
    "references" ["(" privilege_column_list ")"] ;

action_list ::= 
    {action, ","};

add_column_def ::= 
      "add" ["column"] column_def ;
      
add_domain_constraint_def ::= 
      "add" domain_constraint ;

add_table_constraint_def ::= 
      "add" table_constraint_def ;

alter_column_action ::= 
        set_column_default_clause 
      | drop_column_default_clause
      ;
      
alter_column_def ::= 
      "alter" ["column"] 
    column_name alter_column_action ;      
      
alter_domain_action ::= 
        set_domain_default_clause 
      | drop_domain_default_clause 
      | add_domain_constraint_def 
      | drop_domain_constraint_def 
      ;
      
alter_domain_stmt ::= 
      "alter" "domain" 
    domain_name alter_domain_action ;
      
alter_table_action ::= 
        add_column_def 
      | alter_column_def 
      | drop_column_def 
      | add_table_constraint_def 
      | drop_table_constraint_def
      ;
      
alter_table_stmt ::= 
      "alter" "table" 
    table_name alter_table_action 
      ;

assertion_check ::= 
      "check" 
      "(" search_condition ")" ;
      
assertion_def ::= 
      "create" "assertion" 
    constraint_name assertion_check 
      [constraint_attributes] ;
      
                                                            
as_clause ::= 
    ["as"] column_name;
      
between_predicate ::= 
      row_value_constructor 
    [not_tag] "between" row_value_constructor 
    "and" row_value_constructor ;

not_tag ::=
    "not" ;

case_abbreviation ::= 
      nullif_case_abbreviation
    | coalesce_case_abbreviation
    ;

nullif_case_abbreviation ::=
    "nullif" "(" value_exp "," value_exp ")"  ;

coalesce_case_abbreviation ::=
      "coalesce" "(" { value_exp, "," } ")" ;            

case_exp ::= 
        case_abbreviation 
      | case_spec ;
      
case_operand ::= 
    value_exp ;
      
case_spec ::= 
        simple_case 
      | searched_case ;
      
cast_operand ::= 
        value_exp 
    | null_tag;

null_tag ::=
      "null" ;

cast_spec ::= 
      "cast" "(" cast_operand "as" 
      cast_target ")" ;

cast_target ::= 
        domain_name 
      | data_type ;

char_factor ::= 
      char_primary [collate_clause] ;

char_length_exp ::= 
      ("char_length" | "character_length")
      "(" string_value_exp ")" ;
      
char_primary ::= 
        value_exp_primary 
      | string_value_fct ;

char_substring_fct ::= 
      "substring" "(" char_value_exp 
    "from" start_position 
      [for_string_length] ")" ;

    for_string_length ::= 
        "for" string_length ;

char_translation ::= 
      "translate" "(" char_value_exp 
      "using" translation_name ")" ;

char_value_exp ::= 
    { char_factor, concatenation_op };
      
concatenation_op ::= 
    "||" ;
      
char_value_fct ::= 
        char_substring_fct 
      | fold 
      | form_conversion 
      | char_translation 
      | trim_fct 
      ;

check_constraint_def ::= 
      "check" 
      "(" search_condition ")" ;

column_constraint ::= 
        not_null_spec
      | unique_spec 
      | refs_spec 
      | check_constraint_def ;
      
not_null_spec ::= 
    not_tag null_tag ;

column_constraint_def ::= 
      [constraint_name_def] 
      column_constraint 
      [constraint_attributes] ;

column_def ::= 
      column_name 
      (data_type | domain_name)
      [default_clause] 
      [{column_constraint_def}] 
      [collate_clause] ;

column_name_list ::= 
    {column_name, ","} ;

commit_stmt ::= 
      "commit" ["work"] ;

comp_op ::= 
        "=" 
      | "<>"
      | "<" 
      | ">" 
      | "<="
      | ">=" ;

comp_predicate ::= 
      row_value_constructor comp_op 
      row_value_constructor ;

connection_name ::= 
    simple_value_spec ;

connection_object ::= 
        default_tag
      | connection_name ;

default_tag ::=
    "default" ;

connection_target ::= 
        sql_server_name 
        ["as" connection_name] 
        ["user" user_name] 
      | default_tag ;

connect_stmt ::= 
      "connect" "to" connection_target ;

constraint_attributes ::= 
        constraint_check_time 
      [[not_tag] deferrable_tag] 
      | [not_tag] deferrable_tag 
      [constraint_check_time] ;

deferrable_tag ::=
    "deferrable" ;

constraint_check_time ::= 
      "initially" 
    (deferrable_tag | immediate_tag) ;

immediate_tag ::=
    "immediate" ;

constraint_name ::= 
    qualified_name ;

constraint_name_def ::= 
    "constraint" constraint_name ;

constraint_name_list ::= 
      all_tag
      | {constraint_name, ","} ;

all_tag ::= 
    "all" ;

corresponding_column_list ::= 
    column_name_list ;

corresponding_spec ::= 
      "corresponding" 
    [by_corresponding_column_list] ;

by_corresponding_column_list ::=
    "by" "(" corresponding_column_list ")" ;

cross_join ::= 
      "cross" "join" table_ref ;

data_type ::= 
        char_string_type 
        ["character" "set" char_set_spec] 
      | national_char_string_type 
      | bit_string_type 
      | num_type 
      | datetime_type 
      | interval_type ;

default_clause ::= 
      "default" default_option ;

default_option ::= 
        lit 
      | datetime_value_fct 
      | user
      | current_user
      | session_user
      | system_user
      | default_option_null
      ;

user ::= 
    "user" ;

current_user ::= 
    "current_user" ;

session_user ::= 
    "session_user" ;

system_user ::= 
    "system_user" ;

default_option_null ::= 
    "null" ;

default_spec ::= 
      "default" ;

delete_rule ::= 
    "on" "delete" ref_action ;

delete_stmt_searched ::= 
      "delete" "from" table_name 
      ["where" search_condition] ;

derived_column ::= 
    value_exp [as_clause];

derived_column_list ::= 
    column_name_list ;

diag_size ::= 
      "diagnostics" "size" 
    number_of_conditions ;

disconnect_object ::= 
        connection_object
    | all_tag
    | current_tag
    ;

current_tag ::=
    "current" ;

disconnect_stmt ::= 
      "disconnect" disconnect_object ;

domain_constraint ::= 
      [constraint_name_def] 
      check_constraint_def 
    [constraint_attributes] ;

domain_def ::= 
      "create" "domain" domain_name 
      ["as"] data_type 
      [default_clause] 
      [{domain_constraint}]
      [collate_clause] ;

domain_name ::= 
    qualified_name ;

drop_assertion_stmt ::= 
      "drop" "assertion" 
    constraint_name ;

drop_behavior ::= 
      "cascade" 
    | "restrict" ;

drop_column_def ::= 
      "drop" ["column"] 
    column_name drop_behavior ;

drop_column_default_clause ::= 
      "drop" "default" ;

drop_domain_constraint_def ::= 
      "drop" "constraint" 
    constraint_name ;

drop_domain_default_clause ::= 
    "drop" "default" ;

drop_domain_stmt ::= 
      "drop" "domain" 
    domain_name drop_behavior ;

drop_schema_stmt ::= 
      "drop" "schema" 
    qualified_name drop_behavior ;

drop_table_constraint_def ::= 
      "drop" "constraint" 
    constraint_name drop_behavior ;

drop_table_stmt ::= 
      "drop" "table" 
    table_name drop_behavior ;

drop_view_stmt ::= 
      "drop" "view" 
    table_name drop_behavior ;

dyn_parameter_spec ::= 
    "?" ;

else_clause ::= 
    "else" result ;

escape_char ::= 
    char_value_exp ;

exists_predicate ::= 
    "exists" table_subquery ;

explicit_table ::= 
    "table" table_name ;

extract_exp ::= 
      "extract" "(" extract_field 
      "from" extract_source ")" ;

extract_field ::= 
        datetime_field 
      | time_zone_field ;

extract_source ::= 
        datetime_value_exp 
      | interval_value_exp ;

factor ::= 
      [sign] num_primary ;

fold ::= 
    upper_or_lower
      "(" char_value_exp ")" ;

upper_or_lower ::=
      "upper" 
    | "lower" ;

form_conversion ::= 
      "convert" "(" char_value_exp 
      "using" form_conversion_name ")" ;

form_conversion_name ::= 
    qualified_name ;


from_clause ::= 
    "from" {table_ref, ","} ;

general_set_fct ::= 
      set_fct_type 
      "(" [set_quantifier] value_exp ")" ;

general_value_spec ::= 
        parameter_spec 
      | dyn_parameter_spec 
      | variable_spec 
      | user
      | current_user
      | session_user
      | system_user
      | value_tag ;

value_tag ::=
    "value" ;

grantee ::= 
        public_tag
      | authorization_ident ;

public_tag ::=
    "public" ;

grant_stmt ::= 
      "grant" privileges "on" object_name 
      "to" {grantee, grantee} 
      [with_grant_option] ;

with_grant_option ::=
    "with" "grant" "option" ;

grouping_column_ref ::= 
      column_ref [collate_clause] ;

grouping_column_ref_list ::= 
      {grouping_column_ref, ","} ;

group_by_clause ::= 
      "group" "by" 
    grouping_column_ref_list ;

having_clause ::= 
    "having" search_condition ;

indicator_parameter ::= 
      [indicator_tag] parameter_name ;

indicator_tag ::=
    "indicator" ;

indicator_variable ::= 
      [indicator_tag] embdd_variable_name ;

insert_columns_and_source ::= 
        ["(" insert_column_list ")"] query_exp 
      | default_values_tag ;

default_values_tag ::=
    "default" "values" ;

insert_column_list ::= 
    column_name_list ;

insert_stmt ::= 
      "insert" "into" table_name 
      insert_columns_and_source ;

in_predicate ::= 
      row_value_constructor 
      [not_tag] "in" in_predicate_value ;

in_predicate_value ::= 
        table_subquery 
      | [values_tag] "(" in_value_list ")" ;

values_tag ::= 
    "values" ;

in_value_list ::= 
      {value_exp, ","} ;

isolation_level ::= 
      "isolation" "level" 
    level_of_isolation ;

joined_table ::= 
      table_ref_simple (cross_join | qualified_join)
    | "(" joined_table ")" 
    ;

join_column_list ::= 
    column_name_list ;

join_condition ::= 
    "on" search_condition ;

join_spec ::= 
        join_condition 
      | named_columns_join ;

join_type ::= 
        inner_join_type 
      | outer_join_type ["outer"] 
      | union_join_type 
    ;

inner_join_type ::=
    "inner" ;

union_join_type ::=
    "union" ;

length_exp ::= 
        char_length_exp 
      | octet_length_exp 
      | bit_length_exp ;

levels_clause ::= 
        "cascaded" 
      | "local" ;

level_of_isolation ::= 
        "read" "uncommitted" 
      | "read" "committed" 
      | "repeatable" "read" 
      | "serializable" ;

like_predicate ::= 
      match_value [not_tag] "like" pattern 
      ["escape" escape_char] ;

match_predicate ::= 
      row_value_constructor 
    "match" [unique_tag] 
      [match_type] table_subquery ;

unique_tag ::=
    "unique" ;

match_type ::= 
        "full" 
      | "partial" ;

match_value ::= 
    char_value_exp ;

named_columns_join ::= 
      "using" "(" join_column_list ")" ;


query_exp ::= 
    { query_term, (union_tag | except_tag) 
      [all_tag] [ corresponding_spec ] };

union_tag ::= 
    "union" ;

except_tag ::=
    "except" ;


query_term ::= 
    { query_primary, "intersect" 
      [all_tag] [ corresponding_spec ] };

query_primary ::= 
        simple_table 
      | joined_table
      | "(" query_exp ")" ;

null_predicate ::= 
    row_value_constructor 
      "is" [not_tag] null_tag ;

number_of_conditions ::= 
    simple_value_spec ;

num_primary ::= 
        value_exp_primary 
      | num_value_fct ;

num_value_fct ::= 
        position_exp 
      | extract_exp 
      | length_exp ;
      
num_value_exp ::= 
    {term, term_op} ;

term_op ::=
    "+" | "-" ;

object_column ::= 
    column_name ;

object_name ::= 
        ["table"] table_name 
      | "domain" domain_name 
      | "collation" collation_name 
      | "character" "set" char_set_name 
      | "translation" translation_name ;

octet_length_exp ::= 
      "octet_length" 
    "(" string_value_exp ")" ;

ordering_spec ::= 
      "asc" 
    | "desc" ;

order_by_clause ::= 
      "order" "by" sort_spec_list ;

outer_join_type ::= 
        "left" 
      | "right" 
      | "full" ;

overlaps_predicate ::= 
      row_value_constructor 
    "overlaps" row_value_constructor ;

pad_attribute ::= 
        no_tag "pad" 
      | "pad" space_tag ;

no_tag ::= "no" ;

space_tag ::= "space";


parameter_spec ::= 
      parameter_name [indicator_parameter] ;

pattern ::= 
    char_value_exp ;

position_exp ::= 
      "position" "(" char_value_exp 
      "in" char_value_exp ")" ;

predicate ::= 
        comp_predicate 
      | between_predicate 
      | in_predicate 
      | like_predicate 
      | null_predicate 
      | quantified_comp_predicate 
      | exists_predicate 
      | unique_predicate 
      | match_predicate 
      | overlaps_predicate ;

privileges ::= 
      all_privileges
      | action_list ;

all_privileges ::=
    "all" "privileges" ;

privilege_column_list ::= 
    column_name_list ;

qualified_join ::= 
      [natural_tag] [join_type] "join" 
      table_ref [join_spec] ;

natural_tag ::=
    "natural" ;

quantified_comp_predicate ::= 
      row_value_constructor comp_op 
    quantifier table_subquery ;

quantifier ::= 
      "all" 
    | "some" 
    | "any" ;

query_spec ::= 
      "select" [set_quantifier] 
    select_list table_exp ;

refd_table_and_columns ::= 
      table_name ["(" ref_column_list ")"] ;

referencing_columns ::= 
      ref_column_list ;

refs_spec ::= 
      "references" [pendant_tag] 
    refd_table_and_columns
      [match_tag match_type] 
      [ref_triggered_action] ;

match_tag ::= 
    "match" ;

pendant_tag ::=
    "PENDANT" ;

ref_action ::= 
        "cascade" 
      | "set" "null" 
      | "set" "default" 
      | "no" "action" ;

ref_column_list ::= 
    column_name_list ;

ref_constraint_def ::= 
      "foreign" "key" 
      "(" referencing_columns ")" 
      refs_spec ;

ref_triggered_action ::= 
        update_rule [delete_rule]
      | delete_rule [update_rule] ;

result ::= 
        result_exp 
      | null_tag ;

result_exp ::= 
    value_exp ;

revoke_stmt ::= 
      "revoke" [grant_option_for]
      privileges 
      "on" object_name 
      "from" { grantee, "," } 
    drop_behavior ;

grant_option_for ::=
    "grant" "option" "for" ;

rollback_stmt ::= 
      "rollback" ["work"];

row_subquery ::= 
    subquery ;

row_value_constructor ::= 
        row_value_constructor_elem 
      | "(" row_value_const_list ")" 
      | row_subquery ;

row_value_constructor_elem ::= 
        value_exp 
      | null_tag 
      | default_spec ;

row_value_const_list ::= 
      { row_value_constructor_elem, "," } ;

scalar_subquery ::= 
    subquery ;

schema_authorization_ident ::= 
      authorization_ident ;

schema_def ::= 
      "create" "schema" schema_name_clause 
      [schema_char_set_spec] 
      [{ schema_element }] ;

schema_element ::= 
        domain_def 
      | table_def 
      | view_def 
      | grant_stmt 
      | assertion_def 
      | char_set_def 
      | collation_def 
      | translation_def ;

schema_name_clause ::= 
        qualified_name 
        ["authorization" schema_authorization_ident]
      | "authorization" schema_authorization_ident ;

searched_case ::= 
      "case" 
      { searched_when_clause } 
      [else_clause]
      "end" ;

searched_when_clause ::= 
    "when" search_condition "then" result ;

search_condition ::= 
    boolean_value_exp ;

boolean_value_exp ::= 
    { boolean_term, boolean_term_op } ;

boolean_term_op ::=
    "or" ;
      
boolean_term ::= 
    { boolean_factor, boolean_factor_op } ;

boolean_factor_op ::=
    "and" ;
      
boolean_factor ::= 
      [not_tag] boolean_test ;
      
boolean_test ::= 
      boolean_primary 
    ["is" [not_tag] truth_value] ;
     
boolean_primary ::= 
        predicate 
      | "(" search_condition ")" ;

truth_value ::= 
        "true" 
      | "false" 
      | "unknown" ;


select_list ::= 
        asterisk_tag
      | { select_sublist, "," } ;

asterisk_tag ::=
    "*" ;

select_sublist ::= 
        qualified_name "." asterisk_tag
      | derived_column 
    ;

set_catalog_stmt ::= 
      "set" "catalog" value_spec ;

set_clause ::= 
      object_column "=" update_source ;

set_clause_list ::= 
      {set_clause, ","} ;

set_column_default_clause ::= 
      "set" default_clause ;

set_connection_stmt ::= 
      "set" "connection" 
    connection_object ;

set_constraints_mode_stmt ::= 
      "set" "constraints" 
    constraint_name_list 
    (deferred_tag | immediate_tag) ;

deferred_tag ::=
    "deferred" ;

set_domain_default_clause ::= 
    "set" default_clause ;

set_fct_spec ::= 
      count_all_fct
      | general_set_fct ;

count_all_fct ::=
    "count" "(" "*" ")" ;


set_fct_type ::= 
        "avg" 
      | "max" 
      | "min" 
      | "sum" 
      | "count" ;

set_local_time_zone_stmt ::= 
      "set" "time" "zone" 
      set_time_zone_value ;

set_names_stmt ::= 
      "set" "names" value_spec ;

set_quantifier ::= 
    "distinct" | "all" ;

set_schema_stmt ::= 
      "set" "schema" value_spec ;

set_session_auth_ident_stmt ::= 
      "set" "session" "authorization" 
      value_spec ;

set_transaction_stmt ::= 
      "set" "transaction" 
      { transaction_mode, "," } ;

sign ::= 
    "+" | "-" ;

signed_integer ::= 
    [sign] unsigned_integer ;

simple_case ::= 
      "case" case_operand 
      { simple_when_clause } 
      [ else_clause ] 
      "end" ;

simple_table ::= 
        query_spec 
      | table_value_constructor 
      | explicit_table ;

simple_value_spec ::= 
        parameter_name 
      | embdd_variable_name 
      | lit ;

simple_when_clause ::= 
    "when" when_operand "then" result ;

sort_key ::= 
        column_ref 
      | unsigned_integer ;

sort_spec ::= 
      sort_key 
    [collate_clause] 
    [ordering_spec] ;

sort_spec_list ::= 
      { sort_spec, "," } ;

sql_language_id ::= 
      sql_language_id_start 
      [{ "_" | sql_language_id_part }] ;

sql_language_id_part ::= 
        simple_latin_letter 
      | digit ;

sql_language_id_start ::= 
    simple_latin_letter ;


sql_server_name ::= 
    simple_value_spec ;

start_position ::= 
    num_value_exp ;

string_length ::= 
    num_value_exp ;

string_value_fct ::= 
        char_value_fct 
      | bit_value_fct ;

subquery ::= 
    "(" query_exp ")" ;

table_constraint ::= 
        unique_constraint_def 
      | ref_constraint_def 
      | check_constraint_def ;

table_constraint_def ::= 
      [constraint_name_def] 
      table_constraint [constraint_attributes] ;

table_def ::= 
      "create" [table_scope] 
    table_type table_name 
      table_element_list 
      [on_commit_clause] ;

on_commit_clause ::=
    "on" "commit" on_comment_action "rows" ;

on_comment_action ::=
      "delete" 
    | "preserve" ;

table_scope ::=
    global_or_local "TEMPORARY" ;

global_or_local ::=
      "GLOBAL"
    | "LOCAL"
    ;
    
table_type ::= 
    "TABLE";
    
table_element ::= 
        table_constraint_def
      | column_def 
      ;

table_element_list ::= 
      "(" { table_element, "," } ")" ;

table_exp ::= 
      from_clause 
      [where_clause] 
      [group_by_clause] 
      [having_clause] ;

table_ref ::= 
    table_ref_simple 
    [{cross_join | qualified_join}]
    ;

table_ref_simple ::= 
        (table_name | derived_table)
        [["as"] correlation_name 
          ["(" derived_column_list ")"]] 
    ;
      
table_subquery ::= 
    subquery ;

table_value_constructor ::= 
      "values" table_value_const_list ;

table_value_const_list ::= 
      { row_value_constructor, "," } ;

temporary_table_decl ::= 
      "declare" "local" "temporary" "table" 
      qualified_name 
      table_element_list 
      [on_comment_action] ;

term ::= 
    {factor, "*"|"/"} ;

transaction_access_mode ::= 
        "read" "only" 
      | "read" "write" ;

transaction_mode ::= 
        isolation_level 
      | transaction_access_mode 
      | diag_size ;


trim_char ::= 
    char_value_exp ;

trim_fct ::= 
      "trim" "(" trim_operands ")" ;

trim_operands ::= 
      [[trim_spec] [trim_char] "from"] 
    trim_source ;

trim_source ::= 
    char_value_exp ;

trim_spec ::= 
        "leading" 
      | "trailing" 
      | "both" ;

unique_column_list ::= 
    column_name_list ;

unique_constraint_def ::=
      unique_spec ["(" unique_column_list ")"]
    | unique_value
    ;

unique_value ::=
    "UNIQUE" "(" "VALUE" ")" ;

unique_predicate ::= 
    "unique" table_subquery ;

unique_spec ::= 
      "unique" 
    | "primary" "key" ;

unsigned_value_spec ::= 
        unsigned_lit 
      | general_value_spec ;

update_rule ::= 
    "on" "update" ref_action ;

update_source ::= 
        value_exp 
      | null_tag 
      | default_tag ;

update_stmt_searched ::= 
      "update" table_name 
      "set" set_clause_list 
      ["where" search_condition] ;

user_name ::= 
    simple_value_spec ;

value_exp ::= 
        num_value_exp 
      | string_value_exp 
      | datetime_value_exp 
      | interval_value_exp ;

value_exp_primary ::= 
        unsigned_value_spec 
      | set_fct_spec 
      | column_ref 
      | scalar_subquery 
      | case_exp 
      | "(" in_value_list ")" 
      | cast_spec ;

value_spec ::= 
        lit 
      | general_value_spec ;

variable_spec ::= 
      embdd_variable_name [indicator_variable] ;

view_column_list ::= 
    column_name_list ;

view_def ::= 
      "create" "view" table_name 
    ["(" view_column_list ")"] 
      "as" query_exp 
      [with_check_option] ;

with_check_option ::=
    "with" [levels_clause] "check" "option" ;

when_operand ::= 
    value_exp ;

where_clause ::= 
    "where" search_condition ;


// ---------------------------------------------------
//     char set
// ---------------------------------------------------

char_set_def ::= 
      "create" "character" "set" char_set_name 
      ["as"] 
      char_set_source 
      [collate_clause | limited_collation_def] ;
      
char_set_name ::= 
    [qualified_name "."]
      sql_language_id ;

char_set_source ::= 
      "get" existing_char_set_name ;

char_set_spec ::= 
        std_char_rep_name 
      | implt_def_char_rep_name 
      | user_def_char_rep_name 
      | std_univ_char_form_name 
      | implt_def_univ_char_name 
      ;

drop_char_set_stmt ::= 
      "drop" "character" "set" 
    char_set_name ;

existing_char_set_name ::= 
        std_char_rep_name 
      | implt_def_char_rep_name 
      | schema_char_set_name ;

implt_def_char_rep_name ::= 
      char_set_name ;

implt_def_univ_char_name ::= 
      char_set_name ;

schema_char_set_name ::= 
    char_set_name ;

schema_char_set_spec ::= 
      "default" "character" 
      "set" char_set_spec ;

source_char_set_spec ::= 
    char_set_spec ;

std_char_rep_name ::= 
    char_set_name ;

std_univ_char_form_name ::= 
      char_set_name ;

target_char_set_spec ::= 
    char_set_spec ;

user_def_char_rep_name ::= 
    char_set_name ;


// ---------------------------------------------------
//     collation
// ---------------------------------------------------

collate_clause ::= 
    "collate" collation_name ;

collating_sequence_def ::= 
        external_collation 
      | schema_collation_name 
      | desc_collation_name 
      | default_tag ;

desc_collation_name ::=
    "desc" "(" collation_name ")" ;

collation_def ::= 
      "create" "collation" collation_name 
    "for" char_set_spec 
      "from" collation_source 
      [pad_attribute]
    ;

collation_name ::= 
    qualified_name ;

collation_source ::= 
        collating_sequence_def 
      | translation_collation ;

drop_collation_stmt ::= 
      "drop" "collation" collation_name ;

external_collation ::= 
      "external" 
    "(" "'" external_collation_name "'" ")" ;

external_collation_name ::= 
        std_collation_name 
      | implt_def_collation_name ;

implt_def_collation_name ::= 
    collation_name ;

limited_collation_def ::= 
      "collation" "from" collation_source ;

schema_collation_name ::= 
    collation_name ;

std_collation_name ::= 
    collation_name ;

// translation

translation_collation ::= 
      "translation" translation_name 
      ["then" "collation" collation_name] ;

translation_def ::= 
      "create" "translation" translation_name 
      "for" source_char_set_spec 
      "to" target_char_set_spec 
      "from" translation_source ;

translation_name ::= 
    qualified_name ;

translation_source ::= 
      translation_spec ;

translation_spec ::= 
        external_translation 
      | identity_tag
      | schema_translation_name ;

identity_tag ::=
    "identity" ;

drop_translation_stmt ::= 
      "drop" "translation" translation_name ;

external_translation ::= 
      "external" 
     "(" "'" external_translation_name "'" ")" ;

external_translation_name ::= 
        std_translation_name 
      | implt_def_translation_name ;

implt_def_translation_name ::= 
    translation_name ;

schema_translation_name ::= 
    translation_name ;

std_translation_name ::= 
    translation_name ;


datetime_primary ::= 
        value_exp_primary 
      | datetime_value_fct ;

datetime_factor ::= 
      datetime_primary [time_zone] ;

datetime_term ::= 
      datetime_factor ;

datetime_value_exp ::= 
      (datetime_term | 
      interval_value_exp "+" datetime_term)
    [{term_op interval_term}]
    ;

interval_primary ::= 
      value_exp_primary [interval_qualifier] ;

interval_factor ::= 
      [sign] interval_primary ;

interval_term ::= 
      [term asterisk_tag] 
      interval_factor 
      [{factor_op factor}]
      ;

factor_op ::=
    "*" | "/" ;

interval_frac_seconds_prec ::= 
    unsigned_integer ;

interval_leading_fieldprec ::= 
    unsigned_integer ;

interval_qualifier ::= 
        start_field "to" end_field 
      | single_datetime_field ;

interval_type ::= 
    "interval" interval_qualifier ;

interval_value_exp ::= 
      (interval_term 
       | "(" datetime_value_exp "-" 
        datetime_term ")" interval_qualifier)
       [{term_op interval_term }]
       ;

end_field ::= 
        non_second_datetime_field 
      | second_tag 
       ["(" interval_frac_seconds_prec ")"] ;

second_tag ::=
    "second" ;

start_field ::= 
      non_second_datetime_field 
      ["(" interval_leading_fieldprec ")"] ;

single_datetime_field ::= 
        non_second_datetime_field 
        ["(" interval_leading_fieldprec ")"] 
      | second_tag 
      [ "(" interval_leading_fieldprec 
          ["," interval_frac_seconds_prec ] ")"] ;

set_time_zone_value ::= 
        interval_value_exp 
      | local_tag ;

local_tag ::=
    "local" ;

time_string ::= 
      "'" time_value [time_zone_interval] "'" ;

time_value ::= 
      hours_value ":" 
      minutes_value ":" 
      seconds_value ;

time_zone ::= 
      "at" time_zone_specifier ;

time_zone_field ::= 
        "timezone_hour" 
      | "timezone_minute" ;

time_zone_specifier ::= 
        "local" 
      | "time" "zone" interval_value_exp ;

// ======================================================
//
//                DATA TYPES
//
// ======================================================

unsigned_integer 
      ::= numeric;

precision 
    ::= unsigned_integer ;

data_length 
    ::= unsigned_integer ;

scale 
      ::= unsigned_integer ;
      
      
approximate_num_type ::= 
        "float" ["(" precision ")"] 
      | "real" 
      | "double" "precision" 
      ;
      
bit_string_type ::= 
      "bit" [[varying_tag] "(" data_length ")"] ;

varying_tag ::=
    "varying" ;
      
char_string_type ::= 
        ("character" | "char")  
        [[varying_tag] "(" data_length ")"]
      | "varchar" "(" data_length ")" ;
      
exact_num_type ::= 
      ( "numeric"
        | "decimal"
        | "dec" )    ["(" precision [ "," scale ] ")"] 
      | "integer" 
      | "int" 
      | "smallint" 
    ;

national_char_string_type ::= 
      ("national" "character" 
       | "national" "char" | "nchar" ) 
      [[varying_tag] "(" data_length ")"] ;

num_type ::= 
        exact_num_type 
      | approximate_num_type ;


// ---------------------------------------------------
//     date and time
// ---------------------------------------------------

datetime_type ::= 
      date_type
    | time_type
    | timestamp_type 
    ;

date_type 
    ::= "date" ;

time_type ::=
    "time" ["(" time_precision ")"] 
    [with_time_zone] ;

timestamp_type ::=
    "timestamp" ["(" timestamp_precision ")"] 
    [with_time_zone] ;

with_time_zone ::=
    "with" "time" "zone" ;

timestamp_precision ::= 
    time_frac_seconds_prec ;

time_frac_seconds_prec ::= 
    unsigned_integer ;

time_precision ::= 
    time_frac_seconds_prec ;

currenttimestamp_value_fct ::= 
      "current_timestamp"
     ["(" timestamp_precision ")"];

current_date_value_fct ::= 
    "current_date" ;

current_time_value_fct ::= 
      "current_time" 
    ["(" time_precision ")"] ;

datetime_field ::= 
        non_second_datetime_field 
      | second_tag ;

datetime_value ::= 
    unsigned_integer ;

datetime_value_fct ::= 
        current_date_value_fct 
      | current_time_value_fct 
      | currenttimestamp_value_fct ;

date_string ::= 
      "'" date_value "'" ;

date_value ::= 
      years_value "-" months_value 
      "-" days_value ;

days_value ::= 
    datetime_value ;

hours_value ::= 
    datetime_value ;

// intervals

minutes_value ::= 
    datetime_value ;

months_value ::= 
    datetime_value ;

non_second_datetime_field ::= 
        "year" 
      | "month" 
      | "day" 
      | "hour" 
      | "minute" ;

years_value ::= 
    datetime_value ;


seconds_integer_value ::= 
    unsigned_integer ;

seconds_fraction ::= 
    unsigned_integer ;

seconds_value ::= 
      seconds_integer_value 
    ["." [seconds_fraction]] ;


// ---------------------------------------------------
//     bits
// ---------------------------------------------------

bit_length_exp ::= 
      "bit_length" "(" string_value_exp ")" ;
      
bit_primary ::= 
        value_exp_primary 
      | string_value_fct ;
      
bit_substring_fct ::= 
      "substring" "(" bit_value_exp 
     "from" start_position 
      ["for" string_length] ")" ;
      
bit_value_exp ::= 
    {bit_factor, bit_concat_op};

bit_concat_op ::= 
    "||";
      
bit_factor ::= 
    bit_primary ;

bit_value_fct ::= 
      bit_substring_fct ;

/*      
direct_implt_def_stmt 
      ::= temp_syntax_rule;
*/

string_value_exp 
      ::= 
      char_value_exp 
      | bit_value_exp ;

// ===================================================
//
//                TOKENIZER
//
// ===================================================

space_symbol <TERMINAL,HIDDEN> ::= 
        { ("\32" | "\r" |"\n"|"\t")
          | "--" *("\n")
             |  "/*" *("*/") "*/" ,0 }
             ;

simple_latin_letter ::= 
    '[a-zA-Z]';

digit ::= 
    '[0-9]' ;

// literals

unsigned_lit ::= 
        unsigned_num_lit 
      | general_lit ;

unsigned_num_lit ::= 
      ( unsigned_integer 
       [ "." [ unsigned_integer ] ] 
        | "." unsigned_integer) 
      ["e" exponent]
      ;
     
exponent ::= 
    signed_integer ;

general_lit ::= 
        char_string_lit 
      | national_char_string_lit 
      | bit_string_lit 
      | hex_string_lit 
      | datetime_lit 
      | interval_lit ;

char_string_lit ::= 
      ["_" char_set_spec] 
      {s_quotedstring} ;
      
national_char_string_lit ::= 
      "n" {s_quotedstring} ;

bit_string_lit<TERMINAL> ::= 
      "b" {"'" '[01]*' "'"} ;

hex_string_lit ::= 
      "x" {"'" '[a-fA-F0-9]+' "'"} ;

datetime_lit ::= 
        date_lit 
      | time_lit 
      | timestamp_lit ;
      
date_lit ::= 
      "date" date_string ;

interval_lit ::= 
      "interval" [sign] 
    interval_string interval_qualifier ;

s_quotedstring<TERMINAL,SPACE=""> ::=
    '\'[^']*\'';

lit ::= 
        signed_num_lit 
    | general_lit ;

signed_num_lit ::= 
      [sign] unsigned_num_lit ;

timestamp_lit ::= 
      "timestamp" timestamp_string ;

time_lit ::= 
      "time" time_string ;

id ::= 
    ["_" char_set_spec] actual_id ;

actual_id ::= 
      identifier 
    | delimited_id ;

identifier<TERMINAL> ::= 
    '[a-zA-Z_][a-zA-Z0-9_#]*' 
    (? #VALUE !::= reserved_word; );

delimited_id ::= 
      "\"" [{'[^"]' | "\"\""}] "\"" ;



// ====================================================

authorization_ident ::= id ;

time_zone_interval ::= 
    sign hours_value ":" minutes_value ;

timestamp_string ::=
    "'" date_value " " time_value
        [ time_zone_interval ] "'" ;

interval_string ::=
    "'" ( year_month_literal | day_time_literal ) "'" ; 
    
year_month_literal ::=
      years_value
    | [ years_value "-" ] months_value ;

day_time_literal ::=
      day_time_interval
    | time_interval ;
    
day_time_interval ::=
    days_value
      [ " " hours_value [ ":" minutes_value
        [ ":" seconds_value ] ] ] ;

time_interval ::=
      hours_value 
      [ ":" minutes_value [ ":" seconds_value ] ]
    | minutes_value [ ":" seconds_value ]
    | seconds_value ;
    
    
derived_table ::= 
    table_subquery ;

// "virtual" symbols for embedded language support

embdd_variable_name ::= 
      ":" host_id ;

host_id ::= identifier;

// ===================================================

column_name ::= 
    id ;

correlation_name ::= 
    id ;

parameter_name ::= 
    ":" id ;

column_ref ::= 
      qualified_name ;

table_name ::= 
      qualified_name ;

qualified_name ::= 
      {id, "."} ;


reserved_word ::=
    "ABSOLUTE" | "ACTION" | "ADD" | "ALL" | "ALLOCATE" 
  | "ALTER" | "AND" | "ANY" | "ARE" | "AS" | "ASC" 
  | "ASSERTION" | "AT" | "AUTHORIZATION" | "AVG" 
  | "BEGIN" | "BETWEEN" | "BIT" | "BIT_LENGTH" | "BOTH" 
  | "BY" | "CASCADE" | "CASCADED" | "CASE" | "CAST" 
  | "CATALOG" | "CHAR" | "CHARACTER" | "CHAR_LENGTH" 
  | "CHARACTER_LENGTH" | "CHECK" | "CLOSE" | "COALESCE" 
  | "COLLATE" | "COLLATION" | "COLUMN" | "COMMIT" 
  | "CONNECT" | "CONNECTION" | "CONSTRAINT" 
  | "CONSTRAINTS" | "CONTINUE" | "CONVERT" 
  | "CORRESPONDING" | "COUNT" | "CREATE" | "CROSS" 
  | "CURRENT" | "CURRENT_DATE" | "CURRENT_TIME" 
  | "CURRENT_TIMESTAMP" | "CURRENT_USER" | "CURSOR" 
  | "DATE" | "DAY" | "DEALLOCATE" | "DEC" | "DECIMAL" 
  | "DECLARE" | "DEFAULT" | "DEFERRABLE" | "DEFERRED" 
  | "DELETE" | "DESC" | "DESCRIBE" | "DESCRIPTOR" 
  | "DIAGNOSTICS" | "DISCONNECT" | "DISTINCT" | "DOMAIN" 
  | "DOUBLE" | "DROP" | "ELSE" | "END" | "END-EXEC" 
  | "ESCAPE" | "EXCEPT" | "EXCEPTION" | "EXEC" | "EXECUTE" 
  | "EXISTS" | "EXTERNAL" | "EXTRACT" | "FALSE" | "FETCH" 
  | "FIRST" | "FLOAT" | "FOR" | "FOREIGN" | "FOUND" 
  | "FROM" | "FULL" | "GET" | "GLOBAL" | "GO" | "GOTO" 
  | "GRANT" | "GROUP" | "HAVING" | "HOUR" | "IDENTITY" 
  | "IMMEDIATE" | "IN" | "INDICATOR" | "INITIALLY" 
  | "INNER" | "INPUT" | "INSENSITIVE" | "INSERT" | "INT" 
  | "INTEGER" | "INTERSECT" | "INTERVAL" | "INTO" | "IS" 
  | "ISOLATION" | "JOIN" | "KEY" | "LANGUAGE" | "LAST" 
  | "LEADING" | "LEFT" | "LEVEL" | "LIKE" | "LOCAL" 
  | "LOWER" | "MATCH" | "MAX" | "MIN" | "MINUTE" 
  | "MODULE" | "MONTH" | "NAMES" | "NATIONAL" | "NATURAL" 
  | "NCHAR" | "NEXT" | "NO" | "NOT" | "NULL" | "NULLIF" 
  | "NUMERIC" | "OCTET_LENGTH" | "OF" | "ON" | "ONLY" 
  | "OPEN" | "OPTION" | "OR" | "ORDER" | "OUTER" 
  | "OUTPUT" | "OVERLAPS" | "PAD" | "PARTIAL" 
  | "POSITION" | "PRECISION" | "PREPARE" | "PRESERVE" 
  | "PRIMARY" | "PRIOR" | "PRIVILEGES" | "PROCEDURE" 
  | "PUBLIC" | "READ" | "REAL" | "REFERENCES" 
  | "RELATIVE" | "RESTRICT" | "REVOKE" | "RIGHT"
  | "ROLLBACK" | "ROWS" | "SCHEMA" | "SCROLL" 
  | "SECOND" | "SECTION" | "SELECT" | "SESSION" 
  | "SESSION_USER" | "SET" | "SIZE" | "SMALLINT" | "SOME" 
  | "SPACE" | "SQL" | "SQLCODE" | "SQLERROR" | "SQLSTATE" 
  | "SUBSTRING" | "SUM" | "SYSTEM_USER" | "TABLE" 
  | "TEMPORARY" | "THEN" | "TIME" | "TIMESTAMP" 
  | "TIMEZONE_HOUR" | "TIMEZONE_MINUTE" | "TO" 
  | "TRAILING" | "TRANSACTION" | "TRANSLATE" 
  | "TRANSLATION" | "TRIM" | "TRUE" | "UNION" | "UNIQUE" 
  | "UNKNOWN" | "UPDATE" | "UPPER" | "USAGE" | "USER" 
  | "USING" | "VALUE" | "VALUES" | "VARCHAR" | "VARYING" 
  | "VIEW" | "WHEN" | "WHENEVER" | "WHERE" | "WITH" 
  | "WORK" | "WRITE" | "YEAR" | "ZONE" 
  ;

};    // grammar SQL2



For comments or questions about this site, please contact
webmaster@programmar.com
Copyright © 1998-2003 NorKen Technologies, Inc. All rights reserved.