7 Replies Latest reply: Feb 22, 2013 5:20 AM by garcol RSS

    image tag in select vs. image tag via function

    garcol
      Hello,

      Why is this working:
       case when function1( p1, p2 ) = 'N' 
          then
            '<img src="#APP_IMAGES#1.jpg" title="1">'
        else
          '<img src="#APP_IMAGES#2.jpg" title="1">'
        end nv 
      and this not:
      function2( p1, p2 ) images 
      Function1 returns Y or N, Function2 returns the same img-tag as in the 'case when' (<img src="#APP_IMAGES#1.jpg" title="1">). The first statement shows the image correct, the 2nd way does not show the image (red cross).

      Report columns are 'Standard report column', when I change that to 'Display as text', I see the right img-tag.


      Does anyone know why this is not working?

      Edited by: garcol on Feb 22, 2013 10:48 AM
        • 1. Re: image tag in select vs. image tag via function
          Tom Petrus
          That is because the SQL is parsed first, along with substitution strings. The results are not parsed. If you want to substitute in your procedure, you could always pass a substition string in as a parameter, and then parse the to-be-returned text yourself.
          • 2. Re: image tag in select vs. image tag via function
            VC
            garcol wrote:
            Hello,

            Why is this working:
             case when function1( p1, p2 ) = 'N' 
            then
            '<img src="#APP_IMAGES#1.jpg" title="1">'
            else
            '<img src="#APP_IMAGES#2.jpg" title="1">'
            end nv 
            and this not:
            function2( p1, p2 ) images 
            Function1 returns Y or N, Function2 returns the same img-tag as in the 'case when' (<img src="#APP_IMAGES#1.jpg" title="1">). The first statement shows the image correct, the 2nd way does not show the image (red cross).

            Report columns are 'Standard report column', when I change that to 'Display as text', I see the right img-tag.


            Does anyone know why this is not working?

            Edited by: garcol on Feb 22, 2013 10:48 AM
            Is this Classic report or IR?

            In classic report, The best way to do this is change the function to just return the name of image i.e. 1.jpg

            And in the report column attributes add a derived column with Display As set to Standard Report Column and in HTML expression add <img src="#IMAGES#"/>
            • 3. Re: image tag in select vs. image tag via function
              garcol
              OK. It's an interactive report by the way...

              But I wanted to use the function to return more than one image-tag. It will be a list of images, that's why I want to use a function, the list of images is dynamic, so:
              <img src="#APP_IMAGES#1.jpg" title="1"> <img src="#APP_IMAGES#2.jpg" title="2">
              etc.

              Edited by: garcol on Feb 22, 2013 11:27 AM
              • 4. Re: image tag in select vs. image tag via function
                garcol
                OK.

                But I wanted to use a function because I want to show more than one image. The function will return a couple of <img-tags>, so:
                <img src="#APP_IMAGES#1.jpg" title="1"> <img src="#APP_IMAGES#2.jpg" title="2"> <img src="#APP_IMAGES#5.jpg" title="5">
                etc.

                @Tom, I think I do not understand your comment...
                • 5. Re: image tag in select vs. image tag via function
                  VC
                  As Tom already mentioned, you have to pass the #APP_IMAGES# as parameter to the function2
                  // call it as
                  function2( p1, p2,'#APP_IMAGES#') images
                  • 6. Re: image tag in select vs. image tag via function
                    Tom Petrus
                    Exactly as VC showed, that is what i meant. Pass in an extra parameter.

                    For example, this function
                    CREATE OR REPLACE FUNCTION get_images
                    (
                    p1             IN VARCHAR2, 
                    p2             IN VARCHAR2, 
                    p_app_images   IN VARCHAR2
                    )
                    RETURN VARCHAR2
                    IS
                       lImageList VARCHAR2(2000);
                    BEGIN
                       FOR i IN 1..5
                       LOOP
                          lImageList := lImageList || '<img src="' || p_app_images || i || '.jpg" alt="' || i || '" >';
                       END LOOP;
                       
                       RETURN lImageList;
                    END;
                    And suppose this is the sql
                    SELECT get_images('param1', 'param2', '#APP_IMAGES#')
                    FROM DUAL
                    When apex parses the SQL, it will substitute #APP_IMAGES#, and would result in your function being called with the correct value.
                    For example, it would run this after substituting:
                    SELECT get_images('param1', 'param2', '98484C84E98468C464E894C984A47B867')
                    FROM DUAL
                    • 7. Re: image tag in select vs. image tag via function
                      garcol
                      Thanks, that's exactly what I have made now!

                      It works!

                      Many thanks!