I have the below procedure with no error message:
create or replace procedure insert_or_upd_movement_baselines_planned_weight_proc(
p_id IN VARCHAR2,
p_date IN DATE,
p_planned_col_name IN VARCHAR2,
p_planned_value IN NUMBER
) as
begin
declare
plsql_block NVARCHAR2(8000);
begin
plsql_block := 'merge into MOVEMENT_BASELINES mb using dual on (mb.MOVEMENT_ID = ' || p_id || ' and mb.MOVEMENT_DATE = ' || p_date || ')
when not matched then insert (mb.MOVEMENT_ID, mb.MOVEMENT_DATE, mb.' || p_planned_col_name || ')
values ( ' || p_id || ', ' || p_date || ', ' || p_planned_value || ')
when matched then update set '
|| p_planned_col_name || ' = ' || p_planned_value || ';';
execute immediate plsql_block;
end;
end insert_or_upd_movement_baselines_planned_weight_proc;
When I try to execute it with values for the input parameters, I am getting a compiler error:
Connecting to the database localDB.
ORA-00933: SQL command not properly ended
ORA-06512: at "RTT.INSERT_OR_UPD_MOVEMENT_BASELINES_PLANNED_WEIGHT_PROC", line 17
ORA-06512: at line 12
Process exited.
I am new to Oracle and would like to print the dynamic sql to check what is wrong but the print statement does not seem to work. I am guessing the issue is with the dynamic column name in the insert statement - any idea what is wrong? Thanks