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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:13:37+00:00 2026-05-22T21:13:37+00:00

I have written pl/sql script (works, but doesn’t look nice): DECLARE v_exists NUMBER; BEGIN

  • 0

I have written pl/sql script (works, but doesn’t look nice):

DECLARE
   v_exists NUMBER;
BEGIN
   SELECT count(*) INTO v_exists FROM dba_tablespaces WHERE tablespace_name = 'hr_test';
   IF v_exists > 0 THEN
   BEGIN
      EXECUTE IMMEDIATE 'DROP TABLESPACE hr_test INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS';
   END;
   END IF;
   EXECUTE IMMEDIATE 'CREATE TABLESPACE hr_RJ DATAFILE ''E:\hr_test_01.dbf'' SIZE 16M';
END;

Is there any way to rewrite this script without EXECUTE IMMEDIATE?

  • 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-22T21:13:39+00:00Added an answer on May 22, 2026 at 9:13 pm

    No. You cannot issue DDL statements in static PL/SQL.

    And yes, it is perfectly fine to use native dynamic SQL for DDL purposes:

    You need dynamic SQL in the following
    situations:

    You want to execute a SQL data
    definition statement (such as CREATE),
    a data control statement (such as
    GRANT), or a session control statement
    (such as ALTER SESSION). In PL/SQL,
    such statements cannot be executed
    statically.

    Oracle dynamic SQL

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

Sidebar

Related Questions

I have written a SQL query that works just fine, but am having a
I have written an SQL script having the below query. The query works fine.
I have a number of manually written scripts (.sql) for tables, views and stored
Hi I have some software written in VB6.0 that uses an SQL Server, but
I have written an sql script for updating a database that runs in SQL
I have written a PHP script which generates an SQL file containing all tables
Traditionally I have always written my sql scripts by hand so they are nice
I am working with PL/SQL (Oracle). I have written queries before, but I'm not
I have written an SQL query that gets unread messages but I think I
I have written this T-SQL script to roll up duplicate rows in a database

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.