Let's take a look at the total number of queries obtained from dynamic SQL statements in Oracle stored procedures!

Source: Internet
Author: User

Simple development of PL/SQL stored procedures

Paging of stored procedure using dynamic SQL

procedure proc_goods_search_count(p_type     number,
p_keywords varchar2,
p_number out number) is
v_sql varchar2(4000);
begin
v_sql := ' select count(*)
from lt_goods a
where a.status = 2';

if p_type is not null and p_type <> 0 then
v_sql := v_sql || ' and a.goods_type =' || p_type;
end if;
if p_keywords is not null then
v_sql := v_sql || ' and a.goods_name like ''%' || p_keywords || '%''';
end if;

execute immediate v_sql
into p_number;

end proc_goods_search_count;

Obtain the Stored Procedure Definition for querying the total number of items

procedure proc_goods_search_count(p_type     number,
p_keywords varchar2,
p_number out number)

Input parameter: product type p_type, query keyword p_keywords

Outgoing parameter: Total number of queries p_number

Assemble dynamic SQL strings

v_sql varchar2(4000);

Product type filtering

 if p_type is not null and p_type <> 0 then
v_sql := v_sql || ' and a.goods_type =' || p_type;
end if;

Keyword match

 if p_keywords is not null then
v_sql := v_sql || ' and a.goods_name like ''%' || p_keywords || '%''';
end if;

Dynamically execute the SQL statement and copy and transmit the execution result to the p_number parameter.

 execute immediate v_sql
into p_number;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.