'PL/SQL: iterator value from FOR loop as a variable not working
I don't understand behaviour of my code.
Why when I have
select min(i.column_name) into value_min from EMPLOYEES; in my code (see belowe) I get error but if i put in this palce string with correct name of table I get result
select min(SALARY) into value_min from EMPLOYEES;
declare
cursor c_column_name is select column_name, data_type from USER_TAB_COLUMNS where table_name = 'EMPLOYEES';
/***************************
(...)
SALARY NUMBER
(...)
***************************/
value_name_col varchar2(100);
value_min number;
value_max number;
value_result number;
type t_rekord is table of EMPLOYEES%ROWTYPE INDEX BY BINARY_INTEGER;
begin
for i IN c_column_name loop
--DBMS_OUTPUT.PUT_LINE(i.column_name);
if i.data_type = 'NUMBER' and i.column_name = 'SALARY' then
-- coment line get ERROR
-- select min(i.column_name) into value_min from EMPLOYEES;
-- select max(i.column_name) into value_max from EMPLOYEES;
-- code below get results
select min(SALARY) into value_min from EMPLOYEES;
select max(SALARY) into value_max from EMPLOYEES;
select round(dbms_random.value(value_min,value_max),2) into value_result from dual;
DBMS_OUTPUT.PUT_LINE(i.column_name || ' = ' || value_result);
end if;
end loop;
end;
Error which I get:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 27
06502. 00000 - "PL/SQL: numeric or value error%s"
I prepare this for show you how my problem look like, i'ts not exactly what I do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
