Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...If I'd only had resource like eng-tips when I was just getting started! I might have dazzled them with my brilliance instead of my BS..."

Geography

Where in the world do Tek-Tips members come from?
sadhramani (Programmer)
17 Jun 10 8:16
When I try to save a Stored procedure, I get a error.

Below is the code for the stored procedure:
CREATE PROCEDURE CheckTableExists(in :Table_Name varchar);
BEGIN
DECLARE :TestName char(20);
SELECT XF$Name INTO :TestName FROM X$File WHERE XF$Name=:Table_Name;
IF RTrim(:TestName) = :Table_Name THEN
DROP TABLE :Table_Name;
End If;
END;

I am passing a table name as a parameter to this stored procedure and it checks whether that table is available.  If yes, drop that table.

I get a error in the "DROP TABLE" statement.
The error message is:

Syntax Error: DROP TABLE<<???>>?
mirtheil (Programmer)
17 Jun 10 8:52
You can't execute a SQL statement with a variable unless you use the EXEC command:

CODE

CREATE PROCEDURE CheckTableExists(in :Table_Name varchar);
BEGIN
DECLARE :TestName char(20);
SELECT XF$Name INTO :TestName FROM X$File WHERE XF$Name=:Table_Name;
IF RTrim(:TestName) = :Table_Name THEN
exec('DROP TABLE '+ :Table_Name);
End If;

I've only tested compilation. I don't know if it will work.  Also, not all versions of PSQL support the EXEC syntax.  

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

sadhramani (Programmer)
18 Jun 10 7:58
CREATE PROCEDURE "CheckTableExists"();
BEGIN
PRINT 'hai'
END;

Pls find the code for creating a simple stored procedure...

I am trying to run the above stored procedure using the below syntax....

call CheckTableExists()
But to my surprise, the simple text message 'hai' is not printed....Pls find the attached image file (Pervasive_Progress.JPG).  This is the screen I am getting while I am executing the above stored procedure....

Pls help me out......
mirtheil (Programmer)
18 Jun 10 8:22
Print in a Pervasive Stored Procedure does not display a message on the client.  It only displays a message where the engine is running and typically only when the engine is run as an application.  

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

sadhramani (Programmer)
18 Jun 10 8:51
Cool..It works...I removed the print statement and it works...Even the stored procedure code that you gave me which drops the table name also works....Thank you so much...

When I manually try to drop the table, it says "Table is in use.....".  But I am very sure that my program is not running....how to find how this table is being used by anyone?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close