Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to Create Dynamic Stored Procedure

Status
Not open for further replies.

borisch

Programmer
Jun 4, 2002
11
US
I have a stored procured in SQL and I need to re-write it for ORACLE 8.
I am new in Oracle and still learning.
Please Help. Thanks a lot.

CREATE PROCEDURE SearchProductCategory
@Product as varchar(50),
@SearchTypeProd as int,
@Category as varchar(50),
@SearchTypeCat as int

AS
declare @SQL as varchar(8000)
begin
set @SQL='SELECT Name, Category
FROM Product
WHERE Deleted =0 '
if @Product<>''
begin
if @SearchTypeProd=1 -- starts with
begin
set @SQL= @SQL + ' and Name like ''' + @Product + '%'''
end
if @SearchTypeProd=2 -- ends with
begin
set @SQL= @SQL + ' and Name like ''%' + @Product + ''''
end
if @SearchTypeProd=3 -- contain
begin
set @SQL= @SQL + ' and Name like ''%' + @Product + '%'''
end
if @SearchTypeProd=4 -- Equal
begin
set @SQL= @SQL + ' and Name = ''' + @Product + ''''
end
end
if @Category<>''
begin
if @SearchTypeCat=1 -- starts with
begin
set @SQL= @SQL + ' and Category like ''' + @Category + '%'''
end
if @SearchTypeCat=2 -- ends with
begin
set @SQL= @SQL + ' and Category like ''%' + @Category + ''''
end
if @SearchTypeCat=3 -- contain
begin
set @SQL= @SQL + ' and Category like ''%' + @Category + '%'''
end
if @SearchTypeCat=4 -- Equal
begin
set @SQL= @SQL + ' and Category = ''' + @Category + ''''
end
end
--print(@SQL)
exec(@SQL)
end

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top