Various SO answers such as this one and this one imply that you can't use your current approach.
Marin's answer (which I've upvoted) shows how to batch the individual INSERT
statements.
You can also do this in a single query using the INSERT ALL
statement. As with Marin's answer, you'll need to alter your SQL:
INSERT ALL
INTO temp values(TO_DATE ('12-08-15', 'DD/MM/RRRR') - 1, 'rahul', 'START', '12-08-15 06:32:33.577676 PM')
INTO temp values(TO_DATE ('12-08-15', 'DD/MM/RRRR') - 1, 'abhishek', 'START', '12-08-15 06:32:33.577676 PM')
SELECT * FROM DUAL;";
Also, I'd avoid the RRRR
format string unless you happen to be working with a non-Y2K compliant application or it's your lifelong dream to create one. Taking it a step further, you don't even need TO_DATE
here because Oracle supports the ANSI date literal syntax:
INSERT ALL
INTO temp values(DATE '2015-12-08' - 1, 'rahul', 'START', '12-08-15 06:32:33.577676 PM')
INTO temp values(DATE '2015-12-08' - 1, 'abhishek', 'START', '12-08-15 06:32:33.577676 PM')
SELECT * FROM DUAL;
Addendum
In case the last column being inserted is a timestamp type, I'd recommend using the ANSI timestamp literal. If you're relying on an implicit conversion using your default display format, that's a dangerous practice because someone can break your code by simply changing the default timestamp display format.
The answer updated with ANSI timestamp values goes like this (for the ANSI values you need to use a 24-hour clock):
INSERT ALL
INTO temp values(DATE '2015-12-08' - 1, 'rahul', 'START', TIMESTAMP '2015-12-08 18:32:33.577676')
INTO temp values(DATE '2015-12-08' - 1, 'abhishek', 'START', TIMESTAMP '2015-12-08 18:32:33.577676')
SELECT * FROM DUAL;
Understand that when you specify date and timestamp values like this your Oracle code works every time, regardless of the current session or database date/timestamp format settings.
Of course, since you're doing this through Java, an even better approach would be to use prepared statements. They're also immune to the date/timestamp format settings, plus there's the even more important benefit of defending against SQL injection.