请各路高手看过来,有关jboss4.0.1sp1下调用oracle9i函数,返回结果集操作游标时的异常怪问题,急!(附java及oracle函数源码)

05-12-19 zmg229
本人在标题所示版本的jboss下,调用oracle 9i function时,在对结果集游标操作时,获取结果集的记录条数时,遇到异常,信息如下:
13:26:56,348 ERROR [CustomerHandle] [CInfo][3] error ocurred while getCustomerList.
13:26:56,364 ERROR [CustomerHandle] [CInfo][3] error message: 对只转发结果集的无效操作: last
13:26:56,442 INFO [STDOUT] java.sql.SQLException: 对只转发结果集的无效操作: last
13:26:56,474 INFO [STDOUT] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
13:26:56,474 INFO [STDOUT] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
13:26:56,474 INFO [STDOUT] at oracle.jdbc.driver.BaseResultSet.last(BaseResultSet.java:81)
13:26:56,474 INFO [STDOUT] at com.navitone.wap.util.Pager.init(Pager.java:370)
13:26:56,489 INFO [STDOUT] at com.navitone.wap.cinf.CustomerDAO.getCustomerList(CustomerDAO.java:80)
13:26:56,489 INFO [STDOUT] at com.navitone.wap.cinf.CustomerHandle.getCustomerList(CustomerHandle.java:46)
13:26:56,489 INFO [STDOUT] at org.apache.jsp.wap.jpln.cust_005flist_jsp._jspService(cust_005flist_jsp.java:110)
13:26:56,489 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
13:26:56,489 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
13:26:56,489 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
13:26:56,489 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
13:26:56,489 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
13:26:56,489 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
13:26:56,489 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
13:26:56,489 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
13:26:56,505 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
13:26:56,505 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:150)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
13:26:56,505 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
13:26:56,505 INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
13:26:56,505 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
13:26:56,505 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
13:26:56,505 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
13:26:56,505 INFO [STDOUT] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
13:26:56,505 INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
13:26:56,505 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
13:26:56,521 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
......
----------------------------------------------------------
以下是java方法:
public Collection getCustomerList(String simCardNo, int customerType,
String customerName, String customerCode, int findType,
int customerGroupID, Connection conn, Pager pager)
throws SQLException {
Collection collection = new ArrayList();
/* temporary CustomerData object */
CustomerData customerData = null;
CallableStatement call = null;
ResultSet rs = null;
int retVal = -1;

try {
call = conn.prepareCall("{? = call mrm_user_customers_find(?,?,?,"
+ " ?,?,?,?,?)}", ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// call = conn.prepareCall("{? = call mrm_user_customers_find(?,?,?,"
// + " ?,?,?,?,?)}", oracle.jdbc.OracleResultSet.TYPE_SCROLL_SENSITIVE,
// oracle.jdbc.OracleResultSet.CONCUR_UPDATABLE);

call.registerOutParameter(1, oracle.jdbc.OracleTypes.NUMBER);
call.registerOutParameter(9, oracle.jdbc.OracleTypes.CURSOR);

call.setString(2, simCardNo);
call.setInt(3, customerType);
call.setString(4, customerName);
call.setString(5, customerCode);
call.setInt(6, findType);
call.setInt(7, customerGroupID);
/* @SortType int = 0 -- 0: 不排序;1: 按时间升序;2:按时间降序; */
call.setInt(8, 2);

call.execute();

retVal = call.getInt(1);
// rs = ((OracleCallableStatement) call).getCursor(9);
rs = (ResultSet) call.getObject(9);

pager.init(rs);
while (pager.nextRow(rs)) {
customerData = new CustomerData();
customerData.setCustomer_id(rs.getInt("customer_id"));
customerData.setCustomer_type(rs.getInt("type"));
customerData.setName(rs.getString("name"));
customerData.setClassType(rs.getInt("class_type"));
customerData.setUserId(rs.getInt("user_id"));
collection.add(customerData);
}
} catch (SQLException se) {
throw se;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) {
rs.close();
}
if (call != null) {
call.close();
}
}

return collection;
}
......
public void init(ResultSet rs) throws SQLException {
// this.rowCount = rowCount;
if (!this.bIsPager)
return;

// 每页最大记录数默认是20
if (this.pageSize == 0)
this.pageSize = DEFAULT_PAGE_SIZE;

// 当前页码默认为1
if (this.showPage == 0)
this.showPage = 1;

if (rs.next()) {
// 得到总记录数
rs.last();
this.rowCount = rs.getRow();
} else { //无记录
this.bIsPager = false;
return;
}

// 计算总页数
this.pageCount = (this.rowCount + this.pageSize - 1) / this.pageSize;
// 调整待显示的页码
if (this.showPage > this.pageCount)
this.showPage = this.pageCount;

this.offSet = (this.showPage - 1) * this.pageSize;

rs.beforeFirst();

// for JDBC 1.x and up
for (int i = 0; i < this.offSet; i++)
rs.next();

// for JDBC 2.x and up
//rs.absolute(this.offSet);

}
......
-------------------------------------------------------------
以下是oracle 9i funtion 定义:
CREATE OR REPLACE FUNCTION mrm_user_customers_find (
p_Mobile varchar2, -- 手机号码
p_CustomerType int := 0, -- 0: company_info; 1: contact_info, 2: all
p_CustomerName varchar2 :='', -- 通讯录名
p_CustomerCode varchar2 :='', -- 通讯录编号
p_FindType int := 1, -- 0: 精确匹配;1: 模糊查找
p_CustomerGroupID int := -1, -- -1:在所有组范围内查找;其他值:在相应的customer_groups[id]内查找
p_SortType int := 0, -- 0: 不排序;1: 按时间升序;2:按时间降序;
p_cursor OUT pkg_cursor.cur
)
RETURN NUMBER
AS
v_retcode int:=0;
v_UserID int:=0;
--v_ret int:=0;
/******************************************************************************
Name:
mrm_user_customers_find
Description :

Return value :
>=0 :success; <0 :error_code
NOTES:

Version :
for MRM V2.0.0

REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2005-11-14 Song 1. Created this procedure.

******************************************************************************/
BEGIN
v_retcode:= 0;

