Oracle Max Function Issue
Hi All
I have problem in selecting the max value of the field . i have the max value of particular field as 10, When i select using max function it is giving 9 as max value. Can someone help me to find this thing
Thanks...
Hi,
kindly check the data type of column
SQL> create table demo(c1 number);
Table created.
SQL> insert into demo values(10);
1 row created.
SQL> insert into demo values(1);
1 row created.
SQL> insert into demo values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select max(c1) from demo;
MAX(C1)
10
SQL> create table demo1(c1 varchar2(5));
Table created.
SQL> insert into demo1 values('10');
1 row created.
SQL> insert into demo1 values('1');
1 row created.
SQL> insert into demo1 values('2');
1 row created.
SQL> select max(c1) from demo1;
MAX(C
2
SQL> insert into demo1 values('9');
1 row created.
SQL> commit;
Commit complete.
SQL> select max(c1) from demo1;
MAX(C
9
SQL> select max(to_number(c1)) from demo1;
MAX(TO_NUMBER(C1))
10- Pavan Kumar N
Similar Messages
-
Oracle Analytic Function Issue
Hi, I have created a simple table contaning 3 columns and 3 records.
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (1, 1, 1);
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (2, 4, 1);
Insert into MYTABLE (ID, AMOUNT, RESULT) Values (3, 7, 0);
COMMIT;
I can SUM the AMOUNT using the analytic functions as
SELECT ID, AMOUNT, RESULT, SUM(AMOUNT) OVER() as TOTAL
FROM MYTABLE;
ID AMOUNT RESULT TOTAL
1 1 1 12
2 4 1 12
3 7 0 12
What I want to be able to do is summing the AMOUNTs by RESULT in this case 0 and 1.
To get the following result, how should I rewrite the query?
ID AMOUNT RESULT TOTAL RESULT_0_TOTAL RESULT_1_TOTAL
1 1 1 12 7 5
2 4 1 12 7 5
3 7 0 12 7 5SELECT ID, AMOUNT, RESULT
, SUM(CASE WHEN RESULT = 0 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_0
, SUM(CASE WHEN RESULT = 1 THEN AMOUNT ELSE 0 END) OVER() as TOTAL_1
FROM MYTABLE; -
Function issue in oracle 8i (817)
Hello,
Following objects are created in database
1. CREATE OR REPLACE TYPE PARAMETER_OBJ AS OBJECT
RUN VARCHAR2(2000),
BATCH_NO VARCHAR2(2000),
DAY_NO VARCHAR2(2000),
PARAMETER_NAME VARCHAR2(2000),
PARAMETER_VALUE VARCHAR2(2000),
PARAMETER_UOM VARCHAR2(2000)
2. CREATE OR REPLACE TYPE PARAMETER_TYP AS TABLE OF PARAMETER_OBJ ;
Info abt the function
1. function return type is PARAMETER_TYP.
2. Inside the function i initialize tblParameters PARAMETER_TYP:=PARAMETER_TYP();
3. Create a temporary table[TMP_PARAMETER] .The structure of the table is same as "PARAMETER_OBJ"
4. In a loop Insert data into temporary table
5. At the end issue following select statement
SELECT CAST (MULTISET (SELECT * FROM TMP_PARAMETER)
AS PARAMETER_TYP )
INTO tblParameters FROM DUAL;
6. issue commit (which flushes temp table)
7. return RETURN tblParameters
Finally issue following sql statement to get data from the function
select * from table(T_Get_ParameterValue('A03052','-1-SPINNER-CELL_AGE-15L,3-SPINNER-DOUBLING_TIME-15L'))
It works oracle 10g. In oracle 817 function compiles.But if i select as shown above it gives erorr says nested table not found..
Can any body help me.1. CREATE OR REPLACE TYPE PARAMETER_OBJ AS OBJECT
RUN VARCHAR2(2000),
BATCH_NO VARCHAR2(2000),
DAY_NO VARCHAR2(2000),
PARAMETER_NAME VARCHAR2(2000),
PARAMETER_VALUE VARCHAR2(2000),
PARAMETER_UOM VARCHAR2(2000)
2. CREATE OR REPLACE TYPE PARAMETER_TYP AS TABLE OF PARAMETER_OBJ ;
# Code
CREATE OR REPLACE Function T_Get_ParameterValue
a_run CLOB,
a_dytblcoleqp CLOB
-- [T]: TO_REMOVE: Changed return type.
-- 1. Need to create a temporary table TMP_PARAMETER which has the same structure as your object.
--RETURN PARAMETER_TYP PIPELINED
RETURN PARAMETER_TYP
AS
PRAGMA AUTONOMOUS_TRANSACTION;
TYPE cursor_type IS REF CURSOR;
TYPE STR_LST IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;
l_sql varchar2(4000);
l_cr cursor_type;
-- [T]: TO_REMOVE: Added variable.
tblParameters PARAMETER_TYP:=PARAMETER_TYP();
l_batch_lst STR_LST;
l_tblcl_lst STR_LST;
l_tbl_lst STR_LST;
l_col_lst STR_LST;
l_day_lst STR_LST;
l_sign_lst STR_LST;
l_eqp_lst STR_LST;
l_con CLOB;
l_tmp varchar2(4000);--Tmp store
l_pos number:=0; -- LOcator of the seperaotr
s_pos number:=0; -- start position
l_k number:=0; -- Array controller
l_n number:=0; -- Array controller
f_sp varchar2(1):=','; -- First seperator
s_sp varchar2(1):='-'; -- Second seperator
l_col_desc varchar2(2000);
l_column_type varchar2(2000);
l_capture_date varchar2(2000);
-- ipc list
l_parameter_uom varchar2(2000);
l_action_limit_max varchar2(2000);
l_action_limit_min varchar2(2000);
l_control_limit_max varchar2(2000);
l_control_limit_min varchar2(2000);
l_center_line varchar2(2000);
l_parameter_value varchar2(2000);
l_batch_id varchar2(2000);
l_batch_no varchar2(2000);
l_day_no varchar2(2000);
l_eqp varchar2(2000);
l_date date;
-- Loop Control
l_cont number;
i number;
--remove
l_sqlerm varchar2(2000);
BEGIN
l_pos:=0; -- LOcator of the seperaotr
-- Parsing
-- Parsing the tbl and col list
s_pos:=1;
l_cont:=1; -- loop control
i:=0; -- loop control
while (l_cont=1) loop
i:=i+1;
l_k:=l_k+1;
--determine position
l_pos:=instr(a_dytblcoleqp,f_sp,1,i);
if l_pos=0 and i=1 then -- no need to parse ,only 1 record
l_tmp:=a_dytblcoleqp;
l_tblcl_lst(l_k):=l_tmp;
--exit;
l_cont:=0;
elsif l_pos=0 and i!=1 then
l_tmp:=substr(a_dytblcoleqp,s_pos);
l_tblcl_lst(l_k):=l_tmp;
l_k:=l_k-1; re caluclate. nothing else to parse
--exit;
l_cont:=0;
else -- continue parse
l_tmp:=substr(a_dytblcoleqp,s_pos,l_pos-s_pos);
l_tblcl_lst(l_k):=l_tmp;
s_pos:=l_pos+1;
end if;
end loop; -- end of while loop
for j in 1..l_k loop
-- validate sign
if substr(l_tblcl_lst(j),1,1)='-' then
l_tblcl_lst(j):=substr(l_tblcl_lst(j),2);
l_sign_lst(j):='-';
else
l_sign_lst(j):='';
end if;
l_day_lst(j):=substr(l_tblcl_lst(j),1,instr(l_tblcl_lst(j),s_sp,1,1)-1);
l_day_lst(j):=l_sign_lst(j)||l_day_lst(j);
l_tbl_lst(j):=substr(l_tblcl_lst(j),instr(l_tblcl_lst(j),s_sp,1,1)+1,instr(l_tblcl_lst(j),s_sp,1,2)-instr(l_tblcl_lst(j),s_sp,1,1)-1);
l_col_lst(j):=substr(l_tblcl_lst(j),instr(l_tblcl_lst(j),s_sp,1,2)+1,instr(l_tblcl_lst(j),s_sp,1,3)-instr(l_tblcl_lst(j),s_sp,1,2)-1);
l_eqp_lst(j):=substr(l_tblcl_lst(j),(instr(l_tblcl_lst(j),s_sp,1,3)+1));
end loop;
-- Parsing Batch List
s_pos:=1;
l_cont:=1; -- loop control
i:=0; -- loop control
while (l_cont=1) loop
i:=i+1;
l_n:=l_n+1;
--determine position
l_pos:=instr(a_run,f_sp,1,i);
if l_pos=0 and i=1 then -- no need to parse ,only 1 record
l_tmp:=a_run;
l_batch_lst(l_n):=l_tmp;
l_cont:=0;--exit while loop
elsif l_pos=0 and i!=1 then
l_tmp:=substr(a_run,s_pos);
l_batch_lst(l_n):=l_tmp;
l_cont:=0;--exit while loop
else -- continue parse
l_tmp:=substr(a_run,s_pos,l_pos-s_pos);
l_batch_lst(l_n):=l_tmp;
s_pos:=l_pos+1;
end if;
end loop;
--- end of Parsing
-- Build con catenate list
for k in 1..l_n loop
--l_con:=NULL;
--l_con:='(';
--l_con:=l_con||''''||l_batch_lst(k)||''')';
--dbms_output.put_line(l_con);
for j in 1..l_k loop
-- 1 -- Get col desc
begin
select COLUMN_DESCR,COLUMN_TYPE,CAPTURE_DATE
into l_col_desc,l_column_type,l_capture_date
from MDM_ALL_PARAMETER_LIST
where table_name=upper(l_tbl_lst(j))
and column_name=upper(l_col_lst(j));
exception
when others then
l_col_desc:=NULL;
l_column_type:=NULL;
l_capture_date:=NULL;
end;
--dbms_output.put_line(l_batch_lst(k)||'-'||l_tbl_lst(j)||'-'||l_col_lst(j)||'-'||l_col_desc||'-'||to_char(l_capture_date));
--Build Sql Statement
if l_tbl_lst(j)='THAW' then
l_sql:=NULL;
l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw.BIN_NO as bin_no,ipc.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,thaw.'||l_col_lst(j)||','||l_capture_date;
l_sql:=l_sql||' from SPINNER spinner, BIN_HIER bin_hier, THAW thaw,IPC_LIMITS ipc';
l_sql:=l_sql||' where spinner.bin_no = bin_hier.bin_no';
l_sql:=l_sql||' and bin_hier.PROCESS_STEP =30';
l_sql:=l_sql||' and bin_hier.Revival_no = thaw.Revival_no';
l_sql:=l_sql||' and spinner.bin_no=ipc.LOT(+)';
l_sql:=l_sql||' and spinner.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and spinner.BATCH_ID=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
--dbms_output.put_line(l_sql);
elsif l_tbl_lst(j)='THAW_SAMPLES' then
if l_col_lst(j)!='CALC' then
l_sql:=NULL;
l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,thaw_samples.'||l_col_lst(j)||',thaw_samples.'||l_capture_date;
else
l_sql:=NULL;
--l_sql:='select spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,null as Parameter_value,thaw_samples.'||l_capture_date;
l_sql:='select distinct spinner.BATCH_ID as batch_id,thaw_samples.BIN_NO as bin_no,thaw_samples.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,Get_IPC_Parameter_Value('''||l_tbl_lst(j)||''''||','||''''||l_col_lst(j)||''',spinner.BATCH_ID,thaw_samples.BIN_NO,thaw_samples.DAY_NO),thaw_samples.'||l_capture_date;
end if;
l_sql:=l_sql||' from SPINNER spinner, BIN_HIER bin_hier, THAW thaw,THAW_SAMPLES thaw_samples,IPC_LIMITS ipc';
l_sql:=l_sql||' where spinner.bin_no = bin_hier.bin_no';
l_sql:=l_sql||' and bin_hier.PROCESS_STEP =30';
l_sql:=l_sql||' and bin_hier.Revival_no = thaw.Revival_no';
l_sql:=l_sql||' and thaw_samples.bin_no=thaw.bin_no';
l_sql:=l_sql||' and spinner.bin_no=ipc.LOT(+)';
l_sql:=l_sql||' and spinner.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and spinner.BATCH_ID=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
l_sql:=l_sql||' and ipc.day_no(+)=:5';
l_sql:=l_sql||' and thaw_samples.day_no=:6';
elsif l_tbl_lst(j) in ('F1250L_TEST','F200L_TEST','F4000L_TEST','F8000L_TEST') then
l_sql:=NULL;
l_sql:='select t.batch_id,t.bin_no,t.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
l_sql:=l_sql||' where 1=1';
l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
l_sql:=l_sql||' and t.day_no=ipc.day_no(+)';
l_sql:=l_sql||' and t.batch_id=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
l_sql:=l_sql||' and t.day_no=:5';
elsif l_tbl_lst(j) in ('SPINNER_SAMPLES') then
l_sql:=NULL;
l_sql:='select smp.batch_id,smp.bin_no,smp.DAY_NO as day_no,spn.src_vessel_id as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,smp.'|| l_col_lst(j)||',smp.'||l_capture_date;
l_sql:=l_sql||' from SPINNER spn , SPINNER_SAMPLES smp,IPC_LIMITS ipc ';
l_sql:=l_sql||' where 1=1';
l_sql:=l_sql||' and spn.bin_no=smp.bin_no';
l_sql:=l_sql||' and smp.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and smp.DAY_NO=ipc.DAY_NO(+)';
l_sql:=l_sql||' and smp.BIN_NO=ipc.LOT(+)';
l_sql:=l_sql||' and smp.batch_id=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
l_sql:=l_sql||' and smp.DAY_NO(+)=:5';
l_sql:=l_sql||' and upper(trim(replace(spn.src_vessel_id,'' '')))=:6';
elsif l_tbl_lst(j) in ('SPINNER') then
l_sql:=NULL;
l_sql:='select t.batch_id,t.bin_no,null as day_no,t.src_vessel_id as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
l_sql:=l_sql||' where 1=1';
l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
l_sql:=l_sql||' and t.batch_id=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
l_sql:=l_sql||' and upper(trim(replace(t.src_vessel_id,'' '')))=:5';
else
-- rest
l_sql:=NULL;
l_sql:='select t.batch_id,t.bin_no,ipc.DAY_NO as day_no,NULL as eqp,ipc.PARAMETER_UOM as parameter_uom ,ipc.IPC_ACTION_LIMIT_MAX as ipc_action_limit_max,ipc.IPC_ACTION_LIMIT_MIN as ipc_action_limit_min,ipc.IPC_CONTROL_LIMIT_MAX as ipc_control_limit_max,ipc.IPC_CONTROL_LIMIT_MIN as ipc_control_limit_min,ipc.CENTER_LINE as center_line,t.'|| l_col_lst(j)||',t.'||l_capture_date;
l_sql:=l_sql||' from '||l_tbl_lst(j)||' t,IPC_LIMITS ipc ';
l_sql:=l_sql||' where 1=1';
l_sql:=l_sql||' and t.BATCH_ID=ipc.BATCH_ID(+)';
l_sql:=l_sql||' and t.BIN_NO=ipc.LOT(+)';
l_sql:=l_sql||' and t.batch_id=:1';
l_sql:=l_sql||' and ipc.TABLE_NAME(+)=:2';
l_sql:=l_sql||' and ipc.COLUMN_NAME(+)=:3';
l_sql:=l_sql||' and ipc.SITE_ID(+)=:4';
end if;
-- Open the cursor and filled up object
if l_tbl_lst(j)='THAW_SAMPLES' then
open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j),l_day_lst(j);
loop
null;
fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
exit when l_cr%notfound;
--PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
-- [T]: TO_REMOVE: Changed code to populate the temporary table.
INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
end loop;
close l_cr;
elsif l_tbl_lst(j) in ('SPINNER_SAMPLES') then
open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j),l_eqp_lst(j);
loop
null;
fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
exit when l_cr%notfound;
--PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
-- [T]: TO_REMOVE: Changed code to populate the temporary table.
INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
end loop;
close l_cr;
null;
elsif l_tbl_lst(j) in ('SPINNER') then
open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_eqp_lst(j);
loop
null;
fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
exit when l_cr%notfound;
-- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
-- [T]: TO_REMOVE: Changed code to populate the temporary table.
INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
end loop;
close l_cr;
elsif l_tbl_lst(j) in ('F1250L_TEST','F200L_TEST','F4000L_TEST','F8000L_TEST') then
null;
open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1,l_day_lst(j);
loop
null;
fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
exit when l_cr%notfound;
-- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
-- [T]: TO_REMOVE: Changed code to populate the temporary table.
INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
end loop;
close l_cr;
else
open l_cr for l_sql using l_batch_lst(k),l_tbl_lst(j),l_col_lst(j),1;
loop
null;
fetch l_cr into l_batch_id,l_batch_no,l_day_no,l_eqp,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_parameter_value,l_date;
exit when l_cr%notfound;
-- PIPE ROW(PARAMETER_OBJ (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date) );
-- [T]: TO_REMOVE: Changed code to populate the temporary table.
INSERT INTO TMP_PARAMETER VALUES (l_batch_id,l_batch_no,l_day_no,l_col_desc,l_parameter_value,l_parameter_uom,l_action_limit_max,l_action_limit_min,l_control_limit_max,l_control_limit_min,l_center_line,l_eqp,'1',l_tbl_lst(j),l_col_lst(j),l_date);
end loop;
close l_cr;
null;
end if;
end loop;-- end of for loop for j in 1..l_k loop
end loop; --end of for j in 1..l_n loop
-- [T]: TO_REMOVE: Return the data from the temporary table into the table type.
-- Return data into table type.
SELECT CAST (MULTISET (SELECT * FROM TMP_PARAMETER)
AS PARAMETER_TYP )
INTO tblParameters FROM DUAL;
-- [T]: TO_REMOVE: Added commit so that the data in the temporary table is deleted.
COMMIT;
-- [T]: TO_REMOVE: Return the table type.
-- return ;
RETURN tblParameters;
EXCEPTION
WHEN OTHERS THEN
--l_sqlerm:=substr(sqlerrm,1,200);
ROLLBACK;
RAISE_APPLICATION_ERROR (-20001, SQLERRM);
return NULL;
END;
# Select sql statement
select *
from table(T_Get_ParameterValue('A03052','-1-SPINNER-CELL_AGE-15L,3-SPINNER-DOUBLING_TIME-15L')) -
Oracle:how to use max() function in case expression
how to use max() function in case expression, Please explain with any example
Hope this helps and should be self explanatory
with t as
(select 1 col,100 col2 from dual union
select 2 ,100 from dual union
select 2 ,200 from dual union
select 3,100 from dual union
select 3,200 from dual )
select col, case when max(col2)=100 then 'with 100 range'
when max(col2)=200 then 'with 200 range' end from t group by col -
Bug? using MAX() function on char(1) column returns something larger
details:
-- we have a complex nested query, where we are essentially returning the max() value into a variable
-- the max() function is being used on a char(1) column
-- where MAX() is part of an inner select, we have started getting
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
errors.
SELECT MAX(X) INTO var FROM ... works in 9i and 10g
SELECT X INTO var FROM (SELECT MAX(X) X FROM ... worked in 9i, does not work in 10g!
-- We never had problems with the code until upgrading to 10g release 2.
-- the Solution is to cast the final value with TO_CHAR(). The cast MUST be done at the outer most point of the select:
SELECT TO_CHAR(X) INTO var FROM (SELECT MAX(X) X FROM ... works
SELECT X INTO var FROM (SELECT TO_CHAR(MAX(X)) X FROM ... causes an error!
The following script demonstrates the issue, and includes the solution:
* October 3, 2006
* Possible SQL bug introduced with Oracle 10G
* Natalie Gray DBA/Developer, Environment Canada
* Description:
* Have discovered a problem with using the MAX() function
* on columns of type char(1)
* only an issue when used in an inner select
* solution (see test 4)
CREATE TABLE SQL_BUG_TEST
X NUMBER,
Y NUMBER,
Z CHAR(1)
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,1,'A');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,1,'B');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,2,'C');
INSERT INTO SQL_BUG_TEST (X, Y, Z)
VALUES (1,2,'D');
DECLARE
TYPE REC IS RECORD (
x SQL_BUG_TEST.X%TYPE,
y SQL_BUG_TEST.Y%TYPE,
z SQL_BUG_TEST.Z%TYPE
v_rec REC;
BEGIN
-- DISPLAY THE TABLE DATA
BEGIN
DBMS_OUTPUT.PUT_LINE('TABLE DATA:');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * FROM SQL_BUG_TEST ORDER BY X,Y,Z;');
FOR crs IN (SELECT *
FROM SQL_BUG_TEST
ORDER BY X,Y,Z) LOOP
DBMS_OUTPUT.PUT_LINE(':'||crs.X||':'||crs.Y||':'||crs.Z);
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 1
-- returning result from MAX into a variable when the MAX is in the outer most select
-- does not cause an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 1');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y');
FOR crs IN (SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y
ORDER BY X,Y,Z) LOOP
DBMS_OUTPUT.PUT_LINE(':'||crs.X||':'||crs.Y||':'||crs.Z);
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 2
-- returning MAX() from an inner select to an outer select and then into a variable
-- causes an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 2');
DBMS_OUTPUT.PUT_LINE('THIS DID NOT CAUSE AN ERROR WITH ORACLE 9i');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT * INTO v_rec
FROM
(SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 3
-- casting the result from MAX to char before returning to the outer select
-- still causes an error
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 3');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT * INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, to_char(MAX(Z)) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT * INTO v_rec
FROM
(SELECT X, Y, to_char(MAX(Z)) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
-- TEST 4 - SOLUTION
-- the return value of MAX must be cast with to_char at the point where it is assigned to
-- variable (outer most select)
BEGIN
DBMS_OUTPUT.PUT_LINE('*****************************************************');
DBMS_OUTPUT.PUT_LINE('TEST 4 SOLUTION');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('SELECT X, Y, TO_CHAR(Z) Z INTO v_rec');
DBMS_OUTPUT.PUT_LINE('FROM');
DBMS_OUTPUT.PUT_LINE('(SELECT X, Y, MAX(Z) Z');
DBMS_OUTPUT.PUT_LINE('FROM SQL_BUG_TEST');
DBMS_OUTPUT.PUT_LINE('GROUP BY X,Y)');
DBMS_OUTPUT.PUT_LINE('WHERE Y = 1');
SELECT X, Y, TO_CHAR(Z) Z INTO v_rec
FROM
(SELECT X, Y, MAX(Z) Z
FROM SQL_BUG_TEST
GROUP BY X, Y)
WHERE Y = 1;
DBMS_OUTPUT.PUT_LINE(':'||v_rec.X||':'||v_rec.Y||':'||v_rec.Z);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
END;I certainly looks like a bug, but you should raise an iTAR on Metalink since Oracle does not monitor this forum.
I was able to replicate your results on my 10.2.0.1 database.
There is an easier workaround than yours. Try
ALTER TABLE sql_bug_test MODIFY (z VARCHAR2(1));That seems to eliminate the problem on my instance.
John -
MAX Function not returning MAX
I have a query that is pulling in EDI 214 status codes, and want to pull in the last received status for status type "AG". To do this, I'm using the MAX function on the INSERT_DATE field of the status code AG, but the query keeps returning both AG status codes. I've tried this in a single query (Query 1) but it did not work so I also attempted it in a much smaller query to be used as a subquery, but that still did not work. Can anyone identify what the issue is with what I'm attempting to do?
Query 1 (All Inclusive):
SELECT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
AGSS.EVENTDATE AS AG_EVENT,
D1SS.EVENTDATE AS D1_EVENT,
BS.START_TIME AS BUY_START_TIME,
AGSS.STATUS_CODE_GID AS AG,
D1SS.STATUS_CODE_GID AS D1,
BS.DOMAIN_NAME AS BUY_DOMAIN,
MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE,
MAX(D1SS.INSERT_DATE) AS D1_INSERT_DATE,
BS.START_TIME,
BS.DOMAIN_NAME,
SHIPSTAT.STATUS_VALUE_GID
FROM V_ROD_SHIPMENT BS
INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
INNER JOIN V_ROD_SS_STATUS_HISTORY D1SH
ON (BS.SHIPMENT_GID = D1SH.SHIPMENT_GID)
INNER JOIN V_ROD_SHIPMENT_STATUS SHIPSTAT
ON (BS.SHIPMENT_GID = SHIPSTAT.SHIPMENT_GID)
INNER JOIN V_ROD_IE_SHIPMENTSTATUS D1SS
ON D1SH.I_TRANSACTION_NO = D1SS.I_TRANSACTION_NO
WHERE BS.START_TIME > '18/MAY/12'
AND BS.DOMAIN_NAME = 'UPS/CP/HDMB'
AND AGSS.STATUS_CODE_GID = 'AG'
AND D1SS.STATUS_CODE_GID = 'D1'
AND (SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
|| '.SECURE RESOURCES_ACCEPTED'
OR SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
|| '.SECURE RESOURCES_PICKUP NOTIFICATION')
GROUP BY BS.SHIPMENT_GID,
AGSS.EVENTDATE,
D1SS.EVENTDATE,
BS.START_TIME,
AGSS.STATUS_CODE_GID,
D1SS.STATUS_CODE_GID,
BS.DOMAIN_NAME,
SHIPSTAT.STATUS_VALUE_GID
Query 2 (to be used as a sub-query if I cannot pull MAX insert date in previous query):
SELECT DISTINCT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
AGSS.EVENTDATE AS AG_EVENT,
AGSS.STATUS_CODE_GID AS AG,
MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE
FROM V_ROD_SHIPMENT BS
INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
WHERE AGSS.STATUS_CODE_GID = 'AG'
AND BS.SHIPMENT_GID = 'UPS/CP/HDMB.HDM-1000203768'
GROUP BY BS.SHIPMENT_GID,
AGSS.EVENTDATE,
AGSS.STATUS_CODE_GID
Results of query 2 (similar issue as query 1, query doesn't return MAX insert date):
BUY_SHIPMENT_GID AG_EVENT AG AG_INSERT_DATE
UPS/CP/HDMB.HDM-1000203768 5/25/2012 6:00:00 PM AG 5/21/2012 3:10:36 PM
UPS/CP/HDMB.HDM-1000203768 6/1/2012 5:00:00 PM AG 5/20/2012 2:36:18 PM
I appreciate any help.
Thanks,
-AdamHi, Adam,
Welcome to the forum!
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
If you can show what the problem is using commonly available tables (such as those in the scott schem) then you don't have to psot any sample data; just the results and the explanation.
Always say which version of Oracle you're using.
See the forum FAQ {message:id=9360002}
MAX (insert_date) returns the latest insert_date. I think, in this problem, you don't really want the latest insert_date; you want the status code that's related to the last insert_date. One way to get that is the aggregate FIRST (or LAST) function.
Consider this query, using the scott.emp table:
SELECT ename
, hiredate
FROM scott.emp
ORDER BY hiredate
, ename
;Output:
ENAME HIREDATE
SMITH 17-Dec-1980
ALLEN 20-Feb-1981
WARD 22-Feb-1981
JONES 02-Apr-1981
BLAKE 01-May-1981
CLARK 09-Jun-1981
TURNER 08-Sep-1981
MARTIN 28-Sep-1981
KING 17-Nov-1981
FORD 03-Dec-1981
JAMES 03-Dec-1981
MILLER 23-Jan-1982
SCOTT 19-Apr-1987
ADAMS 23-May-1987Say we're only interested in seeing the last hiredate, and the name of the person hired on that date:
LAST_ENAME LAST_HIREDA
ADAMS 23-May-1987Here's how to get those results using the aggregate LAST function:
SELECT MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
, MAX (hiredate) AS last_hiredate
FROM scott.emp
;What if there's a tie for the latest hiredate? For example, say we're only looking at people hired before 1982. In that case, the latest hiredate is December 3, 1981, and there happen to be two people hired on that date. This query
SELECT MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
, MAX (hiredate) AS last_hiredate
FROM scott.emp
WHERE hiredate < DATE '1982-01-01'
;produces only 1 row of output:
LAST_ENAME LAST_HIREDA
FORD 03-Dec-1981Why did it show FORD rather than JAMES? Because of the MIN function. When there happens to be a tie for the latest hiredate, MIN says to return the first ename (in normal sort order) of the rows that have that hiredate.
FIRST and LAST work with GROUP BY, too.
In the example above, we were only looking at one column related to the latest hiredate. If we neede to see several columns, it would be simpler to use the analytic ROW_NUMBER function:
WITH got_r_num AS
SELECT emp.*
, ROW_NUMBER () OVER ( ORDER BY hiredate DESC
, ename
) AS r_num
FROM scott.emp
WHERE hiredate < DATE '1982-01-01'
SELECT *
FROM got_r_num
WHERE r_num = 1
I hope this answers your question.
If not, post a more complete explanation of what you want to do. if you have to use your own tables, then post CREATE TABLE and INSERT statements for a little sample data. Post the results you want from that data, and explain how you get those results from that data. -
Hi all,
I'm a beginner working with XPath expressions.
I have a xml document 'test.xml' with the following contents.
<?xml version="1.0" encoding="UTF-8"?>
<ICRI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.orswegimoarmada.es/ORSWE/ICRI
http://www.orswegimoarmada.es/ORSWE/XSD/ICRI/ICRI.xsd"
xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI">
<ID>ICRI.Prueba.DocPrueba1.2006.11.15-09.19.01</ID>
<NombreRecurso>DocPrueba1</NombreRecurso>
<TipoRecurso>Documento Técnico</TipoRecurso>
<Descripcion>Documento de ejemplo.</Descripcion>
<ExtensionRecurso/>
<VersionRecurso>1.0</VersionRecurso>
<Estado>En Proceso</Estado>
<NivelSeguridad>NATO UNCLASSIFIED</NivelSeguridad>
<Entornos/>
<PalabrasClave/>
<Sinonimos/>
<Modificaciones>
<Modificacion>
<Usuario>demoadminpro</Usuario>
<FechaHora>2006.11.15-09.19.01</FechaHora>
<Secuencia>1</Secuencia>
<EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.19.01.xml</EnlaceRecurso>
</Modificacion>
<Modificacion>
<Usuario>demoadminpro</Usuario>
<FechaHora>2006.11.15-09.20.01</FechaHora>
<Secuencia>2</Secuencia>
<EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.20.01.xml</EnlaceRecurso>
</Modificacion>
<Modificacion>
<Usuario>demoadminpro</Usuario>
<FechaHora>2006.11.15-09.21.01</FechaHora>
<Secuencia>3</Secuencia>
<EnlaceRecurso>/ORSWE/Proyectos/Prueba/Documento Técnico/DocPrueba1.2006.11.15-09.21.01.xml</EnlaceRecurso>
</Modificacion>
</Modificaciones>
</ICRI>
I use the code to obtain information about xml.
SELECT extractValue(value(d), '/ICRI/NombreRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') NOMBRERECURSO,
extractValue(value(d), '/ICRI/TipoRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') TIPORECURSO,
extractValue(value(d), '/ICRI/VersionRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') VERSIONRECURSO,
extractValue(value(d), '/ICRI/Descripcion', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') DESCRIPCION,
extractValue(value(d), '/ICRI/Modificaciones/Modificacion/Secuencia', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') SECUENCIA
FROM RESOURCE_VIEW r, table(xmlsequence(extract(r.res, '/r:Resource/r:Contents/i:ICRI', 'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd" xmlns:i="http://www.orswegimoarmada.es/ORSWE/ICRI"'))) d
WHERE r.any_path='test.xml'But the element Secuencia has several values and I only need to obtain the max of this values. I think, XPath max function can resolve this issue, but I don't know how do I do this?. Is it possible?
Thanks in advance,
David.Well, I am desperate :-(((
I am trying to extend the early query, now, r.any_path must be obtained from another table that it is another registered schema also.
The folowing is a piece of this query:
SELECT
extractValue(value(di), '/ICRI/NombreRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') NOMBRERECURSO,
extractValue(value(di), '/ICRI/TipoRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') TIPORECURSO,
extractValue(value(di), '/ICRI/VersionRecurso', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') VERSIONRECURSO,
extractValue(value(di), '/ICRI/Descripcion', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"') DESCRIPCION
FROM RESOURCE_VIEW r,
table(xmlsequence(extract(r.res, '/r:Resource/r:Contents/i:ICRI', 'xmlns:r="http://xmlns.oracle.com/xdb/XDBResource.xsd" xmlns:i="http://www.orswegimoarmada.es/ORSWE/ICRI"'))) di
WHERE
r.any_path IN
(select extractValue(value(t), '/InfoEntradaGeneral/EnlaceICRI', 'xmlns="http://www.orswegimoarmada.es/ORSWE/PlantillaProyecto')
FROM PLANTILLAPROYECTO p, table(xmlsequence(extract(p.object_value, '/PlantillaProyecto/Proceso/Pasos/Paso[@IdPaso="0"]/Actividades/Actividad[@IdActividad="1"]/EntradasActividad/EntradasGenerales/InfoEntradaGeneral'))) t
WHERE existsNode(p.object_value, '/PlantillaProyecto/DetallesProyecto[NombreProyecto="Prueba"]')=1);Now, Oracle only shows me a register when the query must be three.
The query
select extractValue(value(t), '/InfoEntradaGeneral/EnlaceICRI', 'xmlns="http://www.orswegimoarmada.es/ORSWE/PlantillaProyecto')
FROM PLANTILLAPROYECTO p, table(xmlsequence(extract(p.object_value, '/PlantillaProyecto/Proceso/Pasos/Paso[@IdPaso="0"]/Actividades/Actividad[@IdActividad="1"]/EntradasActividad/EntradasGenerales/InfoEntradaGeneral'))) t
WHERE existsNode(p.object_value, '/PlantillaProyecto/DetallesProyecto[NombreProyecto="Prueba"]')=1);returns several values, for instance:
1. test.xml
2. test1.xml
3. test2.xml
Why does not it work?. I suppose that the query is correct.
I try the same with relational tables and it works fine.
Query SELECT B.COLUMN2 FROM B WHERE B.COLUMN1 IN (SELECT COLUMN1 FROM A returns several values from A and shows the right values from B.
Please, Could someone to help me?
Thanks in advance,
David. -
Friends and Gurus,
Table: comments
column: c1
characterset: WE8IS08859P1
I am trying to use Oracle convert function to identify rowid's where column length greater than 4000 characters.
Table comments was created under 'WE8IS08859P1' characterset and I'm moving this table to 'AL32UTF8'.
I don't have csscan installed so trying to query sql and convert column to 'AL32UTF8' characteset and find rowid's to fix.
I have tried below but doesn't help
SELECT MAX(length(CONVERT(c1,'AL32UTF8'))) FROM comments;
SELECT length(CONVERT(c1,'AL32UTF8'))
FROM comments
WHERE length(c1) > 4000;
did anybody faced similar issue?Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Simplify the problem as much as possible. For example, instead of looking fro strings that have more than 4000 characters (or bytes), post a problem where you want to find strings longer than 4 characters (or bytes).
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
Are you interested in the number of characters, or the number of bytes? Use LENGTHB if you want the length in bytes. -
Using max function in PL/SQL
VERY URGENT...
Am new to oracle...
I've written a package that display gif images in form of histogram/bar chart. using html,
I need to use max function to display values proportionately.
please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabledFirst of all Thanks to all gentlemen who replied ..many thanks ...
Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
Any further suggestions or ideas as to how this could be resolved..
SELECT 'Y', 'Y', ITEM_KEY
FROM
( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
) T WHERE RN <= 1
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 1.57 0 0 0 0
Fetch 1 8700.00 544968.73 8180 8185 0 0
total 2 8700.00 544970.30 8180 8185 0 0
many thanks -
Using Max Function in View Criteria
Hi
I am having a requirement where by i need to make use of max function in view criteria but not able to see any such option. Can someone please help me over it. Here is the requirement.
In table i will be having multiple rows for an employee and i need to pick latest row based on a column say request_id For e.g.
Emp RequestId
A 1
A 2
A 3
A 4
So if i pass the employee id i should get Row Number 4. In simple SQL language I want something like this
select * from emp where empid=A and requestid=( select max(requestid) from emp where empid=A)
Just wanted to know is there any approach that i can use to do all this as part of View Criteria or any other way.
Any help is appreciated!!!
Thanks
AJOne way is this -
1)https://blogs.oracle.com/adf/entry/using_groovy_aggregate_functions_in (You might need to create a self-referencing VL for this , try if it works using a ViewAccessor too)
OR
Order by RequestId descending in your SQL for the VO if thats ok , then have the ViewCriteria for the EmpId and programmatically pickup the first row... -
Problem with max function in air
Hello ,how are you,I write this query : [b]SELECT *, max(trackerId) FROM sessiontracker [/b]in
sqlite manager and it works ,but when I use it in Air application ,it send me back this error:
ReferenceError: Error #1056: Cannot create property max(trackerId) on
com.afarinesh.models.SessionTracke
,I guess that Actionscript 3 can not pars max function.
I appreciate your helpHello,
AIR does support max function. Please see Page 1067 of the actionscript developer's guide, which can be download from http://help.adobe.com/en_US/as3/dev/as3_devguide.pdf. And I tried the max function in my AIR application: create a table, insert some records into the table, and use the "select *, max(column) from table". It works fine.
I noticed your error is the ReferenceError and related to some AS class. So I am not sure if you use any ORM tool. If so, the issue may be caused by the use of the tool. Please check the configuration and usage of the tool.
Thanks,
Yang -
I have the following tables along with their attributes(the
stared fields show the primary key:
Agent(AgentPhoneNo*, NameOfAgent)
Constituency(ConstituencyNo*,
ConstituencyName,District,RegionCode)
PollingStation(StationNo*,ConstituencyNo*,AgentPhoneNo,
StationName)
VoteResults(Party*, ResultsCategory*,Votes, AgentPhoneNo*)
Results category has two values (S,L) and the number of
parties is variable
My issue is this, below is my code that returns the total
votes received by each party with each constituency. This
query works fine.
<cfquery name="WinningPartyinConstituency"
datasource="#request.datasource#">
SELECT c.ConstituencyName, s.ConstituencyNo, v.Party,
Sum(v.Votes) AS TotalVotes
From (Constituency c
INNER JOIN PollingStation s ON c.ConstituencyNo =
s.ConstituencyNo)
INNER JOIN VoteResults v ON s.AgentPhoneNo = v.AgentPhoneNo
WHERE v.ResultCategory = 'L' AND s.ConstituencyNo IN (Select
ConstituencyNo From Constituency)
Group By c.ConstituencyName, s.ConstituencyNo, v.Party
Order By c.ConstituencyName
</cfquery>
Now I want to check and return the name and total votes of
the party with the maximum votes within each constituency. And but
I can't seem to figure out how to do that, especially because the
max() function takes only to
values.
I will appreciate any guidance on how to write a query that
returns the the party with the maximum votes in each constituency
and the votes it got. TIAMy approach would be to do 2 or 3 Q of Qs to get the numbers
I need. -
Hi,
One of our customers is facing an error while executing a PL/SQL block like,
declare
l_flag varchar2(30);
begin
select max('Y') into l_flag from v$database; -- Can use any table here
end;
however, when the select query is changed to as follows, no error is seen.
select substr(max('Y'),1,30) into l_flag from v$database;
Can someone please help me in identifying what could be issue?
Thanks,
DolaWe are actually trying to check if the table contains any rows.Hmmm, I would have thought that using a MAX() function to do that is rather expensive (if it's a large table)...
SQL> set autotrace traceonly stat
SQL> select max('Y') from tt1
2 /
Statistics
0 recursive calls
0 db block gets
432 consistent gets
428 physical reads
0 redo size
378 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> select count(*) from tt1
2 /
Statistics
0 recursive calls
0 db block gets
432 consistent gets
423 physical reads
0 redo size
381 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> select null from tt1
2 where rownum = 1
3 /
Statistics
0 recursive calls
0 db block gets
4 consistent gets
5 physical reads
0 redo size
372 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> Cheers, APC -
How to Avoid Errors in Max Function When Data Contains Blank Cells
I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
Thanks,
NicI don't see a problem with "blank" (null string) cells mixed with duration cells. MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"? -
Hi Everyone,
Am aware of the following flavors of MAX function
1) choose MAX from the folders/fields list (selected items tab)
2) create calculation using: MAX keep dense
3) create calculation using: MAX analytic function
questions, pls:
===========
a) with MAX regular, MAX keep dense, MAX - analytic function
is it necessary to sort it using tools/sort - choose fields to sort by?
or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
1) i understand that analytic functions are applied after detail row processing
does MAX keep dense calculation happen during detail row processing?
2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
tx for your ideas and assistance, sandraHi,
a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
Rod West
Maybe you are looking for
-
Hi all! I was trying to download my pictures from my iphone to my MAC for storage so that I can erase them off my iphone but could not find an easy was to do this? The whole sync operation seems cumbersome and only allows you to upload photos from yo
-
i used a mini-dvi to hmdi adapter with a hdmi to hdmi cable to connect my macbook to a tv and it works fine...then i used the same adapter with a hdmi to rca cable and it didn't work...do i need a digital to analog converter? thanks
-
How to disable Adobe Acrobat popups
I installed the turnkey solution and, when doing so, assumed that I would need PDF generator - it turns out that I don't. As a result I'm now stuck with the situation in which my Adobe Acrobat Professional trial has expired and, whenever I try to vie
-
Auto Resize of Web Analysis Screen
<p>Is it possible to get web Analysis to resize its self based onthe screen resolution of the PC.</p><p> </p><p>Problem is screens designed in one size but useres havedifferent resolutions so graphs miss the bottom axis off and noscroll bar available
-
i have a problem with FireFox keeps on crashing while i am surfing and loading pages. i always do the latest updates and i have the recent version.i would like to get help please.