I want to execute the following command through a cursor where I have column name and column values in a different table.
However the script fails with following error message.
ORA-00933: SQL command not properly ended
execute immediate 'UPDATE EMP_DETAILS_T SET ' || EMP_REC.COLUMN_NAME || ' = ' || '''' || EMP_REC.VALUE ||''' ' || ' where employee_id = ' || ''''|| EMP_REC.EMPLOYEE_ID || ''' ' ;
entire command is as follow.
DECLARE
CURSOR CR_EMP_ATT IS
SELECT COLUMN_NAME,
VALUE,
EMPLOYEE_ID
FROM UPDATE_DATA_T
WHERE EMPLOYEE_ID = P_EMP_ID;
BEGIN
FOR CR_EMP IN CR_EMP_ATT LOOP
BEGIN
EXECUTE IMMEDIATE 'Update EMP_DETAILS_T set ' || CR_EMP.COLUMN_NAME || ' = ' ||''''||CR_EMP.VALUE||''''|| ' where employee_id = ' ||''''|| P_EMP_ID||'''';
DBMS_OUTPUT.PUT_LINE('temp table updated');
END;
END LOOP;
END;
I have placed this query in a procedure to run when needed by employee.
dbms_outputcall before theexecute immediateto show the command that's actually going to be executed, to see which values it fails on? Are any of yourcolumn_namevalues reserved words, perhaps? - Alex Poole