Solved

compare varchar2 field in pl/sql procedure urgent  help !!!!!

Posted on 2003-11-17
2
1,856 Views
Last Modified: 2013-12-12
Hi,

I have procedure which need to compare the varchar2 field. I tried different way but I am not able to put  single quote  during variable comparison. if I hardcode single quote with value then it works but i Need variable value different and not hardcoded.

here is the procedure:

CREATE OR REPLACE procedure ACCT_INFO_MKT_MAP1_upd

is
--formula :      680100.001*(430400/NS$TOTALBLDSRAZS)
      cursor inrec is
            select hyp_acct_no,frstcol,trim(sndcol)sndcol from ACCT_INFO_MKT_MAP1 ;

v_acct_no  ACCT_INFO_MKT_MAP1.HYP_ACCT_NO%type;
v_frstcol  ACCT_INFO_MKT_MAP1.frstcol%type;
v_sndcol   ACCT_INFO_MKT_MAP1.sndcol%type;
v_janval_frstcol  number(20);
v_janval_sndcol  number(20);
v_janval_total  number(20);
v_err_no  varchar2(20);
v_err_msg  varchar2(200);
v_srt_tm  varchar2(20);
v_end_tm  varchar2(20);
v_sndcol1 varchar2(200);

-- first value is 430400  
--second value is  NS$TOTALBLDSRAZS

begin
      for rec in inrec loop
            exit when inrec%notfound;


            select jan_val into v_janval_sndcol
                        from HYP_ENT_HIST
                              where trim(hyp_acct_no)=TRIM('||v_sndcol1||') and acct_yr=1999;
                              

            select jan_val into v_janval_frstcol
                        from HYP_ENT_HIST
                              where trim(hyp_acct_no)=trim(rec.frstcol) and acct_yr=1999;
/* I am getting problem while comparing the second varchar value
both columns are varchar2 and same length.
 the select statemnt is like
   select jan_val v_janval_frstcol
                        from HYP_ENT_HIST
                              where trim(hyp_acct_no)='NS$TOTALBLDSRAZS ' and acct_yr=1999;
                              then it works fine
      */

            update ACCT_INFO_MKT_MAP1
                        set total=nvl(rec.hyp_acct_no*(v_janval_frstcol/(v_janval_sndcol)),0)
                              where hyp_acct_no=trim(rec.hyp_acct_no) ;                              

            end loop;
            commit;
                  
end;
/

/* I am getting problem while comparing the second value
it the select statemnt is like
   select jan_val v_janval_frstcol
                        from HYP_ENT_HIST
                              where trim(hyp_acct_no)='NS$TOTALBLDSRAZS ' and acct_yr=1999;
                              then it works fine
      */

1)  how to put single quote for variable in procedure?
2) incase query returns more then one row then how to avoid that?


Thank you very much in advance.
dcmumbai
0
Comment
Question by:dcmumbai
2 Comments
 
LVL 5

Accepted Solution

by:
gmyers earned 250 total points
ID: 9769032
If this works
   select jan_val v_janval_frstcol
                    from HYP_ENT_HIST
                         where trim(hyp_acct_no)='NS$TOTALBLDSRAZS ' and acct_yr=1999;
                         then it works fine
and this doesn't
         select jan_val into v_janval_frstcol
                    from HYP_ENT_HIST
                         where trim(hyp_acct_no)=trim(rec.frstcol) and acct_yr=1999;
then trim(rec.frstcol) doesn't match 'NS$TOTALBLDSRAZS '
The last character looks like a space, but if the trim isn't getting rid of it, could be a tab or something more ugly.
do a
select distinct ascii(substr(trim(hyp_acct_no),length(trim(hyp_acct_no)))) from HYP_ENT_HIST

I use the following to strip out all non-uppercase letters from a string. If you include all the characters you want in the string, it will strip out all the others (tabs, carriage retuns etc).
updat table set col =  
translate(col,' '||translate(col,' ABCDEFGHIJKLMNOPQRTSUVWXYZ',' '),' ') a
0
 

Author Comment

by:dcmumbai
ID: 9775995
Hi gmyers,

How are you? I appreciate your prompt help. Thank you very much. It was my mistake while comparing the wrong column. I was in hurry and didn't realise the problem.

 I am comparing the  
          select jan_val into v_janval_sndcol
                    from HYP_ENT_HIST
                         where trim(hyp_acct_no)=TRIM('||v_sndcol1||') and acct_yr=1999;

should be

          select jan_val into v_janval_sndcol
                    from HYP_ENT_HIST
                         where trim(hyp_acct_no)=TRIM(rec.hyp_acct_no) and acct_yr=1999;

sorry for that.

Once again thank you very much.
dcmumbai

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PL/SQL LOOP CURSOR 3 56
null value 15 92
Oracle Subquery bad Join 11 59
C# Connection String for Oracle database is not working 22 89
Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now