dcmumbai
asked on
compare varchar2 field in pl/sql procedure urgent help !!!!!
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$TOTA LBLDSRAZS)
cursor inrec is
select hyp_acct_no,frstcol,trim(s ndcol)sndc ol from ACCT_INFO_MKT_MAP1 ;
v_acct_no ACCT_INFO_MKT_MAP1.HYP_ACC T_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$TOTA LBLDSRAZS ' 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_sn dcol)),0)
where hyp_acct_no=trim(rec.hyp_a cct_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$TOTA LBLDSRAZS ' 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
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$TOTA
cursor inrec is
select hyp_acct_no,frstcol,trim(s
v_acct_no ACCT_INFO_MKT_MAP1.HYP_ACC
v_frstcol ACCT_INFO_MKT_MAP1.frstcol
v_sndcol ACCT_INFO_MKT_MAP1.sndcol%
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('||
select jan_val into v_janval_frstcol
from HYP_ENT_HIST
where trim(hyp_acct_no)=trim(rec
/* 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$TOTA
then it works fine
*/
update ACCT_INFO_MKT_MAP1
set total=nvl(rec.hyp_acct_no*
where hyp_acct_no=trim(rec.hyp_a
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$TOTA
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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('||
should be
select jan_val into v_janval_sndcol
from HYP_ENT_HIST
where trim(hyp_acct_no)=TRIM(rec
sorry for that.
Once again thank you very much.
dcmumbai