Hi,
I have written a following stored procedure
The task is to update certain columns in a table with certain values in batches.. Is the SP looking OK (syntaxwise).
Please provide the inputs.
I have written a following stored procedure
Code:
CREATE OR REPLACE PROCEDURE SP_TEST
DECLARE
tablename VARCHAR2(50) ;
id NUMBER ;
column1 NUMBER ;
column2 VARCHAR2(50) ;
column3 DATE ;
strencrypt VARCHAR2(50);
dateencrypt DATE;
numencrypt NUMBER ;
loop_cnt NUMBER;
batchCount NUMBER;
minrowid NUMBER;
maxrowid NUMBER;
startid NUMBER;
endid NUMBER;
query_str VARCHAR2(1000);
BEGIN
tablename := 'table1';
id := 'ID';
column1 := 'EMPID';
column2 := 'FIRSTNAME';
column3 := 'LAST_NAME';
strencrypt := 'test';
dateencrypt := '01-JAN-1881';
SELECT MIN(id), MAX(id) into minrowid, maxrowid FROM tablename;
startid := minrowid;
endid := 0;
WHILE endid <= maxrowid
LOOP
IF loop_cnt > 1 THEN
startid := startid + batchCount + 1;
END IF
endid := startid + batchCount;
/* form a query */
query_str := 'UPDATE ' || tablename || ' SET ' || column1 || '=' || strencrypt || ','
|| column2 || ' = ' || strencrypt || ','
column3 || '=' || to_date(dateencrypt, 'dd-mmm-yyyy') ||
' WHERE ' || id || ' between ' || startid || ' and ' || endid;
/* execute query */
EXECUTE IMMEDIATE query_str;
loop_cnt := loop_cnt + 1;
END LOOP;
END SP_TEST ;
Please provide the inputs.