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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:00:47+00:00 2026-06-03T09:00:47+00:00

I am trying to drop tables, which have a particular suffix(passed as argument $1),

  • 0

I am trying to drop tables, which have a particular suffix(passed as argument $1), using shell script.

If a parent table is selected without its child tables being dropped, I am bypassing the parent table and increasing the counter in the exception block.

When I run this script in sql developer with $1 replaced with the proper value, it works. But when I run this shell script, it is getting stuck.

Could you please have a look and let me know, what am I missing in the shell script?

Code:

#!/bin/bash

cat <<ENDDROPNEWTABS >dropnewtabs.sql
set pagesize 100

DECLARE

t_cnt NUMBER;
CURSOR C001
IS
SELECT table_name FROM user_tables WHERE table_name LIKE '%$1%';

BEGIN
BEGIN SELECT COUNT(*) INTO t_cnt FROM user_tables WHERE table_name LIKE '%$1%'; 
END;

WHILE(t_cnt > 0) LOOP
FOR i IN C001 LOOP
BEGIN EXECUTE IMMEDIATE 'DROP TABLE '||i.table_name;
EXCEPTION
WHEN OTHERS THEN
t_cnt := t_cnt+1;
NULL;
END;      
t_cnt := t_cnt-1;
END LOOP;
END LOOP;

END;

exit
ENDDROPNEWTABS

echo "Dropping the tables created for this task..."

sqlplus -s usn/pwd@sid @dropnewtabs.sql >tablesDropped.txt

#END
  • 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-03T09:00:48+00:00Added an answer on June 3, 2026 at 9:00 am

    You are missing a / after the END; of your anonymous block, so it will never execute it, and the exit will be seen as part of the previous command. The / is very roughly analogous to ‘run’ in SQL Developer.

    ...
    END LOOP;
    
    END;
    /
    
    exit
    ENDDROPNEWTABS
    

    (You don’t need the BEGIN/END around the SELECT, or the NULL in the exception handler, but those won’t break anything; it’s also not a good idea to squash all possible exceptions silently, just look for the one you’re expecting to see. And personally I find it easier to follow with some indentation).

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

Sidebar

Related Questions

I'm trying to run a script which is just a series of drop tables
I have the below SQL Script which is run from Excel VBA using ADO
I have been trying to make a stored procedure which autodeletes temporary tables. CREATE
I'm trying to drop a few tables with the DROP TABLE command but for
I am trying to populate a drop-down box which I have created in the
I am trying to programmatically drop a column in a table inside of an
I'm trying to drop a SQL Server database from .NET code. I've tried using
I'm trying to make a drop down menu using javascript/jquery but can't get my
I'm trying to write a drop-in replacement for System.Media.SoundPlayer using the waveOut... API. This
I'm trying to create a custom drop down and using the code below it

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.