I have procedure like this...
declare
v_psg varchar2(10);
id_no number;
begin
select value into v_psg from settings_am where key = 'PSG';
select id into id_no from product where to_char(psg) in (v_psg);
end;`
The value returned from select value into v_psg from settings_am where key = 'PSG'; would be
'1','2','3'
when i run this procedure i am returned with ora error - ORA-01403.
please advise how i should pass the v_psg value to psg column of product table?
If you got
ORA-01403, you were kind of lucky. It is theNO_DATA_FOUNDerror, which means that one (probably the first) query didn't return anything.Those two statements could be combined into
Why would you select
valuefirst, and then use it in another query? Besides, it just wouldn't work.v_psgis declared asVARCHAR2variable. The way you described it, it contains the following string:'1','2','3', as if this is what you have:As you can see, I enlarged the
valuecolumn size, although variable you declared says10. Why? Because ofi.e. you can't put something that is long 11 into something that accepts length 10.
Or, if your data actually contains 3 rows for the
PSGkey, are those values already enclosed into single quotes? If so, that's strange; people usually don't do that. Anyway, suppose that you managed to get string'1,2,3'(which is what I presume you actually have) into aVARCHAR2variable, then you have to split it into rows in order to be able to use it in theINclause:Query is then (where lines #3 - 5 represent splitting a string into rows):
So, wouldn't it be simpler to use
Note that both options also show why your query is wrong: you can't put two values (rows) into a variable declared as
id_no number;as you'd getTOO_MANY_ROWSerror.Finally, what is it that you'd want to do? What problem are you trying to solve? Apparently, except for special cases (only one row for each value) your query can't work. If you could provide test case (create table & insert into sample data), as well as expected output, it would be easier to help you.