Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CREATE OR REPLACE PROCEDURE LABWORKS.histogram
(
InputBin IN NUMBER,
InputLoc IN VARCHAR2,
InputAnl IN VARCHAR2,
InputBegDate IN DATE,
InputEndDate IN DATE
)
IS
CURSOR c_minmax IS
WITH temp AS
(
SELECT loccode,
analyte,
sample_date,
result
FROM view_histogram
WHERE loccode = InputLoc
AND analyte = InputAnl
AND TO_DATE(sample_date) BETWEEN InputBegDate AND InputEndDate
AND acode IN('$SCAN_AMBIENT','$SCAN_AMBIENT_ME','$SCAN_AMBIENT_UC','$SIM_AMBIENT',
'$SIM_AMBIENT_RI','$TO-15_AMBIENT_EPA')
)
SELECT loccode,
analyte,
MIN(display_as_num(RESULT)) AS min_result,
MAX(display_as_num(RESULT)) AS max_result
FROM temp
GROUP BY loccode, analyte
;
-- Retrive the columns needed for the report
CURSOR c_temp IS
SELECT acode,
DISPLAY_AS_NUM(result) AS result,
loccode,
analyte,
anlname,
sample_date,
sampno,
casnumb
FROM view_histogram
WHERE loccode = InputLoc
AND analyte = InputAnl
AND TO_DATE(sample_date) BETWEEN InputBegDate AND InputEndDate
AND acode IN('$SCAN_AMBIENT','$SCAN_AMBIENT_ME','$SCAN_AMBIENT_UC','$SIM_AMBIENT',
'$SIM_AMBIENT_RI','$TO-15_AMBIENT_EPA') ;
Actually, quite the opposite. I highlight person's screen names as a sign of respect to that person...Kinda like putting someone's name in lights.William said:I hope that by seeing my name in bold I have not upset you.
SELECT acode,
DISPLAY_AS_NUM(result) AS result,
loccode,
analyte,
anlname,
sample_date,
sampno,
casnumb
CREATE OR REPLACE PACKAGE BODY LABWORKS.analyte_histogram AS
/******************************************************************************
NAME: ANALYTE_HISTOGRAM
PURPOSE: If a stored procedure is used within a Crystal Report is must be
in a package and must use a REF CURSOR.
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ---------------------------------
1.0 04/19/2008 William Chadbourne 1. Created this package body.
*******************************************************************************/
PROCEDURE histogram_cnt
(InputBin IN NUMBER,
InputLoc IN VARCHAR2,
InputAnl IN VARCHAR2,
InputBegDate IN DATE,
InputEndDate IN DATE,
hist_cursor IN OUT hist_type)
/******************************************************************************
NAME: histogram_cnt
PURPOSE: To define the number of data points (bind) a user can define on
a Crystal Reports chart in the Analyte Histogram report.
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- --------------------------------
1.0 04/16/2008 William Chadbourne 1. Created this procedure.
NOTES:
******************************************************************************/
IS
BEGIN
DECLARE
v_bins NUMBER ;
v_divisor NUMBER ;
v_x1 NUMBER ;
v_x2 NUMBER ;
v_x3 NUMBER ;
v_x4 NUMBER ;
v_x5 NUMBER ;
v_x6 NUMBER ;
v_x7 NUMBER ;
v_x8 NUMBER ;
v_x_ins NUMBER ;
-- Get the minimum and maximume values of the result column
-- by loccode and Analyte.
CURSOR c_minmax IS
WITH temp AS
(
SELECT loccode,
analyte,
sample_date,
result
FROM view_histogram
WHERE loccode = InputLoc
AND analyte = InputAnl
AND TO_DATE(sample_date) BETWEEN InputBegDate AND InputEndDate
AND acode IN('$SCAN_AMBIENT','$SCAN_AMBIENT_ME','$SCAN_AMBIENT_UC','$SIM_AMBIENT',
'$SIM_AMBIENT_RI','$TO-15_AMBIENT_EPA')
)
SELECT loccode,
analyte,
MIN(DISPLAY_AS_NUM(RESULT)) AS min_result,
MAX(DISPLAY_AS_NUM(RESULT)) AS max_result
FROM temp
GROUP BY loccode, analyte
;
-- Retrieve the columns needed for the report
CURSOR c_temp IS
SELECT acode,
DISPLAY_AS_NUM(result) AS result,
loccode,
analyte,
anlname,
sample_date,
sampno,
casnumb
FROM view_histogram
WHERE loccode = InputLoc
AND analyte = InputAnl
AND TO_DATE(sample_date) BETWEEN InputBegDate AND InputEndDate
AND acode IN('$SCAN_AMBIENT','$SCAN_AMBIENT_ME','$SCAN_AMBIENT_UC','$SIM_AMBIENT',
'$SIM_AMBIENT_RI','$TO-15_AMBIENT_EPA') ;
BEGIN
-- Empty the HISTOGRAM_TEMP table
EXECUTE IMMEDIATE('TRUNCATE TABLE histogram_temp') ;
-- Pass the value entered by the user to the v_bins variable
v_bins := InputBin ;
-- Execute the first loop which determines the divisor and then
-- computes the values based upon the user selection in the
-- InputBins paramter.
FOR r_minmax IN c_minmax
-- Populate the DIVISOR variable with the result of subtractibg
-- the minimum value from the maximum value in the RESULT column
LOOP
CASE
WHEN r_minmax.max_result - r_minmax.min_result = 0 THEN
v_divisor := 0 ;
ELSE
v_divisor := (r_minmax.max_result - r_minmax.min_result) / v_bins ;
END CASE ;
-- Based upon the user's inpuutted value, calculate the ranges that each
-- individual result will fall into.
CASE
WHEN v_bins = 3 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
WHEN v_bins = 4 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
v_x4 := v_divisor * 4 ;
WHEN v_bins = 5 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
v_x4 := v_divisor * 4 ;
v_x5 := v_divisor * 5 ;
WHEN v_bins = 6 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
v_x4 := v_divisor * 4 ;
v_x5 := v_divisor * 5 ;
v_x6 := v_divisor * 6 ;
WHEN v_bins = 7 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
v_x4 := v_divisor * 4 ;
v_x5 := v_divisor * 5 ;
v_x6 := v_divisor * 6 ;
v_x7 := v_divisor * 7 ;
WHEN v_bins = 8 THEN
v_x1 := v_divisor ;
v_x2 := v_divisor * 2 ;
v_x3 := v_divisor * 3 ;
v_x4 := v_divisor * 4 ;
v_x5 := v_divisor * 5 ;
v_x6 := v_divisor * 6 ;
v_x7 := v_divisor * 7 ;
v_x8 := v_divisor * 8 ;
END CASE ;
-- Execute the second loop which inserts the value of the
-- v_x_ins variable into the range column of the
-- histogram_temp table.
FOR r_temp IN c_temp
LOOP
CASE
WHEN v_bins >= 3
AND r_temp.result BETWEEN 0 AND v_x1 THEN
v_x_ins := v_x1 ;
WHEN v_bins >= 3
AND r_temp.result > v_x1 AND r_temp.result <= v_x2 THEN
v_x_ins := v_x2 ;
WHEN v_bins >= 3
AND r_temp.result > v_x2 AND r_temp.result <= v_x3 THEN
v_x_ins := v_x3 ;
WHEN v_bins >= 4
AND r_temp.result > v_x3 AND r_temp.result <= v_x4 THEN
v_x_ins := v_x4 ;
WHEN v_bins >= 5
AND r_temp.result > v_x4 AND r_temp.result <= v_x5 THEN
v_x_ins := v_x5 ;
WHEN v_bins >= 6
AND r_temp.result > v_x5 AND r_temp.result <= v_x6 THEN
v_x_ins := v_x6 ;
WHEN v_bins >= 7
AND r_temp.result > v_x6 AND r_temp.result <= v_x7 THEN
v_x_ins := v_x7 ;
WHEN v_bins >= 8
AND r_temp.result > v_x7 AND r_temp.result <= v_x8 THEN
v_x_ins := v_x8 ;
ELSE
NULL ;
END CASE ;
IF r_temp.loccode = r_minmax.loccode AND
r_temp.analyte = r_minmax.analyte THEN
-- Insert the records into the table
INSERT INTO histogram_temp(acode,
result,
loccode,
analyte,
anlname,
sample_date,
sampno,
casnumb,
range)
VALUES(r_temp.acode,
r_temp.result,
r_temp.loccode,
r_temp.analyte,
r_temp.anlname,
r_temp.sample_date,
r_temp.sampno,
r_temp.casnumb,
v_x_ins) ;
END IF ;
END LOOP ;
END LOOP ;
-- This is the result returned to Crystal Reports
OPEN hist_cursor
FOR
SELECT *
FROM histogram_temp ;
END ;
END histogram_cnt ;
END ANALYTE_HISTOGRAM;
/
Then will this work:William said:I want the values entered by a user in the INPUTLOC and INPUTANL parameters to be strung together...
declare
str_hold varchar2(100);
begin
...
str_hold := ''''||INPUTLOC||''','''||INPUTANL||'''';
...
end;
/
...WHERE INSTR(InputLoc,LocCode) > 0
...