0

Can some one help me how to use the string inside a string? I need to use something without bound variables because I am passing all the input parameters from a procedure which I am using in my real requirement, so the values are fixed.

create or replace procedure Sample( rowsize number )
is
    v_result varchar2(100);
    v_str varchar2(200);
begin
    v_str := 'Select rtrim(legl_ent_name) || '' | '' ||rtrim(legl_ent_prd_grp) as heirarchy from legl_ent_regn where rownum < rowsize';
    EXECUTE IMMEDIATE v_str ;
    DBMS_OUTPUT.PUT_LINE(rowsize);

end;
/

I'm getting the error below when I run the procedure.

BEGIN 
dbms_output.enable(); 
Sample(2); 
END;

ERROR at line 1:
ORA-00904: "ROWSIZE": invalid identifier
ORA-06512: at "RATABASE.SAMPLE", line 7
ORA-06512: at line 3
2
  • 2
    Would this work? v_str := 'Select ... where rownum < ' || to_char(rowsize) ; Commented Dec 17, 2018 at 14:53
  • 2
    "need to use without bind variable because i am passing all the input parameters from procedure which i am using in my real requirement, so the values are fixed." — that doesn't quite seem to make sense. The answer posted uses a bind variable, or you can use @ypercubeᵀᴹ's suggestion but surely you have the option? If the values are really fixed you could just hard-code them into the quesy? Commented Dec 17, 2018 at 16:42

1 Answer 1

1
create or replace procedure Sample(rowsize number)
is
    v_result varchar2(100);
    v_str varchar2(200);
begin
    v_str := 'Select rtrim(legl_ent_name) || '' | '' ||rtrim(legl_ent_prd_grp) as heirarchy from legl_ent_regn where rownum < :1';
    EXECUTE IMMEDIATE v_str USING rowsize;
    DBMS_OUTPUT.PUT_LINE(rowsize);
end;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.