习惯了用微软的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;