Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2014
    Posts
    294

    Unanswered: Max function in a dynamic sql

    Hi,

    I am looking to run the following statement in dynamic sql

    SET TEXT = ('set ? =(SELECT MAX(' ||m_id || ') FROM ' || database ||'.' || table || ')');
    PREPARE S1 FROM TEXT;
    EXECUTE S1 into P_id;

    this the debug value for the above statement
    SELECT MAX(apple_id) FROM SAMPLE.TROY.LOYEE

    Apple_id column is an integer data type.

    But throwing an error: apple_id is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703.

    I never used this Max function inside a dynamic sql yet. I know how to run this alone on static.
    I request can some tel me how to use these max,min, avg etc functions inside a dynamic sql. This is very basic, but the help will be a big thing for me.

  2. #2
    Join Date
    Jul 2014
    Posts
    294
    Solved

    SET TEXT = ('set ? =(SELECT MAX(' || m_id || ') FROM ' || database ||'.' || table || ')');
    PREPARE S1 FROM TEXT;
    EXECUTE S1 into P_id;
    call dbms_output.put_line(P_id);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •