Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Nice try, but according to the Oracle 10g Documentation, the syntax for CREATE INDEX and ALTER TABLE ADD CONSTRAINT are not interchangeable in this regard, which is why you got that syntax error:</p> <pre><code>CREATE INDEX ::= CREATE [ UNIQUE | BITMAP ] INDEX [ schema. ]index ON { cluster_index_clause | table_index_clause | bitmap_join_index_clause } ; table_index_clause ::= [ schema. ]table [ t_alias ] (index_expr [ ASC | DESC ] [, index_expr [ ASC | DESC ] ]...) [ index_properties ] index_expr ::= { column | column_expression } </code></pre> <p>Therefore CREATE INDEX allows column_expression, which is basically a "function-based index".</p> <p>On the other hand:</p> <pre><code>ALTER TABLE ::= ALTER TABLE [ schema. ]table [ alter_table_properties | column_clauses | constraint_clauses | alter_table_partitioning | alter_external_table_clauses | move_table_clause ] [ enable_disable_clause | { ENABLE | DISABLE } { TABLE LOCK | ALL TRIGGERS } [ enable_disable_clause | { ENABLE | DISABLE } { TABLE LOCK | ALL TRIGGERS } ]... ] ; constraint_clauses ::= { ADD { out_of_line_constraint [ out_of_line_constraint ]... | out_of_line_REF_constraint } | MODIFY { CONSTRAINT constraint | PRIMARY KEY | UNIQUE (column [, column ]...) } constraint_state | RENAME CONSTRAINT old_name TO new_name | drop_constraint_clause } out_of_line_constraint ::= [ CONSTRAINT constraint_name ] { UNIQUE (column [, column ]...) | PRIMARY KEY (column [, column ]...) | FOREIGN KEY (column [, column ]...) references_clause | CHECK (condition) } [ constraint_state ] </code></pre> <p>Therefore a UNIQUE constraint definition may only be column names, and cannot be column expressions.</p> <p>You can do this in 11g using virtual columns, in 10g and earlier most people tend to create derived columns (along with the burden of keeping them up-to-date programmatically).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload