BRabbit27
BRabbit27

Reputation: 6623

Error binding variable in dynamic PLSQL

My sqlQuery is this:

sqlQuery := 'SELECT sa.nombre_archivo, sha.registrosok, sha.registroserroneos,'||
            ' sha.registrosinconsistentes,'||
            ' (sha.registrosok+sha.registroserroneos+sha.registrosinconsistentes),'||
            ' sha.fechaprocesamiento'||
              ' FROM src_historialarchivo sha, src_archivo sa, src_usuario su'||
            ' WHERE sa.idarchivo = sha.idarchivo'||
              ' AND sa.nombre_archivo LIKE ''%:1%'''||
              ' AND sa.idusuario = su.idusuario'||
              ' AND isvalidrange(sha.fechaprocesamiento,:2,:3) = ''T'''||
            ' ORDER BY to_date(sha.fechaprocesamiento, ''DD/MM/YYYY'')';

But there's seems to be a problem with the binding-variable :1, how to solve it? The error thrown is java.sql.SQLException: ORA-01006

Upvotes: 1

Views: 123

Answers (1)

A.B.Cade
A.B.Cade

Reputation: 16905

Try it like this:

sqlQuery := 'SELECT sa.nombre_archivo, sha.registrosok, sha.registroserroneos,'||
            ' sha.registrosinconsistentes,'||
            ' (sha.registrosok+sha.registroserroneos+sha.registrosinconsistentes),'||
            ' sha.fechaprocesamiento'||
              ' FROM src_historialarchivo sha, src_archivo sa, src_usuario su'||
            ' WHERE sa.idarchivo = sha.idarchivo'||
              ' AND sa.nombre_archivo LIKE :1'||
              ' AND sa.idusuario = su.idusuario'||
              ' AND isvalidrange(sha.fechaprocesamiento,:2,:3) = ''T'''||
            ' ORDER BY to_date(sha.fechaprocesamiento, ''DD/MM/YYYY'')';

execute immediate sqlQuery using '%abc%';

Upvotes: 2

Related Questions