Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamic Queries statement

16 views
Skip to first unread message

Javier Montero

unread,
Jun 3, 2013, 7:42:43 PM6/3/13
to
Hello Guys

I new in this forum and I have a question about a problem for build a dynamic statement. My problem is when try to run my code from ASP or any app I have a error, I don't know that is bad in code, please below my PL*SQL. I'm not expertise in oracle but I try.
Basically my problem is in the LIKE statement maybe I declared bad this sentence.
The common code errors when try to load my query from asp are:
ERROR-ORA-01756
ERROR-ORA-00911
I appreciate your comments and recommendations

CREATE OR REPLACE PACKAGE SAME.TESTPGK2 AS
TYPE out_cursor IS REF CURSOR;
PROCEDURE T01_PRUEBA2(pp IN VARCHAR2, status IN VARCHAR2, outputCursor OUT out_cursor);
END TESTPGK2;

CREATE OR REPLACE PACKAGE BODY TESTPGK2 AS
PROCEDURE T01_PRUEBA2(pp IN VARCHAR2, status IN VARCHAR2, outputCursor OUT out_cursor)
AS

v_query varchar2(8000);

BEGIN
v_query := 'SELECT ID_TYP_ACTOR AS CODIGO, DESCRIPCION AS DESCRIPCION, ESTATUS AS ESTATUS FROM T01_TIPOS_ACTORES';
v_query := v_query || ' WHERE 1 = 1';
IF pp IS NOT NULL THEN
v_query := v_query || ' AND DESCRIPCION LIKE %||pp||% ';

END IF;
IF status IS NOT NULL THEN
v_query := v_query || ' AND ESTATUS LIKE %||status||%' ;

END IF;
v_query := v_query || 'ORDER BY ID_TYP_ACTOR';

OPEN outputCursor for v_query;


EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001, 'An Error was Encountred - ' ||SQLCODE||' -ERROR-'||SQLERRM);
END T01_PRUEBA2;
END TESTPGK2;

Kay Kanekowski

unread,
Jun 4, 2013, 1:44:38 AM6/4/13
to
Hi Javier,
i expect your quotes are not right. Try this:

IF pp IS NOT NULL THEN
v_query := v_query || ' AND DESCRIPCION LIKE ''%' || pp || '%''';
END IF;
IF status IS NOT NULL THEN
v_query := v_query || ' AND ESTATUS LIKE ''%' || status || '%''' ;
END IF;
v_query := v_query || ' ORDER BY ID_TYP_ACTOR';


regards
Kay
0 new messages