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