INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Creation of a Stored Procedure

Creation of a Stored Procedure

(OP)
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<<???>>?

RE: Creation of a Stored Procedure

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

RE: Creation of a Stored Procedure

(OP)
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......

RE: Creation of a Stored Procedure

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

RE: Creation of a Stored Procedure

(OP)
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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

Resources

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