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 9203949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:35:26+00:00 2026-06-17T23:35:26+00:00

I want to convert manually below stored procedure from T-SQL(MS SQL Server 2008) to

  • 0

I want to convert manually below stored procedure from T-SQL(MS SQL Server 2008) to P-SQL(Oracle DB 11g). I recently try to convert this procedure using SQL Developer and SwisSQL Tool, but without success. This stored procedure contains one parameter @sptotest for the searching one word. Here is the code:

T-SQL:

CREATE PROCEDURE sp_name @sptotest sysname AS

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 TOP 1 @single_email = email
FROM   persons
WHERE  person_id BETWEEN 321106 AND 325000 AND  email LIKE '%.com'
ORDER  BY person_id


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


  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 + '".'


  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

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-17T23:35:27+00:00Added an answer on June 17, 2026 at 11:35 pm

    You can’t create a table inside a procedure directly. You have to use execute immediate to create a global temporary table. You would need to use declare

    A cursor declaration must be in declaration part that mean above the begin statement.

    I tried to correct the possible errors and I didn not test it, because I don’t have an instance. Please do the modifications as needed based on my example.

    Small Example for Execute Immediate #

    begin
      execute immediate 'create table t23 as  select ''1'' aa from dual'; 
      execute immediate 'update t23 set aa =''2'' where aa=''1''';
      COMMIT ;
    end;
    
    And your Proc Follows
    
    create or replace procedure test_sp 
    (
    sptotest in varchar2 default null
    )
     as
    d date;
    tookms number;
    cnt number;
    single_mail varchar2(80);
    word varchar2(50);
    
    cursor cur is select word from testwords order by no;
    
    begin
    execute immediate ('create global temporary table testwords
    (
    no     int          not null,
    word   varchar2(80) not null,
    PRIMARY KEY(no)
    )');
    
    execute immediate ('create global temporary table temp
    (
    person_id   int           not null,
    first_name  nvarchar2(50) null,
    last_name   nvarchar2(50) not null,
    birth_date  date          null,
    email       varchar2(80)  not null,
    PRIMARY KEY(person_id)
    )');
    
    select Colm_name into Variable_name
    from persons
    where person_id between 311106 and 32500 and email like '%.com'
    order by person_id;
    
    insert into testwords
    (
    no, 
    word
    )
    select 1, 'joy' from Table_name1
    union all
    select 4, single_email from Table_name2;
    
    DBMS_OUTPUT.PUT_LINE(  '------------------ Testing '  || ' '  || CAST(sptotest AS  VARCHAR2)  || ' ----');  
    
    open cur; 
     -- Cursor Processing
    Close Cur;
    end test_sp;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve rows from an oracle table and convert them into objects.
I want to convert sqlite query to Ormlite query. SELECT * FROM Test where
I know C# and I want to convert this code into VB.NET. lol.Navigated +=
I want to convert a big csv file from gb2312 encoding to UTF-8 encoding.
I want to convert /Users/Irwan/Documents/test.jpg into MyMac:Users:Irwan:Documents:test.jpg I can do that manually but I
I want to convert a number of unicode codepoints read from a file to
I have DataReader that holds the results from a stored procedure caal. The results
I want to convert a string to formatted text in C# in WPF application,
I want to convert all the URLs in a javascript string to links, in
I want to convert a column of numbers to numeric, but there are certain

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.