我需要添加一對和語句到我的WHERE子句。查詢返回2年
我需要從今天返回2年的數據。我不知道如何在SQL中編寫它。我的每一件事情別人了,所以它的代碼的末尾:
FUNCTION summarize_item_search_data (p_obj_code IN VARCHAR2, p_val2 IN VARCHAR2,
p_sac IN NUMBER, p_job_type_id IN NUMBER,
p_sup IN NUMBER)
RETURN sys_refcursor
IS
stmt VARCHAR2(4000);
result_cur sys_refcursor;
BEGIN
OPEN result_cur FOR
SELECT DISTINCT jp.id, jp.row_top.mwslin AS mwslin, jp.obj_code, jp.jobload_year, jp.row_top.fiscal_year AS fiscal_year,
val1s.sac, val2s.val2, val1s.val1,
DECODE(jp.row_top.val1_id, NULL, jp.row_top.nomenclature ,val1s.nomenclature) AS nomenclature, jp.row_top.sup AS sup
FROM schedules sch, job_plans JP, master_val1 val1s, master_val2 val2s, TABLE(val2s.group_id) (+) ntab,
groups pgds
WHERE
-- stmt := stmt || ' AND ''' || p_year || ''' = ntab.fiscal_year(+)';
(val1s.sac = p_sac OR p_sac IS NULL) AND
(UPPER(val2s.val2) LIKE UPPER(p_val2) OR p_val2 IS NULL) AND
(UPPER(jp.obj_code) LIKE UPPER(p_obj_code) OR p_obj_code IS NULL) AND
(jp.row_top.sup <= p_sup OR p_sup IS NULL) AND
(jp.row_top.job_type_id = p_job_type_id OR p_job_type_id IS NULL)
AND ntab.group_id = pgds.id(+)
AND jp.row_top.val1_id = val1s.id(+)
AND val1s.val2_id = val2s.id(+)
AND jp.jobload_year >
AND fiscal_year >
RETURN result_cur;
END summarize_item_search_data;
您需要告訴我們數據類型是什麼。 – JNK
避免使用'(+)'使用古老的Oracle外部連接符號,並學習如何使用現代JOIN和LEFT JOIN表示法。 –
好的....我明天就會這樣 –