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

  • Home
  • SEARCH
  • 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 7039445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:47:57+00:00 2026-05-28T01:47:57+00:00

I want to run 100 Insert statements of the below Insert`s in a Script.

  • 0

I want to run 100 Insert statements of the below Insert`s in a Script. The schema name db1 and db2 must used in the placeholder variable SourceDatabase and TargetDatabase.

DECLARE
SourceDatabase VARCHAR2(50) := 'DB1';
TargetDatabase VARCHAR2(50) := 'DB2';

BEGIN

Insert Into TargetDatabase.TableName (SELECT  * FROM SourceDatabase.TableName);
Insert Into TargetDatabase.TableName (SELECT  * FROM SourceDatabase.TableName);
Insert Into TargetDatabase.TableName (SELECT  * FROM SourceDatabase.TableName);
...
Commit

END;

How can I write that in a dynamic way that Oracle accepts this statement?

  • 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-05-28T01:47:58+00:00Added an answer on May 28, 2026 at 1:47 am

    Do you really mean “database” in the Oracle definition of the term? Or do you mean “schema”? The pseudocode you posted appears to be assuming that SourceDatabase and TargetDatabase are schemas in a single database. If you really mean to indicate that they are separate databases, you would needd to use database links to query the remote tables.

    Assuming you mean schemas

    DECLARE
      l_src_schema varchar2(30) := 'Source';
      l_dest_schema varchar2(30) := 'Destination';
      l_sql_stmt varchar2(4000);
    BEGIN
      l_sql_stmt := 
        'INSERT INTO ' || l_dest_schema || '.table_name ' ||
        '  SELECT * FROM ' || l_src_schema || '.table_name';
      dbms_output.put_line( 'Preparing to execute: ' || l_sql_stmt;
      execute immediate l_sql_stmt;
    END;
    

    Note that it’s generally a good idea to generate the dynamic SQL statement in a separate variable that you can print out because that makes debugging the code much easier. Otherwise, if there is an error, there is no way to retrieve the actual SQL statement that your code tried to execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want run a script as follows: runner: ssh 'java program &' ssh 'java
SQL Server 2005. I want a script to run in the near future when
Please see/run the following script. DECLARE @Products Table ( PId int ) INSERT @Products
I have 100 threads. I want to run 10 thread before 10 another threads
Why this code don't work,when i want run this code vwd 2008 express show
I want to run a weekly batch process in an asp.net page. How can
I want to run a web application on php and mysql, using the CakePHP
I want to run javascript/Python/Ruby inside my application. I have an application that creates
I want to run a command as soon as a certain text appears in
I want to run a background task that reads input from a TextReader and

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.