I would like to insert contents of a dataframe into an existing table in an oracle database.
sqlSave(conn, df[1:3,c(which(names(df) == "x"), which(names(df) == "y"), which(names(df) == "z")], tablename = "A_X", append = TRUE)
I get the error Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in »data«
because the chosen columns and those of the Oracle table are not matching.
The oracle table has more columns than the data frame, so the non matching columns should be filled with NULL. How can I implement this in R? I would like to include the contents of the df in the SQL code at the bottom as follows:
INSERT INTO A_X
VALUES (df[1:3,c(which(names(df) == "x"), which(names(df) == "y"), which(names(df) == "z")], AUTO_ID, NULL, NULL);
In Oracle SQL this would be possible with the following code:
INSERT INTO A_X
VALUES (300, 'text', 'text', AUTO_ID, NULL, NULL);
The second problem is to generate the ID AUTO_ID
automatically. I have version Oracle DB 11.2.0.3 and it's not possible to update to version 12c currently.