How can we create procedure in BigSQL? - bigsql

I am trying to create procedure in BigSQL. where i got some syntax error since i used db2 systax.Could you please tell me. what is the systax for procedure creation in BigSQL.

The documentation for the BigSQL syntax can be found here: http://www-01.ibm.com/support/knowledgecenter/SSPT3X_4.0.0/com.ibm.swg.im.infosphere.biginsights.db2biga.doc/doc/biga_intro.html?lang=en
However, as noted, you probably are dealing with a specific syntax issue and you should post the code for the procedure you created.

Related

Run stored procedure included sql script using robot framework

I want to run sql script which include db and table creations and stored procedure creations.
but when I try to run sql script using execute sql script keyword in database library I get an error like below
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$\n CREATE OR
REPLACE PROCEDURE `proc_GetCustomerDetails`(\n I...' at line 2")
before procedure I have delimiter like this,
DELIMITER $$
CREATE OR REPLACE PROCEDURE `proc_GetCustomerDetails`(
IN CustomerNbr LONGTEXT,
IN Lang VARCHAR(5)
)
DETERMINISTIC
BEGIN
IF Lang IS NULL THEN SET lang = "fin";
END IF;
SELECT * from dbname.customer;
END;$$
DELIMITER ;
If I comment stored procedure part, sql file is running without errors with rest of the table creation statements.
I googled this and couldn't find any related issue. I saw we have call stored procedure keyword. but I want to keep table creations and stored procedures in same sql file and need to run. I use MariaDB for this task.
Libraries used,
pymysql
robotframework-databaselibrary
If I run sql file using HeidiSQL it is running without any errors with procedures and delimiters. That mean there are no sql errors.
Can Someone tell me how to fix this?
DELIMITER is a statement supported only for the client, it is not supported by the server; thus the error. The solution - drop it.
Here's a question with very good answers what is it and why it's needed.
In short - when you work with a client you need a way to instruct it "this is not a statement you should execute immediately, this is still just a line in the SP you'll be sending to the server" - so you tell (to the client) "the DELIMITER b/n statements is temporarily $$". The server doesn't need/care about that - it knows everything between CREATE PROCEDURE, BEGIN, END are connected statements, a block.
When you connect to the DB through API (pymysql) vs an interactive client (shell, heidisql, etc) - you're sending the SP as a block, there's no way its statements will be ran one by one, thus the DELIMITER is not needed, not a supported command by the server, and generates an error. Drop it.

MySQL trigger Error: 1442

DB: MySQL
Using: MySQL Workbench
I am currently working on a project for class where we have to design a airport website in which users can login/register and buy tickets for various flights offered. After working on the project for some time I realized that my trigger is not working.
I receive the error: Error Code: 1442. Can't update table 'reservation' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
I stumbled upon this error by trying to insert a reservation before creating the form for users to select and buy tickets. I was wondering if someone could take a look at my database, insert command use, and also my trigger code. Any help would be much appreciated because I am at wits end trying to figure this out for hours.
Insert command: http://pastebin.com/tyBPWNDd
Entire DB and Trigger in question: http://pastebin.com/BvUj1NdH
Solved: thanks to all helpers I was able to identify my problem which was using recursive triggers when MySQL does not support them. I solved my problem by removing the recursive code and letting my website backend handle the current_date set instead of the trigger. I will post the fixed trigger shortly.
Yes, the error is self explanatory. You are trying to create a recursive trigger which is not supported in MySQL as can be seen in your posted code
Create Trigger reservation_all
after insert on Reservation
for each row
begin
update Reservation
Check MySQL Documentation on same for more infromation. Quoting from that
Stored functions cannot be used recursively.
A stored function or trigger cannot modify a table that is already being used (for reading or writing) by the statement that invoked the
function or trigger.

MS Access - Syntax error on CREATE TABLE Statement in MySql - using Trigger

For some reason, i can't get this to work..
CREATE TRIGGER triggerupdate
INSTEAD OF UPDATE ON ORDERDETAILS
AS
IF UPDATE(ORDERVALUE) BEGIN
Print ('INSTEAD OF Trigger [triggerupdate] - Trigger executed!!')
Print('You cannot update Order Value')
END
I'm trying to do a trigger if someone tries to update OrderValue. IT kept saying that Syntax error on Create Table.
Let me know what I have wrong.
Thanks
You can't use MS Access. Access does not support TRIGGERs, that's why you're getting Syntax errors, because "CREATE TRIGGER" is not supported SQL in Access.
Also, Print isn't a function in Access SQL either.
It's possible that you're meant to use Access as a front-end for MSSQL Server, which can be done, and where your SQL statements will become valid (but your use of Print is archaic).

How to insert the SQL Error message into table

I want to store the error messages which occurs while executing the stored procedure in another error table.
Here is the my sample procedure having some error statements.
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`$$
CREATE PROCEDURE `test`()
BEGIN
SELECT * FROM emp;
END $$
DELIMITER $$;
When i call the above procedure it gives me error.I wnat to store this error code & message in another table as "error".
Any pointers are appreciated.
Thanks in Advance.
The standard way to handle this in MySQL is to declare a HANDLER to handle the error condition the way you want. This allows you to insert an error message into another table if you want, and then to either CONTINUE or EXIT the running procedure as required.
Here's the documentation:
http://dev.mysql.com/doc/refman/5.0/en/declare-handler.html
Unfortunately you will not be able to access the SQLSTATE of the statement that caused the error, so this approach is somewhat limited.
Here's another relevant question on SO with much more detail:
MySQL Stored Procedure Error Handling
SQL ERROR means there is something wrong with your SQL Query. It may (or may not) depend on your table. If the error is TABLE SPECIFIC or QUERY SYNTAX ERROR, that is, if there is something wrong with a specific table ONLY, or with a query, then definitely you can insert your errors into a table. But, if there is something with your CONNECTION or something else, then you cannot insert errors into any table.
ALWAYS try to log your errors in a html file or txt (text) file, so that you can smoothly access it. Also there is a less chance for failure.

EXECUTE AS on truncate sproc - Incorrect syntax

I'm getting an Incorrect syntax when trying to create a stored procedure to truncate a table then reseed it. Here's my code
CREATE PROCEDURE [dbo].[_TransportZipporah_Purge]
WITH EXECUTE AS owner
AS
TRUNCATE TABLE [dbo].[*tablename*];
GO
DBCC CHECKIDENT ('dbo.*tablename*', RESEED, 0);
As i have got this direct from MSDN I would have thought it would be correct.
Database server i'm using is : SQL Server 2008 v10.0.4064.0
Can anyone help please?
Thanks in advance
Scott
The syntax is correct - but you cannot have a GO statement inside a proc.