Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creation of a Stored Procedure

Status
Not open for further replies.

sadhramani

Programmer
Jun 8, 2010
19
CA
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<<???>>?
 
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
 
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......
 
 http://www.mediafire.com/myfiles.php
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
 
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top