How to use Bind Variables in Informix Procedure - informix

I am trying to use Bind Variable for Informix Procedure.
Can someone guide me how to use for the below procedure?
CREATE PROCEDURE neura_omega_stg.grn_payment_mode_update(vv_material_document_id Varchar(20),vv_payment_mode Varchar(10))
UPDATE goods_receive_header_tbl SET payment_mode=vv_payment_mode WHERE
material_document_id=vv_material_document_id;
END PROCEDURE;

If you use JVM language like Java, or Jython which can use Informix JDBC driver then you can use CallableStatement:
proc = db.prepareCall("{ call neura_omega_stg.grn_payment_mode_update(?, ?) }")
proc.setString(1, "10")
proc.setString(2, "20")
proc.execute();
In JDBC/ODBC you can use Prepared Statement:
pstm = db.createStatement("EXECUTE PROCEDURE neura_omega_stg.grn_payment_mode_update(?, ?)")
pstm.setString(1, "10")
pstm.setString(2, "20")
pstm.execute()

Presumably in Data Studio SQL Editor you would execute something like:
EXECUTE PROCEDURE neura_omega_stg.grn_payment_mode_update("One", "Two");

Related

Use of variable SET statement in stored procedures compiles but fires exception at runtime

In a Snowflake SQL-stored procedure, I would like to SET value of a variable like the following:
DROP PROCEDURE IF EXISTS MY_DB.MY_SCHEMA.MY_SP_SQL();
CREATE PROCEDURE MY_DB.MY_SCHEMA.MY_SP_SQL()
RETURNS STRING NOT NULL
LANGUAGE SQL
AS
DECLARE
retValue VARCHAR;
BEGIN
SET retVal = '';
[...]
Everything rocks at compile time but fails at runtime with the following exception
Uncaught exception of type 'STATEMENT_ERROR' on line x at position y :
Stored procedure execution error: Unsupported statement type 'SET'.
despite documentation says this to be possible ๐Ÿคจ
Can someone gently explain to the noob of me? ๐Ÿ˜
Thanks,
Within a SQL stored procedure use LET instead of SET. The syntax for stored procedures (also known as Snowflake Scripting) is different from interactive SQL. The valid commands in SQL scripting are described in the Snowflake Scripting Reference

Unable to create a Stored procedure in Redshift Aginity and aginity pro

Trying to create the stored procedure in redshift aginity workbench but it through an error like 'unterminated dollar-quoted string at or near "$$
'
In amazon, they already gave the solution for this
https://docs.aws.amazon.com/redshift/latest/dg/stored-procedure-create.html
particular client tool only supported to create the stored procedure.
I want to conform aginity don't have the option to create this?
and
Which is the best tool to create stored-procedure?
CREATE OR REPLACE PROCEDURE staging.test_sp1(f1 int, f2 varchar)
AS $$
BEGIN
RAISE INFO 'f1 = %, f2 = %', f1, f2;
END;
$$ LANGUAGE plpgsql;
You can create RedShift stored procedures in Aginity Pro by using Run Batch. Full support will be in the 9/16 release.
Aginity need to update their tool to pass the dollar quoted procedure body to Redshift correctly. I note that Aginity is able to execute the procedure with CALL staging.test_sp1().
Some other tools have already been updated to allow creation and you can always use psql to create the procedure.

DB2 Stored Procedure try catch

Hi i'm creating a database with DB2. I use IBM Data Client. I want to use try catch into my stored procedure but it seems that are not supported by DB2, can any one help me? I need to handle sql errors and to return its. How can i do that?
DB2 LUW supports exception handlers (continue handlers, or exit handlers) for SQL PL procedures. Look in the DB2 Knowledge Center for your version for all the details. You can use them alongside conditions. You can have multiple handlers if you need specific processing. There are plenty of sample SQL PL procedures in both the Knowledge Center and in the DB2 LUW installed product directories.
CREATE OR REPLACE PROCEDURE sp_Applicazione_Aggiorna
(
IN #VAR1 INT,
IN #VAR2 INT,
IN #VAR3 VARCHAR(16),
OUT #ReturnCode INTEGER,
)
LANGUAGE SQL
P1: BEGIN
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND
SET #ReturnCode = SQLCODE;
IF not exists (select VAR1 from DB.TABLEA where VAR1 = #VAR1)
THEN
set #ReturnCode = 3011;
ELSE
UPDATE DB.TABLEA SET
VAR2=#VAR2,
VAR3=#VAR3
WHERE VAR1=#VAR1;
END IF;
END P1

Cursor not returned from Query

I'm using Delphi XE and FireBird 2.5.
Try use a TSQLStoredProc and give me the error "Cursor not returned from Query" when I put the Active property to TRUE.
An dummy example of storedproc
CREATE PROCEDURE NEW_PROCEDURE
RETURNS(
RDO SMALLINT)
AS
BEGIN
Rdo = 5;
/* Procedure body */
SUSPEND;
END;
As a workaround, a query like SELECT * FROM NEW_PROCEDURE should work (using TSQLQuery).
I think you are supposed to use the ExecProc method instead of Open / Active. Setting Active to true should only be used if your SQL Statement returns a ResultSet (a set of records), which yours doesn't.
Regards,
Stefaan

Delphi / ADO : how to get result of Execute()?

I have declared AdoConnection : TADOConnection; and successfully connected to the default "mysql" database (so, no need to pass that code).
Now, taking baby steps to learn, I would like to AdoConnection.Execute('SHOW DATABASES', cmdText); which seems to work ok, in the sense that it doesn't throw an exception, but I am such a n00b that I don't know how I can examine the result of the command :-/
Halp!
#mawg, the SHOW DATABASES command returns an dataset with one column called 'Database', so you can use the TADOQuery component to read the data.
try this code.
var
AdoQuery : TADOQuery;
begin
AdoQuery:=TADOQuery.Create(nil);
try
AdoQuery.Connection:=AdoConnection;
AdoQuery.SQL.Add('SHOW DATABASES');
AdoQuery.Open;
while not AdoQuery.eof do
begin
Writeln(AdoQuery.FieldByname('DataBase').AsString);
AdoQuery.Next;
end;
finally
AdoQuery.Free;
end;
end;
What you need is to reach the returned _Recordset.
If you don't mind using the Delphi components, you should use TADODataSet or TADOQuery to execute a SQL command which can return any results (or the more low-evel TADOCommands' Execute methods).
If you wanty something realy simple, w/o all the VCL balast, you mignt want to try the TADOWrap class from ExplainThat (MIT licenced).
You must use an TADOQuery connected to TADODataBase. At property SQL you must include the SQl statament to retrive databases in SGDB. In SQL Server you can do this:
SELECT * FROM sysdatabases
In MySQL must exist something similar to retrieve the names.
You can connect this TADOQuery to a TDataSource and a DBGrid to see visual result or use code to explore the result of the query (some similar to this):
ADOQuery1.Open;
while not ADOQuery1.eof do begin
Name := ADOQuery1.FieldByName('DBName').AsString;
ADOQuery1.Next;
end;
Regards
You need TAdoQuery to execute statements, that return results.
If you simply want to populate a grid why dont you use adotable ?
Adotable.open;
Adotable.first;
While NOT adotable.eof do(not sure about not or <>)
Begin
Put values in variant or array;
Adotable.next;
End
Then you can let any UI access the array or variant.
Or populate a dataset.

Resources