Sql – insert maximum selected value as new record oracle

oracleoracle10gsql

i'm using oracle DB . and i'm trying to select max number from table and then increment it by one then re-insert it as new record for example:
insert into table1(id,name) values (select max(id) from table1 + 1,'name2');

but it gave me missing expression error.

thanks in advance.

Best Answer

INSERT INTO table1( id, name )
  SELECT max(id) + 1, 'name2'
    FROM table1

will be valid syntax. This method of generating id values, is a very poor approach. It does not work in a multi-user environment since many different sessions may get the same id value. It is also much less efficient than using a sequence.