Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Add support for alternative INSERT .. SET syntax

Lukas EderNov 14 2017 — edited Nov 14 2017

One of the cool little MySQL features is its non-standard INSERT .. SET syntax for single row inserts:

INSERT INTO my_table

SET col1 = value1,

    col2 = value2,

    col3 = value3,

    ...

    colN = valueN

This syntax is much more readable for larger tables, where the alternative using the standard VALUES clause is hard to visually format:

INSERT INTO my_table (col1,   col2,   col3,   ..., colN)

VALUES               (value1, value2, value3, ..., valueN)

If the whole set of column names / values aren't kept on a single line, it's pretty much impossible to match the pairs against each other to be sure the order is kept in place. If they're kept on a single line, well that line can easily span 1000s of characters, in the presence of strings.

There's a workaround using PL/SQL RECORD types, e.g.

DECLARE

  r my_table%ROWTYPE;

BEGIN

  r.col1 = value1;

  r.col2 = value2;

  r.col3 = value3;

  ...

  r.colN = valueN;

  INSERT INTO my_table VALUES r;

END;

But that only works with PL/SQL, and it always inserts all the columns (bypassing DEFAULT expressions), not just the ones I want to be inserted explicitly.

Besides, the INSERT .. SET syntax, being equivalent to the UPDATE .. SET syntax allows for easily switching between INSERT / UPDATE statements.

If this were adopted, then the MERGE statement would need to be adapted as well.

Comments
Post Details
Added on Nov 14 2017
5 comments
696 views