(用视图的好处,比如pagehelp分页只要括号级别超过三层,就是报解析错误,这是就要借助视图)
1:直接在sql中把视图当作结果集,临时表,直接放在sql中当作临时表:
1. 增加视图VW_TB_BAS_SPSX
公式为:
SELECT TB1.SPSX_KEY, TB1.CODING, TB1.RECKON_CODING,
TB1.SPSX_NAME,
(SELECT TB5.LOOKUP_NAME FROM TB_BAS_LKP TB5 WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.DATA_TYPE' AND TB5.LOOKUP_TYPE =
TB1.DATA_TYPE) AS DATA_TYPE,
(SELECT TB5.LOOKUP_NAME FROM TB_BAS_LKP
TB5 WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.DATA_MODE' AND
TB5.LOOKUP_TYPE
= TB1.DATA_MODE) AS DATA_MODE,
TB1.DISPLAY_ORDER,
(SELECT
TB5.LOOKUP_NAME
FROM TB_BAS_LKP TB5 WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.CHK_TYPE' AND
TB5.LOOKUP_TYPE =
TB1.CHK_TYPE) AS CHK_TYPE,
(SELECT TB5.LOOKUP_NAME
FROM TB_BAS_LKP TB5
WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.IS_NULL' AND
TB5.LOOKUP_TYPE =
TB1.IS_NULL) AS IS_NULL,
TB1.MIN_VAL, TB1.MAX_VAL,
TB1.CLUE_INFO,
(SELECT TB5.LOOKUP_NAME FROM TB_BAS_LKP
TB5 WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.IS_CLU_CHL' AND
TB5.LOOKUP_TYPE =
TB1.IS_CLU_CHL) AS IS_CLU_CHL,
TB1.PARENT_SPSX_KEY,
(SELECT
TB5.LOOKUP_NAME FROM TB_BAS_LKP TB5 WHERE
TB5.BUSINESS_TYPE='TB_BAS_SPSX.IS_VALID' AND TB5.LOOKUP_TYPE =
TB1.IS_VALID) AS IS_VALID,
TB1.REMARK, TB1.INPUT_UNIT, TB1.INPUT_INFO,
TB1.CHK_PARAM, TB1.ZM, TB1.EN,
TB1.ENSHORT, TB1.XSCJ, TB1.ZMEN,
(SELECT
LISTAGG(TB3.WARE_NAME, ', ') WITHIN GROUP (ORDER BY TB3.WARE_KEY)
WARE_NAME FROM TB_BAS_BED TB3 INNER JOIN TB_BAS_SPSX_TLTN TB2 ON
TB2.WARE_KEY = TB3.WARE_KEY WHERE TB1.SPSX_KEY = TB2.SPSX_KEY ) AS WARE_NAME
FROM
TB_BAS_SPSX TB1
函数:
也是放在sql中类似系统函数一样用
CREATE OR REPLACE FUNCTION FC_GET_AREANAME (
F_AREA_KEY VARCHAR2)
RETURN VARCHAR2 IS
V_AREA_LEVEL VARCHAR2(1);
V_RETNAME VARCHAR2(256);
V_AREA_FULL_NAME VARCHAR2(128);
V_COUNT INTEGER;
V_PARENT_AREA_KEY VARCHAR2(32);
BEGIN
V_RETNAME:='';
SELECT COUNT(1) INTO V_COUNT
FROM TB_BAS_AREA_FULL
WHERE AREA_KEY=F_AREA_KEY;
IF V_COUNT = 0 THEN
RETURN '??????';
END IF;
SELECT PROVINCE_NAME||CITY_NAME||COUNTY_NAME
INTO V_AREA_FULL_NAME
FROM TB_BAS_AREA_FULL
WHERE AREA_KEY=F_AREA_KEY;
RETURN V_AREA_FULL_NAME;
END;
public QueryResult findDataList(Map
throws Exception
{
StringBuffer sqlBuff = new StringBuffer();
sqlBuff.append("select A.*,FC_GET_AREANAME(A.CITY_AREA_KEY) AREA_NAME from TB_CUS_FIRM_WEB A WHERE 1 = 1");
if (searchMap != null) {
for (String key : searchMap.keySet())
{
Object obj = searchMap.get(key);
if (!BeanUtils.isNull(obj)) {
if ("customerName".equals(key)) {
sqlBuff.append(" AND (lower(trim(CHINESE_NAME)) LIKE '%'||lower(trim(:customerName))||'%' OR lower(trim(ENGLISH_NAME)) LIKE '%'||lower(trim(:customerName))||'%')");
} else if ("email".equals(key)) {
sqlBuff.append(" AND lower(trim(TRADE_MAN_EMAIL)) LIKE '%'||lower(trim(:email))||'%' ");
}
}
}
}
sqlBuff.append("AND USER_CHK='A'");
sqlBuff.append(" ORDER BY A.CUSTOMER_KEY DESC ");
return this.commonDao.findObjectsBySQL(sqlBuff.toString(), searchMap, page);
}
存储过程:
就是Java代码调用