In trigger I have that lines:
select p.place into place
from places p
where p.prime_commodity = p_Comm;
for x in (select * from some_table s where s.place = place)
that gives me every row in “some_table”, not filtering anything by “place”
and misses some rows that should be there
(
for x in (select * from some_table s where s.place = 'ABC')
works fine tho)
example
some_table:
| Place | InsPlace | InsState
| -------- | -------- |
| * | * | A
| * | ABC | A
| ABC | * | D
| ABC | ABC | A
code:
select '*' into place
from places p
where p.prime_commodity = p_Comm -- doesnt matter, select '*' into place will select only '*',
select listagg(s.place || ' ' || s.insplace || ' ' || s.insstate, chr(10)) within group (order by txt)
into dummy from some_table s
where s.place = place; --<- doesnt work
raise_application_error(-20001,place || chr(10) || dummy); -- only for debugging in trigger
expected
*
* * A
* ABC A
result
*
* * A
* ABC A
ABC * D
ABC ABC A
(all rows anyway, “where s.place = place” can be commented and result not even gonna change)
can it be fixed? what am I missing? can it be that place is ‘*’ symbol? could it be that oracle uses it as “anything” symbol inside triggers for some reason?
(in normal sql window any of it works like it should, only in trigger it does that shenanigan)
Before I used
CONTINUE when x.place <> place;
at the begining of for loop
but now it doesnt give some rows that it should
and results in something like
*
* * A <- wheres "* ABC A" row?
ABC * D
ABC ABC A
tried: select * from some_table s where s.place = place in trigger
expected: rows with s.place = place
resulted: all rows
user26814368 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
This is wrong:
select * from some_table s where s.place = place)
---------------
this
Never name variables the same as column names; it is the same as if you used where 1 = 1
(i.e. no filtering at all).
Rename variable to e.g. v_place
, then
select p.place
into v_place --> this
from places p
where p.prime_commodity = p_Comm;
and – finally:
... where s.place = v_place)