程序员人生 网站导航

oracle 存储过程模糊查询的两种写法

栏目:Oracle时间:2014-01-31 12:49:25
习惯了用微软的SQL Server2005写 T-SQL,突然使用oracle 使用PL/SQL写SQL语句,感觉很多细节都不一样,一个模糊查询写法完全不一样

T-SQL的写法: 

USE AdventureWorks;
GO
CREATE PROCEDURE FindEmployee @EmpLName varchar(20)
AS
SELECT @EmpLName = RTRIM(@EmpLName) + '%';
SELECT c.FirstName, c.LastName, a.City
FROM Person.Contact c JOIN Person.Address a ON c.ContactID = a.AddressID
WHERE c.LastName LIKE @EmpLName;
GO
EXEC FindEmployee @EmpLName = 'Barb';

PL/SQL的写法:

create or replace procedure Query_By_Key
(
p_key1 in varchar2,
p_key2 in varchar2,
p_cursor out JN_TABLE.JN_CTable
)*
as
str_Sql varchar2(500):=' select * from TableA' ||
' where pname like :v_key1 and pname like :v_key2 ' ;
begin
open p_cursor for str_Sql using '%' || p_key1|| '%' , '%'|| p_key2||'%';
end Query_By_Key;

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