Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:44:40+00:00 2026-06-18T00:44:40+00:00

I’m new to Oracle PL/SQL. In my database I created a table PERSONS :

  • 0

I’m new to Oracle PL/SQL. In my database I created a table PERSONS:

person_id int
first_name nvarchar(50)
last_name nvarchar(50)
birth_date datetime
email varchar(80)

The first stored procedure tester_sp takes one parameter @sptotest for searching time in millisecond of the words. The other procedure search_sp takes one parameter @word and shows how the word to be searched (in this stored procedure I’m using a LIKE clause).

First stored procedure tester_sp:

CREATE PROCEDURE tester_sp

DECLARE @d            datetime,
       @tookms       int,
       @cnt          int,
       @single_email varchar(80),
       @word         varchar(50)

DECLARE @testwords TABLE
       (no   int         NOT NULL PRIMARY KEY,
        word varchar(80) NOT NULL)

CREATE TABLE #temp(person_id  int          NOT NULL PRIMARY KEY,
                  first_name nvarchar(50) NULL,
                  last_name  nvarchar(50) NOT NULL,
                  birth_date datetime     NULL,
                  email      varchar(80)  NOT NULL)

-- Select one email address
SELECT TOP 1 @single_email = email
FROM   persons
WHERE  person_id BETWEEN 321106 AND 325000 AND  email LIKE '%.com'
ORDER  BY person_id

-- This is the list of testword(joy and email)
INSERT @testwords(no, word)
  SELECT 1, 'joy'
  UNION ALL
  SELECT 4, @single_email

PRINT '------------------ Testing ' + ' ' + quotename(@sptotest) + ' ----'

DECLARE cur CURSOR STATIC LOCAL FOR
  SELECT word FROM @testwords ORDER BY no
OPEN cur

WHILE 1 = 1
BEGIN
  FETCH cur INTO @word
  IF @@fetch_status <> 0
     BREAK

  TRUNCATE TABLE #temp

  CHECKPOINT
  DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS

  -- Run the procedure and read all from disk.
  SELECT @d = getdate()
  INSERT #temp
     EXEC @sptotest @word
  SELECT @tookms = datediff(ms, @d, getdate())
  SELECT @cnt = COUNT(*) FROM #temp
  PRINT ltrim(str(@tookms)) + ' ms, ' +
        ltrim(str(@cnt)) + ' rows. Word = "' + @word + '". Data in disk.'

  -- Run it again with data in cache.
  TRUNCATE TABLE #temp
  SELECT @d = getdate()
  INSERT #temp
     EXEC @sptotest @word
  SELECT @tookms = datediff(ms, @d, getdate())
  SELECT @cnt = COUNT(*) FROM #temp
  PRINT ltrim(str(@tookms)) + ' ms, ' +
        ltrim(str(@cnt)) + ' rows. Word = "' + @word + '". Data in cache.'

  END

  DEALLOCATE cur

Second stored procedure search_sp:

CREATE PROCEDURE search_sp @word varchar(50) 
AS
SELECT person_id, first_name, last_name, birth_date, email
FROM   persons WHERE email LIKE '%' + @word + '%'

Executing the storing procedures:

EXEC tester_sp 'search_sp'

The result of execution is:

------------------ Testing  [search_sp] ----
6146 ms, 10 rows. Word = "joy". Data in disk
5586 ms, 10 rows. Word = "joy". Data in cache.
6280 ms, 1 rows. Word = "omamo@petinosemdesetletnicah.com". Data in disk
5943 ms, 1 rows. Word = "omamo@petinosemdesetletnicah.com". Data in cache.    

My question is: how to convert the whole process using stored procedures in Oracle database 11g using PL/SQL? Please help. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:44:41+00:00Added an answer on June 18, 2026 at 12:44 am

    Creating tables:

    create table PERSONS (
        person_id  integer not null, 
        first_name nvarchar2(50 char),
        last_name  nvarchar2(50 char) not null, 
        birth_date date, 
        email      varchar2(80 char),
        PRIMARY KEY (person_id)
    );
    
    CREATE global temporary TABLE temp_persons (
        person_id  integer not null,
        first_name nvarchar2(50 char),
        last_name  nvarchar2(50 char) NOT NULL,
        birth_date date,
        email      varchar2(80 char)  NOT NULL,
        PRIMARY KEY (person_id)
    ) on commit delete rows;
    

    Stored procedure:

    CREATE PROCEDURE tester_sp as
       start        timestamp;
       diff         interval day to second;
       tookms       integer;
       cnt          integer;
       single_email varchar2(80 char);
       msg          varchar2(1000 char);
    begin
        -- Select one email address
        SELECT email
          into   single_email
          FROM   persons
          WHERE  person_id BETWEEN 321106 AND 325000 
            AND  email LIKE '%.com'
            and rownum = 1;
    
        dbms_output.put_line('------------------ Testing ----');
    
        for r in (
          with testwords as (  
            -- This is the list of testword(joy and email)
            SELECT 1 as no, 'joy' as word from dual
            UNION ALL
            SELECT 4, single_email from dual)
          SELECT word 
          FROM testwords 
          ORDER BY no) loop
    
            -- Run the procedure twice
            for pass in 1..2 loop
              start := systimestamp;
              INSERT into temp_persons (person_id, first_name, last_name, birth_date, email)
                SELECT person_id, first_name, last_name, birth_date, email
                FROM   persons 
                WHERE  email LIKE '%'||r.word||'%';
              cnt := sql%rowcount;
              diff := systimestamp - start;
              tookms := round(1000 * ( 
                extract(hour from diff)   * 3600 +
                extract(minute from diff) * 60   +
                extract(second from diff))); 
              msg := to_char(tookms)||' ms, '||to_char(cnt)||' rows. Word = "'||r.word||'". ';
              if pass = 1 then
                msg := msg||'Data on disk.';
              else
                msg := msg||'Data in cache.';
              end if;
              dbms_output.put_line(msg);
              rollback; -- instead of 'TRUNCATE TABLE temp_persons'
            end loop;
    
        end loop;
    end;
    

    Executing the stored procedure:

    begin
        tester_sp;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am confused How to use looping for Json response Array in another Array.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.