Sometimes I want to generate INSERT statements from the contents of a database table.
With SQLite, I can do:
SELECT 'INSERT INTO foo (col1, col2) VALUES (' || quote(col1) || ',' || quote(col2) || ');'
FROM bar;
With Oracle, I have to do :
SELECT 'INSERT INTO foo (col1, col2) VALUES (''' || replace(col1, '''', '''''') || ''',''' || replace(col2, '''', '''''') || ''');'
FROM bar;
And furthermore, it won’t work with NULL values.
Is there a better way?
If you’re on 11g, I’d use DBMS_ASSERT.ENQUOTE_LITERAL instead of rolling your own.