SELECT rv.user_id
INTO v_UserID
FROM device dv, rover rv
WHERE dv.simCardNO=p_Mobile
and dv.device_id=rv.device_id;

v_retcode := mrm_sys_customers_find (v_UserID,3,p_CustomerType,p_CustomerName,p_CustomerCode,
p_FindType, p_CustomerGroupID, p_SortType, p_cursor);

RETURN v_retcode;
EXCEPTION
WHEN OTHERS THEN
v_retcode:= ERRCODE;
RETURN v_retcode;
END mrm_user_customers_find;
/
--------------------------------------------------------------
CREATE OR REPLACE FUNCTION mrm_sys_customers_find(
p_ObjectID int,-- 若ObjectType=1, 为要列表的公司客户的ID,对应clients[id]
-- 若ObjectType=2, 为要列表的用户组的ID,对应users_group[id]
-- 若ObjectType=3, 为要列表的用户的ID,对应users[id]
p_ObjectType int, -- 若为1,表示@ObjectID为ClientID,若为2,表示为GroupID,若为3,表示为UserID
p_CustomerType int := 0, -- 0: company_info; 1: contact_info, 2: all
p_CustomerName varchar2:='', -- 通讯录名
p_CustomerCode varchar2:='', -- 通讯录编号
p_FindType int := 1, -- 0: 精确匹配;1: 模糊查找
p_CustomerGroupID int := -1, -- -1:在所有组范围内查找;其他值:在相应的customer_groups[id]内查找
p_SortType int := 0, -- 0: 不排序;1: 按时间升序;2:按时间降序;
p_cursor OUT pkg_cursor.cur
)RETURN NUMBER
/******************************************************************************
Description :
通过给定的ObjectID及ObjectID类型(CustomerType),查找所有它所能访问的通讯录。
例如,当@ObjectType为3时,表示为UserID,则找出所有该UserID能访问的通讯录,并且名字为test。
虽然参数中带有CustomerName和CustomerCode两个查找参数,但只有当他们不为空时才会做为查找
条件。若都为空则返回所有记录,与mrm_sys_customers_list返回的结果相同。
Return value :
=0 :success; <0 :error
Version :
for MRM V2.0.0
Modify log :
2005-11-14 张 创建
******************************************************************************/
AS
strCompanyFields varchar2(2000):=' ';
strContactFields varchar2(2000):=' ';
strCompanySql varchar2(10000):=' ';
strContactSql varchar2(2000):=' ';
strConditionSql varchar2(2000):=' ';
v_ClientID int:=0;
v_GroupID int:=0;
v_UserID int:=0;
v_UserType int:=-1;

