skip to main | skip to sidebar

Search Oracle Blogs

List of Blogs maintained by Paweł Barut.


Wednesday, September 05, 2007

Alternative Syntax for Insert

Alternative Syntax for Insert

Let me show my idea of SQL improvement, that I would like to see. Traditional insert works like that:
insert into table_a
(column_1, column_2, column_3, column_4)
values
(value_1, value_2, value_3, value_4);
What I would like to have is something like that:
insert into table_a
set column_1 = value_1
,column_2 = value_2
,column_3 = value_3
,column_4 = value_4;
With this syntax code would be easier to maintain. Especially, when you have to add or delete, or find error in insert to table with many columns. Biggest advantage of this would be close relationship between column name and value that will be set for that column. In INSERT that we know it column name and value are quite far from each other, so even for table with 10 columns it might be hard to find corresponding entries.
In PL/SQL there is an workaround to get similar solution:
declare
v_row table_a%rowtype;
begin
v_row.column_1 := value_1;
v_row.column_2 := value_2;
v_row.column_3 := value_3;
v_row.column_4 := value_4;
insert into table_a values v_row;
end;
But it's PL/SQL not pure SQL. I really would like to have this syntax in next Oracle release...

Cheers, Paweł

7 comments:

SydOracle said...

I like it. I'd even be happy with something like
INSERT INTO table_a
(col_a) VALUES (val_a)
(col_b) VALUES (val_b)
I won't hold my breath though.

06 September, 2007 01:11
Patrick Wolf said...

Paweł, that would be a very good enhancement! Especially if you have a lot of columns it's sometimes really hard to identify the correlating value in the VALUES section. Your proposed SET syntax would make it quite clear and it would be similar to UPDATE.

Patrick

06 September, 2007 08:35
Paweł Barut said...

Good to know that my idea is reasonable for You and that I'm not the only one who see it useful.

06 September, 2007 18:30
Unknown said...

I like it too Pawel. But i believe this has not been introduced since it might affect the uniformity in the way insert works. For example, when we want to insert based on data from another table we would have to change the syntax similar to the current one since the set syntax would not make sense there.

Venkat

18 September, 2007 14:22
Paweł Barut said...

Venkat,
I agree that current syntax is better for inserting many rows by single statement. My proposition is additional syntax for inserting just single row. It should be only considered as alternative to insert into .. values .

Regards, Paweł

18 September, 2007 18:46
Anonymous said...

Just like in MySQL in other words... ;)

05 October, 2007 10:17
Paweł Barut said...

T Rex,
Thanks for sharing this info. I do not use MySQL and I didn't know that any DB has it already.

05 October, 2007 12:06

Post a Comment

Subscribe to: Post Comments (Atom)
 

AltStyle によって変換されたページ (->オリジナル) /