I am writing a stored procedure where I want to pass in the field name and data then in the procedure use the field name to reference to field to insert / update:
BEGIN
INSERT INTO trainees (txtTrainee, _field) VALUES (_txtTrainee, _data)
ON DUPLICATE KEY UPDAYE _field=VALUES(_field);
END
The parameters passed into the procedure are:
_txtTrainee, this is a TEXT field and contains the host name to use
_field, this is a TEXT field and contains the field name to modify
_data, this is a VARCHAR(16) and contains the data to insert or update
I can see I need some kind of translation function to get the contents of _field.
I'm using MariaDB 10.8
The solution is to use a prepared statement:
BEGIN
SET #SQL = CONCAT("INSERT INTO trainees (txtTrainee,?)",
"VALUES(?,?)",
"ON DUPLICATE KEY UPDATE ?=VALUES(?)");
PREPARE stmt FROM #SQL;
EXECUTE stmt USING _field,_txtTrainee,_data,_field,_field;
END
Need help on getting query on a text file using stored procedure in db2. I'm very new to this so please help.
Till now i am able to create a file and get get data in created file. But i want a complete query in the file not a single column data.
I have created a Stored Procedure like this
CREATE or replace PROCEDURE SCOPEMASTERP(my_statement varchar(10000))
AUTONOMOUS
BEGIN
DECLARE v_filehandle UTL_FILE.FILE_TYPE;
DECLARE v_dirAlias VARCHAR(50) DEFAULT 'mydir';
DECLARE v_filename VARCHAR(100) DEFAULT 'bluestar_transaction-';
DECLARE v_format VARCHAR(200);
SET v_format = '%s\n';
set v_filename = concat(v_filename, VARCHAR_FORMAT(current_date, 'DD-MM-YYYY'));
set v_filename = concat(v_filename, '.log');
CALL UTL_DIR.CREATE_OR_REPLACE_DIRECTORY('D:', '/archivelog/asd/');
SET v_filehandle = UTL_FILE.FOPEN(v_dirAlias,v_filename,'a');
CALL UTL_FILE.PUTF(v_filehandle,v_format, my_statement);
CALL DBMS_OUTPUT.PUT_LINE('Wrote to file: ' || v_filename);
CALL UTL_FILE.FCLOSE(v_filehandle);
END
and i have created a trigger inside trigger i am calling stored procedure
CREATE OR REPLACE TRIGGER SCOPEMASTER_Trigger
AFTER INSERT ON SERVEIT.SCOPENAMEMASTER
REFERENCING NEW AS N
FOR EACH ROW
BEGIN ATOMIC
call SCOPEMASTERP(N.SCOPENAMEID);
END
insert statement i am executing
Insert into SERVEIT.SCOPENAMEMASTER (SCOPENAMEID) values (1013)
GO
And file which is creating in "D" drive i am getting
But instead of just getting 1013 i need the complete query in the file
Insert into SERVEIT.SCOPENAMEMASTER (SCOPENAMEID) values (1013)
What changes i need to do please help. Thanks in advance!!
There are no special registers/variables/etc. available in DB2 that provide the SQL statement that is being executed, so what you're asking for is not possible.
I thought Shell.Explorer means Webbrowser Control in AutoHotkey.
But as I view the output of the parameters of theNavigateError event, it is slightly different than the ones described in MSDN pages.
I found two different pages at MSDN for NavigateError.
DWebBrowserEvents2::NavigateError http://msdn.microsoft.com/en-us/library/aa768286%28v=vs.85%29.aspx
NavigateError Event http://msdn.microsoft.com/en-us/library/bb268221%28v=vs.85%29.aspx
Since the second parameter shows a url with the below code, I guess AutoHotkey is using the DwebBrowserEvents2 interface but the MSDN page says the method accepts 5 parameters while AutoHotkey receives 6 of them.
new WBConttrol("file:///" A_ScriptDir "/nofile")
class WBConttrol {
NavigateError(oParams*) {
msgbox, 64, % Parameters, % "the number of passed parameters: " oParams.MaxIndex() "`n"
. "1: " (IsObject(oParams.1) ? "object" : oParams.1) "`n"
. "2: " (IsObject(oParams.2) ? "object" : oParams.2) "`n" ; url
. "3: " (IsObject(oParams.3) ? "object" : oParams.3) "`n"
. "4: " (IsObject(oParams.4) ? "object" : oParams.4) "`n"
. "5: " (IsObject(oParams.5) ? "object" : oParams.5) "`n"
. "6: " (IsObject(oParams.6) ? "object" : oParams.6) "`n"
}
__New(strURL="") {
static WB
Gui, New, Resize MaximizeBox
Gui, Add, ActiveX, vWB w300 h200, Shell.Explorer
Gui, show, w300 h200
ComObjConnect(WB, this)
WB.Navigate(strURL)
}
}
Shell.Explorer does indeed mean the WebBrowser control.
The extra (sixth) parameter is defined in the documentation for ComObjConnect():
PrefixEventName([Params..., ComObject])
...
ComObject is optional, and can only be used if the correct number of Params are defined; it contains a reference to the original wrapper object which was passed to ComObjConnect.
The reason for this extra parameter is that some COM event methods do not define any parameters at all, and therefore don't provide a reference to the COM object which the event is being raised on.
I really like SQuirreL SQL as a SQL query tool, but I've never been able to get it to call stored procedures in our AS/400 DB2 database. I always get the error "The number of parameter values set or registered does not match the number of parameters." I've double-checked the number of params and had no luck. This is the syntax I've tried for a procedure that takes one IN and one OUT:
call SOMESPROC(12345, ?);
It seems that SQuirrel currently is not capable of doing that on AS/400 DB2.
Using the open source "SQL Workbench/J" (http://www.sql-workbench.net/) I was able to call a procedure:
wbcall SOMESPROC(12345, ?);
It has its own command for calling a procedure "wbcall". Use ? for out parameters.
Note: While installing SQL Workbench/J make sure to download the right DB2 driver from IBM and also add the licence file while adding the driver inside SQL Workbench/J.
In Squirrel you can use something like this. You'll want to make sure the type of the declared variable matches the type of your out parameter in the stored procedure.
BEGIN
DECLARE outParam INT;
STORED_PROC_NAME(outParam);
END
If you also need to provide input for the procedure you could do this.
BEGIN
DECLARE outParam INT;
STORED_PROC_NAME('input', outParam);
END
You also need to change the statement separator to something other than ;. Otherwise it will break up the statement and try to send each piece individually.
In the pro version of DbVisualizer, with the "Process Parameter Markers in SQL" under the SQL Commander menu option enabled, it will allow the "?" param
call SOMESPROC(12345, ?);
through trial and error, I was able to see the results in Squirrel.
create or replace variable var4 char(1);
create or replace variable var5 decimal(3,0);
create or replace variable var6 char(60);
call getthedata('XXX',123456789,'1234567',var4,var5,var6);
select var4,var5,var6 from sysibm.sysdummy1; -- displays OUT parms
I would think that if there is one in then the call should be:
CALL SomeSProc(12345)
to get a result maybe try:
SELECT * FROM SomeSProc(12345)
Here is an tested example which works on Squirrel 3.7 with a db2 stored procedure . The trick is to passe with an transitional stored procedure MY_PROC_TEST to call the real stored procedure PROC_TEST.
change statement separator in squirrel > session > session properties > SQL : #
DROP PROCEDURE MY_PROC_TEST()#
CREATE PROCEDURE MY_PROC_TEST()
RESULT SETS 1 -- out resultset (call product)
LANGUAGE SQL
BEGIN
DECLARE flag SMALLINT; -- out parameter
CALL MY_PROC('2015', flag);
END #
CALL MY_PROC_TEST()#
END #
Then you can call the sored procedure like this :
CALL MY_PROC_TEST()#
This will work in Squirrel if you change the delimiter (as specified above). However, to see what the variable is, you need to do the following...
In my example, I will set the delimiter to a tildy (~). Include after last "end", before "select". Code begins here...
begin
declare inoutParm numeric(2,0);
call spMyStoredProcedure(
1234567
, inoutParm
);
declare global temporary table session.myTempTbl
(MyResult char(1024) )
with replace ;
insert into session.myTempTbl
(myResult)
values(inoutParm) ;
end
~
select myResult from session.myTempTbl
Mic Keeley
as400(db2) SQL Developer
I was able to cobble together some amalgamation of all of the above answers and came up with this which worked for me. I'm using Squirrel SQL 2018 connecting to an IBM AS/400 DB2 database. I did have to declare a statement separator, I used "#".
BEGIN
DECLARE success CHAR(1); -- output parameters
DECLARE message CHAR(300);
SET success = ' ';
SET message = ' ';
CALL myProc('some', 'params', 4, success, message);
DECLARE GLOBAL TEMPORARY TABLE session.myTmp(s_res CHAR(1), m_res CHAR(300)) WITH REPLACE;
INSERT INTO session.myTmp(s_res, m_res) VALUES(success, message);
END
# -- <- statement separator needs to be set to something other than ";" in this case it's set to "#"
SELECT * FROM session.myTmp;
change statement separator in squirrel > session > session properties > SQL : '#'
BEGIN
DECLARE inOutParam varchar(200);
set inOutParam = 'a value';
STORED_PROC_NAME(outParam);
END;
#
How to add parameters in TSmartQuery?
I mean on the Parameter tab which can be seen when I click on params properties.
I found two ways:
-editing the dfm file
-parameters are filled out automatically based on used :vars in Sql tab.
I did not managed to add them manually using a user interface.
TSmartQuery is component from ODAC library.
TSmartQuery is similar to other TQuery family you can use parameters in different ways depend on your needs:
If you already used Sql with parameters such as: Qry1.Sql.Text := 'Select * from Table where Id = :id';
then you can the defined parameter values as : Qry1.ParamByName('Id').asInteger := 10;
If you have an instance from TParam you can add to the qry like : Qry1.Params.AddParam(myParam).
You can create Parameter and assigned directly to the ParamList with : Qry1.Params.CreateParam();
which defined as:
function CreateParam(FldType: TFieldType; const ParamName: _string;
ParamType: TParamType): TDAParam;
2 & 3 mostly used with Stored Procedures because you need to define if the parameter will be input or output param.
Update:
I didn't notice that you are using Intraweb when I post my answer, but it should be the same way as you do with normal Delphi applications.