我在oracle中有一个表,所有列都包含数值 我需要一个查询或(PL \ sql脚本)来从表中查找最大数字 请帮忙......
答案 0 :(得分:1)
试试这个:
declare
maxNumCol nubmer;
maxNum nubmer := 0;
begin
for aCol in (select column_name from user_tab_cols where table_name = 'MY_TABLE' and column_type = 'NUMBER') loop
execute immediate 'select max('||aCol.column_name||') from MY_TABLE' into maxNumCol;
maxNum := greatest(maxNum, maxNumCol);
end loop;
dbms_output.put_line(maxNum);
end;
也许你也可以使用它,但我不确定:
select greatest(max(col_a), max(col_b), max(col_c)) from my_table
答案 1 :(得分:0)
没有程序脚本
select MAX(num)
from
(
select colA as num
from test
union
select colB
from test
union
Select colC
from test
union
.
.
) x