title: ERROR: cursor "<unnamed portal>" does not exist
body: <p>According to this procedure the cursor will shows two rows, but when i execute this query, it shows ERROR:  cursor "unnamed portal" does not exist
  In image table   </p>
  
  <pre><code>CREATE TABLE image
  (
    id numeric(9,0) NOT NULL,
    nm_code character varying(100) NOT NULL,
    synonym text NOT NULL,
    CONSTRAINT synonym_id PRIMARY KEY (id)
  )
  INSERT INTO image(
              id, nm_code, synonym)
      VALUES (01,'13160101','CAR TYRE');
  INSERT INTO image(
                  id, nm_code, synonym)
          VALUES (01,'10000101','CAR TYRE');
  </code></pre>
  
  <p>Legacy master table</p>
  
  <pre><code>CREATE TABLE legacymaster
  (
    legacy_code character varying(20),
    source_data text,
  )
  
  insert into legacymaster (legacy_code,source_data) values ('123','WITH CAR TYRE FROM AUDI 2000')
  </code></pre>
  
  <p>mm_nounmodmaster table structure</p>
  
  <pre><code>CREATE TABLE mm_nounmodmaster
  (
    nm_code character varying(18) NOT NULL,
    noun character varying(35),
    modifier1 character varying(35) NOT NULL,
    modifier2 character varying(35),
    modifier3 character varying(35),
    nm_type character(1) NOT NULL,
    nm_abbr character varying(200),
    nm_description character varying(80) NOT NULL,
    is_template character(1) DEFAULT 'N'::bpchar,
    )
  
  
      INSERT INTO mm_nounmodmaster(nm_code, noun, modifier1, modifier2, modifier3, nm_type, nm_abbr, 
              nm_description,is_template)
      VALUES ("10000101","ABRASIVE","--","--","","F","--","ABRASIVE",'Y')
  
      INSERT INTO mm_nounmodmaster(nm_code, noun, modifier1, modifier2, modifier3, nm_type, nm_abbr, 
                  nm_description,is_template)
                  VALUES ("13160101","TYRE","AUTOMOBILE","--","","F","TYR,AUTO","TYRE,AUTOMOBILE",'Y')
      INSERT INTO mm_nounmodmaster(nm_code, noun, modifier1, modifier2, modifier3, nm_type, nm_abbr, 
              nm_description,is_template)
              VALUES ("10020101","ACTUATOR","ELECTRICAL","--","--","F","ACTR,ELE","ACTUATOR,ELECTRICAL",'Y')
  </code></pre>
  
  <p>in nounmodmaster table three records are inserted but in image table synonyms contains 'car tyre' is only two nm_codes. So when i execute this function cursor will execute two rows in nounmodmaster except last row because it doesn't match with image table </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION func_source_based_nounmod(legacy_code_in character varying)
                    RETURNS refcursor AS
                  $BODY$
                      declare 
                          source text;
                          nmcode character varying(50);
                          v_parent_Rec1 record;
                          v_parent_Rec2 record;
                          item_desc character varying(50);
                          noun_t character varying(50);
                          mod1 character varying(50);
                          CUR REFCURSOR;
                  begin
                      --select source_data into source from legacymaster where source_data=legacy_code_in;
                      raise notice '1';
                      for v_parent_Rec1 in(SELECT id,nm_code,synonym FROM image)loop
                  raise notice '2';
                          --if exists (select source_data from legacymaster where legacy_code=legacy_code_in) then
                  raise notice '3';
                          IF exists (select source_data from legacymaster where legacy_code=legacy_code_in and source_data ilike '%'||v_parent_Rec1.synonym||'%') THEN
                  raise notice '4';
                              FOR v_parent_Rec2 IN(SELECT DISTINCT AA.NM_CODE, NM_TYPE,
                          (CASE WHEN NM_ABBR IS NOT NULL THEN NM_ABBR ELSE '--' END) as NM_ABBR,
                          NM_DESCRIPTION, NM_CATEGORY,
                          (CASE WHEN image.NM_CODE IS NOT NULL THEN 'ACTIVE' ELSE 'INACTIVE' END) as STATUS,
                          (CASE WHEN NOUN IS NOT NULL AND NOUN &lt;&gt; '--' AND trim(both ' ' from NOUN) &lt;&gt; '' THEN NOUN ELSE '' END) || 
                          (CASE WHEN MODIFIER1 IS NOT NULL AND MODIFIER1 &lt;&gt; '--' AND TRIM(BOTH ' ' FROM MODIFIER1) &lt;&gt; '' THEN ',' || MODIFIER1 ELSE '' END) ||
                          (CASE WHEN MODIFIER2 IS NOT NULL AND MODIFIER2 &lt;&gt; '--' AND TRIM(BOTH ' ' FROM MODIFIER2) &lt;&gt; '' THEN ',' || MODIFIER2 ELSE '' END) ||
                          (CASE WHEN MODIFIER3 IS NOT NULL AND MODIFIER3 &lt;&gt; '--' AND TRIM(BOTH ' ' FROM MODIFIER3) &lt;&gt; '' THEN ',' || MODIFIER3 ELSE '' END) AS NOUNMOD,
                          is_template, Count(image.nm_code) AS CountOfnm_code from mm_nounmodmaster aa
                              inner join image on image.nm_code=aa.nm_code
                              where image.synonym =v_parent_Rec1.synonym and image.nm_code=v_parent_Rec1.nm_code group by aa.nm_code,image.nm_code)LOOP
  
                      --raise notice '%',v_parent_Rec2.noun;
                      --raise notice '%',v_parent_Rec2.modifier1;
                          END LOOP;
                          ITEM_DESC:=v_parent_Rec1.nm_code;
                      raise notice '%',ITEM_DESC;
                      raise notice '%',v_parent_Rec2.nm_code;
                      raise notice '%',v_parent_Rec2.NM_TYPE;
                      raise notice '%',v_parent_Rec2.NM_ABBR;
                      raise notice '%',v_parent_Rec2.NM_DESCRIPTION;
                      raise notice '%',v_parent_Rec2.NM_CATEGORY;
                      raise notice '%',v_parent_Rec2.NOUNMOD;
                      raise notice '%',v_parent_Rec2.CountOfnm_code;
                          --end if;
                          OPEN CUR FOR 
                      SELECT DISTINCT v_parent_Rec2.nm_code,v_parent_Rec2.NM_TYPE,v_parent_Rec2.NM_ABBR,v_parent_Rec2.NM_DESCRIPTION,v_parent_Rec2.NM_CATEGORY,v_parent_Rec2.NOUNMOD,v_parent_Rec2.CountOfnm_code;
                      close cur;
                          end if;
                          end loop;
                    raise notice '5';
                  RETURN CUR;
                      end;
                  $BODY$
  </code></pre>
  
  <p>By passing Legacy_code_in parameter, it is in legacymaster table, if source data string contains  'Car Tyre'. then it will show two rows compare with image table</p>
  
  <p>i need </p>