-2
我在oracle中有一個表,其中包含數值的所有列 我需要查詢或(PL \ sql腳本)從表中查找最大數字 請幫助...如何從包含數值的所有列的表中獲得最大值
我在oracle中有一個表,其中包含數值的所有列 我需要查詢或(PL \ sql腳本)從表中查找最大數字 請幫助...如何從包含數值的所有列的表中獲得最大值
試試這個:
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
無程序腳本
select MAX(num)
from
(
select colA as num
from test
union
select colB
from test
union
Select colC
from test
union
.
.
) x
謝謝你...我會嘗試 – user3162380