动态SQL和动态游标的例子

v_sql := 'SELECT MAX(aad215) FROM ad20, ad22 WHERE ad22.aad032 IN (' || v_old_aad032list ||
') AND ad20.oae200 = ad22.oae200';
EXECUTE IMMEDIATE v_sql
INTO ad20data.aad215;

v_sql := 'SELECT * FROM ad21 WHERE ad21.oae200 IN (SELECT distinct oae200 FROM ad22 WHERE ad22.aad032 IN (' ||
v_old_aad032list || '))';

OPEN c1 FOR v_sql;
LOOP
FETCH c1
INTO ad21data;
EXIT WHEN c1%NOTFOUND;
ad21data.oae200 := n_oae200;
SELECT seq_a_rowid.NEXTVAL INTO ad21data.oae001 FROM dual;
INSERT INTO ad21 VALUES ad21data;
END LOOP;
CLOSE c1;

你可能感兴趣的:(sql)