MACRO_COMPANY_INFO int:=0;
MACRO_CONTACT_INFO int:=1;
MACRO_ALL_INFO int:=2;
MACRO_CLIENT_TYPE int:=1;
MACRO_GROUP_TYPE int:=2;
MACRO_USER_TYPE int:=3;
MACRO_GROUP_T int:=0;
MACRO_MEMBER_T int:=1;
BEGIN

if p_ObjectType = MACRO_USER_TYPE then
v_UserID := p_ObjectID;
select u.user_type,u.group_id,u.client_id
into v_UserType,v_GroupID,v_ClientID
from users u
where u.id=v_UserID;
elsif p_ObjectType = MACRO_GROUP_TYPE then
select client_id into v_ClientID
from user_groups
where id=p_ObjectID;

v_GroupID := p_ObjectID;
v_UserType := MACRO_GROUP_TYPE;
elsif p_ObjectType = MACRO_CLIENT_TYPE then
v_ClientID := p_ObjectID;
v_UserType := MACRO_CLIENT_TYPE;
else
return -10;
end if;


if len(p_CustomerName) > 0 then
if p_FindType = 1 then
strConditionSql := strConditionSql||' and ct.name like ''%'||p_CustomerName||'%''';
else
strConditionSql := strConditionSql||' and ct.name = '''||p_CustomerName||'''';
end if;
end if;

if len(p_CustomerCode) > 0 then
if p_FindType = 1 then
strConditionSql := strConditionSql||' and ct.customer_code like ''%'||p_CustomerCode||'%''';
else
strConditionSql := strConditionSql||' and ct.customer_code = '''||p_CustomerCode||'''';
end if;
end if;

if p_CustomerGroupID > -1 then
strConditionSql := strConditionSql||' and ct.customer_group_id = '||to_char(p_CustomerGroupID);
end if;

if p_CustomerType = MACRO_ALL_INFO then
strCompanyFields := '( select '||to_char(p_ObjectID)||' as object_id, ct.id as customer_id, ct.user_id, ct.xml_customer_id, ct.name, ct.type, ct.sub_id, ct.create_time, ct.descinfor,
ct.customer_code, ct.customer_group_id, ct.group_id, ct.client_id, ct.class_type,
geo.latitude, geo.longitude, geo.house_number, geo.street, geo.cross_street, geo.county, geo.city,
geo.state, geo.landmark, geo.create_time ,
info.telephone1, info.telephone2, info.fax, info.email, info.operation, info.tax_no, info.bank_no,
info.create_time, info.business_info, info.operation_type, info.ifchecked,
null as gender, null as age, null as favorite, null as home_tel, null as office_tel, null as responsibility ';

strContactFields := '( select '||to_char(p_ObjectID)||' as object_id, ct.id as customer_id, ct.user_id, ct.xml_customer_id, ct.name, ct.type, ct.sub_id, ct.create_time, ct.descinfor,
ct.customer_code, ct.customer_group_id, ct.group_id, ct.client_id, ct.class_type,
geo.latitude, geo.longitude, geo.house_number, geo.street, geo.cross_street, geo.county, geo.city,
geo.state, geo.landmark, geo.create_time,
null as telephone1, null as telephone2, null as fax, info.email, null as operation, null as tax_no, null as bank_no,
info.create_time, info.business_info, info.operation_type, null as ifchecked,
info.gender, info.age, info.favorite, info.home_tel, info.office_tel, info.responsibility ';
elsif p_CustomerType = MACRO_COMPANY_INFO then
strCompanyFields := '( select '||to_char(p_ObjectID)||' as object_id, ct.id as customer_id, ct.user_id, ct.xml_customer_id, ct.name, ct.type, ct.sub_id, ct.create_time, ct.descinfor,
ct.customer_code, ct.customer_group_id, ct.group_id, ct.client_id, ct.class_type,
geo.latitude, geo.longitude, geo.house_number, geo.street, geo.cross_street, geo.county, geo.city,
geo.state, geo.landmark, geo.create_time ,
info.telephone1, info.telephone2, info.fax, info.email, info.operation, info.tax_no, info.bank_no,
info.create_time, info.business_info, info.operation_type, info.ifchecked ';
elsif p_CustomerType = MACRO_CONTACT_INFO then
strContactFields := '( select '||to_char(p_ObjectID)||' as object_id, ct.id as customer_id, ct.user_id, ct.xml_customer_id, ct.name, ct.type, ct.sub_id, ct.create_time, ct.descinfor,
ct.customer_code, ct.customer_group_id, ct.group_id, ct.client_id, ct.class_type,
geo.latitude, geo.longitude, geo.house_number, geo.street, geo.cross_street, geo.county, geo.city,
geo.state, geo.landmark, geo.create_time,
info.email, info.create_time, info.business_info, info.operation_type, info.gender, info.age,
info.favorite, info.home_tel, info.office_tel, info.responsibility ';
end if;

if p_CustomerType = MACRO_COMPANY_INFO or p_CustomerType = MACRO_ALL_INFO then
strCompanySql := CONCAT(strCompanySql,strCompanyFields);

if v_UserType = MACRO_CLIENT_TYPE then
strCompanySql := strCompanySql
||' from customer ct, customer_geo_info geo, company_info info '
||' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
|| strConditionSql
||' ) ';

elsif v_UserType = MACRO_GROUP_TYPE then
-- 属于该GroupID组的所有CustomerID
strCompanySql := strCompanySql
||' from customer ct, customer_geo_info geo, company_info info '
||' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.group_id='||to_char(v_GroupID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID授权的CustomerID组
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt ';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.customer_group_id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_id = '||to_char(v_GroupID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID授权的单个CustomerID
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_id = '||to_char(v_GroupID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID组中成员授权的CustomerID组
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and cgt.which_id = ct.customer_group_id '
||' and cgt.which_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_id = '||to_char(v_UserID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID组中成员授权的单个CustomerID
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt, users u ';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_id = u.id'
||' and u.group_id = '||to_char(v_GroupID)
||' and (u.id = '||to_char(v_UserID)||' or 0='||to_char(v_UserID)|| ')'
|| strConditionSql
||' ) ';

elsif v_UserType = MACRO_USER_TYPE then
-- 属于该UserID组的所有CustomerID
strCompanySql := strCompanySql
||' from customer ct, customer_geo_info geo, company_info info, customer_groups cg '
||' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.user_id='||to_char(v_UserID)
--||' and (ct.customer_group_id = cg.id or ct.customer_group_id = 0 )' ---默认组里的客户
--||' and (ct.customer_group_id = 0 or (ct.customer_group_id = cg.id and cg.user_id = ct.user_id'-- + CAST(@UserID as varchar(20)) --Add by hx: 增加对用户权限的判断
||' and ( ct.customer_group_id = 0 or (ct.customer_group_id = cg.id and cg.user_id = ct.user_id) or (ct.customer_group_id IN (select cg.id from customer c, customer_groups cg, customer_grant cgt where cgt.which_id = c.id and cgt.which_type = 1 and c.customer_group_id = cg.id and cgt.who_type = 1 and cgt.who_id =' ||to_char(v_UserID)|| ' UNION select cg.id from customer c, customer_groups cg, customer_grant cgt where cgt.which_id = c.id and cgt.which_type = 1 and c.customer_group_id = cg.id and cgt.who_type = 0 and cgt.who_id ='||to_char(v_GroupId)||')'--Add by hx: 增加对用户权限的判断
||'))'
|| strConditionSql
||' ) ';
-- 联合对该UserID授权的CustomerID组
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.customer_group_id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_id = '||to_char(v_UserID)
|| strConditionSql
||' ) ';
-- 联合对该UserID授权的单个CustomerID
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '

||' and ct.client_id='||to_char(v_ClientID)
||' and ct.id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_id = '||to_char(v_UserID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID组中成员授权的CustomerID组
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and cgt.which_id = ct.customer_group_id '
||' and cgt.which_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_id = '||to_char(v_GroupID)
|| strConditionSql
||' ) ';
-- 联合对该GroupID授权的单个CustomerID
strCompanySql := strCompanySql || ' UNION ';
strCompanySql := strCompanySql || strCompanyFields;
strCompanySql := strCompanySql || ' from customer ct, customer_geo_info geo, company_info info, customer_grant cgt';
strCompanySql := strCompanySql || ' where geo.id=info.customer_geo_info_id '
||' and ct.sub_id=info.id '
||' and ct.type = 0 '
||' and ct.client_id='||to_char(v_ClientID)
||' and ct.id = cgt.which_id '
||' and cgt.which_type = '||to_char(MACRO_MEMBER_T)
||' and cgt.who_type = '||to_char(MACRO_GROUP_T)
||' and cgt.who_id = '||to_char(v_GroupID)
|| strConditionSql
||' ) ';

end if;
end if;

if p_CustomerType = MACRO_CONTACT_INFO or p_CustomerType = MACRO_ALL_INFO
then
if p_ObjectType = MACRO_CLIENT_TYPE
then
strContactSql := strContactFields
|| ' from customer ct, customer_geo_info geo, users u, contact_info info'
|| ' where geo.id=info.customer_geo_info_id '
|| ' and ct.sub_id=info.id '
|| ' and ct.type = 1 '
|| ' and u.client_id= '||to_char(v_ClientID)
|| ' and u.id = ct.user_id'
|| strConditionSql
|| ' ) ';
elsif p_ObjectType = MACRO_GROUP_TYPE then
strContactSql := strContactFields
|| ' from customer ct, customer_geo_info geo, users u, contact_info info'
|| ' where geo.id=info.customer_geo_info_id '
|| ' and ct.sub_id=info.id '
|| ' and ct.type = 1 '
--|| ' and u.group_id='||to_char(GroupID)
|| ' and u.id = ct.user_id'
|| strConditionSql
|| ' ) ';

elsif p_ObjectType = MACRO_USER_TYPE then
strContactSql := strContactFields
|| ' from customer ct, customer_geo_info geo, users u, contact_info info'
|| ' where geo.id=info.customer_geo_info_id '
|| ' and ct.sub_id=info.id '
|| ' and ct.type = 1 '
|| ' and ct.user_id = u.id'
|| ' and u.id = '||to_char(v_UserID)
|| strConditionSql
|| ' ) ';
end if;
end if;


if p_CustomerType =MACRO_COMPANY_INFO
then
if p_SortType>0 then
strCompanySql := strCompanySql || ' order by 8/*ct.create_time*/';
end if;
if p_SortType=1 then
strCompanySql := strCompanySql || ' asc';
elsif p_SortType=2 then
strCompanySql := strCompanySql || ' desc';
end if;
open p_cursor for strCompanySql;
--print strCompanySql

elsif p_CustomerType = MACRO_CONTACT_INFO then
if p_SortType>0 then
strContactSql := strContactSql || ' order by 8/*ct.create_time*/';
end if;
if p_SortType=1 then
strContactSql := strContactSql || ' asc';
elsif p_SortType=2 then
strContactSql := strContactSql || ' desc';
end if;
open p_cursor for strContactSql;
else
if p_SortType>0 then
strContactSql := strContactSql || ' order by 8/*ct.create_time*/';
end if;
if p_SortType=1 then
strContactSql := strContactSql || ' asc';
elsif p_SortType=2 then
strContactSql := strContactSql || ' desc';
end if;
open p_cursor for strCompanySql || ' UNION ALL ' || strContactSql;
end if;
return 0;
EXCEPTION
WHEN OTHERS THEN
RETURN ERRCODE;
END mrm_sys_customers_find;
/

在线等 ,请高手不吝赐教......