handling error of null

hi to all

regarding this question

 select count(SUP_NO) into sn from sup_tran
          AND TRAN_NO1=to_char(d)
          AND (LINE_NO=vs.LINE_NO or line_no is null);
         if sn > 0 then
         	select nvl(SUP_NO,0) into sn from h2002.sup_tran
          AND TRAN_NO1=d
          AND (LINE_NO=vs.LINE_NO or line_no is null);
          SELECT initcap(ESUP_NAME) into benf FROM h2002.SUP_FILE  WHERE SUP_NO=NVL(sn,0);
          end if;

Open in new window

the statement fail if there is data
when i disable the 1st condition
the second select return correct data
i think it is because of the parameter d
d should be  varchar2
but why it fail in the 1st statement & success in the 2nd , i dont know
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I will do a "guess" and say: renamed your variables AND use aliases.

should be


so, the variables should have some prefix to identify it's a variable, and all columns should be prefixed with the table name or better alias. I presume that vs is a cursor or the like ...
SELECT count(st.SUP_NO) 
  INTO v_sn 
FROM sup_tran st
          AND st.TRAN_NO1=to_char(v_d)
          AND (st.LINE_NO=vs.LINE_NO or st.line_no is null);
         if v_sn > 0 then           
         	select nvl(SUP_NO,0) 
                  INTO v_sn 
                 FROM h2002.sup_tran st
         	WHERE st.TRAN_DATE=vs.DOC_DATE
                   AND st.TRAN_NO1= v_d
                AND (st.LINE_NO=vs.LINE_NO or st.line_no is null)
                SELECT initcap(ESUP_NAME) 
                      into benf 
              FROM h2002.SUP_FILE  sf 
              WHERE sf-SUP_NO=NVL(v_sn,0);
          end if; 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NiceMan331Author Commented:
it works
i know the mistake
i forgot to use : h2002.  before table name
h2002.sup_trans  instead of sup_tran
any how , please give me chance to try more , if there is no other mistakes , i will accept and close it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.