如何使用substr函数验证过滤器,并从Oracle PLSQL中的存储过程中获取结果?
我创建了一个存储过程,在where子句中有两个过滤器。我已经包含了一个过滤器,并且能够得到结果。但是,当我尝试包含第二个过滤器时,该过程没有显示任何值 用户从UI屏幕输入参数并单击搜索按钮 UI屏幕:如何使用substr函数验证过滤器,并从Oracle PLSQL中的存储过程中获取结果?,oracle,input,where-clause,procedure,substr,Oracle,Input,Where Clause,Procedure,Substr,我创建了一个存储过程,在where子句中有两个过滤器。我已经包含了一个过滤器,并且能够得到结果。但是,当我尝试包含第二个过滤器时,该过程没有显示任何值 用户从UI屏幕输入参数并单击搜索按钮 UI屏幕: Procedure search_emp ( pt_id in number, pt_name in varchar2, pt_country i
Procedure search_emp ( pt_id in number,
pt_name in varchar2,
pt_country in varchar2,
empCursor out ref cursor)
as
v_countrycode CHAR(2);
v_count NUMBER;
begin
SELECT count(*) INTO v_count FROM r_country where UPPER(country) = UPPER(pt_country);
IF v_count > 0 THEN
SELECT countrycode INTO v_countrycode FROM r_country where UPPER(country) = UPPER(pt_country);
ELSE NULL;
END IF; -- here, am trying to get the country code from the table for the input parameter 'pt_country' that is passed.
open empCursor for
select e.emp_id,
e.name,
e.phone_number
from employee e
where upper(e.emp_id) = upper(pt_emp_id)
and (UPPER(substr(e.phone_number,1,2)) LIKE UPPER(v_countrycode) or pt_country IS NULL);
--- I'm not sure how to get the results when the User gives a value to the input parameter 'pt_country'.
END;
Emp ID:\uuuuuuuuuuuuuuuuuuuuuuuuuuu
国家:__________
Search button Cancel button
数据来自Oracle数据库中名为Employee的表
员工表:
Procedure search_emp ( pt_id in number,
pt_name in varchar2,
pt_country in varchar2,
empCursor out ref cursor)
as
v_countrycode CHAR(2);
v_count NUMBER;
begin
SELECT count(*) INTO v_count FROM r_country where UPPER(country) = UPPER(pt_country);
IF v_count > 0 THEN
SELECT countrycode INTO v_countrycode FROM r_country where UPPER(country) = UPPER(pt_country);
ELSE NULL;
END IF; -- here, am trying to get the country code from the table for the input parameter 'pt_country' that is passed.
open empCursor for
select e.emp_id,
e.name,
e.phone_number
from employee e
where upper(e.emp_id) = upper(pt_emp_id)
and (UPPER(substr(e.phone_number,1,2)) LIKE UPPER(v_countrycode) or pt_country IS NULL);
--- I'm not sure how to get the results when the User gives a value to the input parameter 'pt_country'.
END;
Emp\u id----姓名------电话号码------国家
1----约翰·史密斯----US-765-234-4567----美国
2---Sam Benigal---AL-978-346-765----阿根廷
3----马克·泰勒----AS-987-3987-857----澳大利亚
4----克莱尔·弗纳---加拿大CA-85-454-5454
对于第二个过滤器,我需要使用包含以countrycode开头的数据的电话号码(“美国国家的US-765-234-4567”;阿根廷国家的“AR-978-346-765”;澳大利亚国家的“AS-987-3987-857…”等)并与输入参数“pt_country”匹配以生成结果。
我在这个场景中使用了Substring函数,因为根据电话号码中的前两个字符,我需要得到结果
此外,输入参数“pt_country”可以有值,也可以为空
代码:
Procedure search_emp ( pt_id in number,
pt_name in varchar2,
pt_country in varchar2,
empCursor out ref cursor)
as
v_countrycode CHAR(2);
v_count NUMBER;
begin
SELECT count(*) INTO v_count FROM r_country where UPPER(country) = UPPER(pt_country);
IF v_count > 0 THEN
SELECT countrycode INTO v_countrycode FROM r_country where UPPER(country) = UPPER(pt_country);
ELSE NULL;
END IF; -- here, am trying to get the country code from the table for the input parameter 'pt_country' that is passed.
open empCursor for
select e.emp_id,
e.name,
e.phone_number
from employee e
where upper(e.emp_id) = upper(pt_emp_id)
and (UPPER(substr(e.phone_number,1,2)) LIKE UPPER(v_countrycode) or pt_country IS NULL);
--- I'm not sure how to get the results when the User gives a value to the input parameter 'pt_country'.
END;
请提供帮助。尝试以下步骤,需要将游标定义为SYS\u REFCURSOR以获取输出
create or replace Procedure search_emp ( pt_emp_id in number,
pt_name in varchar2,
pt_country in varchar2,
empCursor out SYS_REFCURSOR)
as
v_countrycode CHAR(2);
v_count NUMBER;
begin
SELECT count(*) INTO v_count FROM r_country where UPPER(country) = UPPER(pt_country);
IF v_count > 0 THEN
SELECT countrycode INTO v_countrycode FROM r_country where UPPER(country) = UPPER(pt_country);
ELSE NULL;
END IF; -- here, am trying to get the country code from the table for the input parameter 'pt_country' that is passed.
open empCursor for
select e.emp_id,
e.name,
e.phone_number
from employee e
where upper(e.emp_id) = upper(pt_emp_id)
and (UPPER(substr(e.phone_number,1,2)) LIKE UPPER(v_countrycode) or pt_country IS NULL);
--- I'm not sure how to get the results when the User gives a value to the input parameter 'pt_country'.
END;
使用单个查询获得以下结果:
Select e.emp_id,
e.name,
e.phone_number
from employee e
Join r_country c
On (e.phone_number like c.countrycode || '-%')
Where upper(e.emp_id) = upper(pt_emp_id)
And UPPER(c.country) = UPPER(COALESCE(pt_country, c.COUNTRY))
干杯 另外,输入参数在调用pt_id和使用inside block时不同,因为pt_emp_idI尝试了上述两种解决方案。但是,它们不起作用。请帮忙!在UI中没有任何概念。。但是当我在后端运行这个过程时,我能够得到结果,代码运行得很好。但是,表中countrycode列存在数据问题,导致筛选器无法工作。有些国家代码有空格。谢谢kanagraj和Tejash的回复。