I'm having a problem while i'm trying to collect explain plan with the db2exfmt tool.
Can some body explain me the process of how to use that tool?
My requirement is to collect cost of a stored procedure. I have the EXPLAIN tables created in instance 'XYZ' schema and I have a procedure named "UNNAMED", which has the package name "P123456" and the schema "ABCD".
I used the following commands:
! db2exfmt -d SAMPLE -e DB2INST1 -s ABCD -n P123456 -g TIC -w -1 -#***5*** -t
Wherein 5 is the Section Number of the part of the procedure I'm trying to collect cost for.
Furthermore, I have also tried to do the following:
1) Identify the package corresponding to the stored proc :
select r.routineschema, r.routinename, rd.bname as packagename
from syscat.routines r, syscat.routinedep rd
where
r.specificname=rd.specificname and
r.routineschema=rd.routineschema and
rd.btype='K' and
r.routineschema = 'XYZ' and
r.routinename = 'ABCD'
2) Identify the section number for the SQL statement :
select sectno, text
from syscat.statements
where pkgschema='XYZ' and pkgname='P123456'
3) Populate Explain tables :
call EXPLAIN_FROM_CATALOG( 'XYZ', 'P123456', ' ', 5, 'SYSTOOLS', ?, ?, ?, ?, ? )
The latter throws an error:
Message: The parameter mode OUT or INOUT is not valid for a parameter in the routine named "EXPLAIN_FROM_CATALOG" with specific name "EXPLAIN_FROM_CATALOG" (parameter number "5", name "EXPLAIN_SCHEMA").. SQLCODE=-469, SQLSTATE=42886, DRIVER=3.50.152
I am logged in as USER : "MNO" and want the explain tables under SYSTOOLS schema to be populated.
Can someone please help me resolve the problem?
As the error message indicates, and the manual says, explain_schema is an INOUT parameter, so you cannot specify a literal value.
You may want to try wrapping the procedure call in a compound statement, providing declared variables for each OUT and INOUT parameter, something like:
begin
declare v_schema varchar(50) default 'SYSTOOLS';
declare v_req, v_srcname, v_srcschema, v_srcver varchar(128);
declare v_ts timestamp;
call EXPLAIN_FROM_CATALOG( 'XYZ', 'P123456', ' ', 5, v_schema,
v_req, v_ts, v_srcname, v_srcschema, v_srcver );
end
PS. Code is not tested
You have to specify every IN/OUT parameter with a "?" - running it will then prompt you for the input value ('SYSTOOLS').
So try
call EXPLAIN_FROM_CATALOG( 'XYZ', 'P123456', ' ', 5, **?**, ?, ?, ?, ?, ? )
Related
I am creating a WPF application using Advantage database server. I want to insert some data using stored procedure
Any sample code ?
I tried two input parameter TestID and TestName (both NCHAR)
INSERT INTO TestTable(
Test_Id,
Test_Name)
VALUES (
#TestID,
#TestName);
But show error like
Error 7200: AQE Error: State = HY000; NativeError = 5154;
[SAP][Advantage SQL Engine][ASA] Error 5154: Execution of the stored
procedure failed. Procedure Name: TestInsert. Error 7200: AQE
Error: State = S0000; NativeError = 2121; [SAP][Advantage SQL
Engine]Column not found: #TestID -- Location of error in the SQL
statement is: 42 (line: 3 column: 5) Error in stored procedure:
TestInsert AdsCommand query execution failed.
I am new in SAP ADS. Please help me.
use _XXXX notation for input parameters.
ie,
INSERT INTO TestTable( Test_Id, Test_Name)
VALUES ( _#TestID, _#TestName);
I have been seraching solution for this issue .Though this particular question has been discussed many times in this forum, i did not get any proper answer for my problem.
I will be getting data from 3rd party which can contain single quote.This data need to be inserted into data base and when it contains single quote it fails and throws following error:
Msg 105, Level 15, State 1, Line 7
Unclosed quotation mark after the character string '
---Following is c++ code to pass trandata as input along with other parameters and invoke fn_stripsingleQuote10 function from SQL server:
strSQLText = "declare #returnType as varchar(max)\n EXEC #returnType = CABINET..fn_stripsingleQuote10 ";
sqlTxtParams.Format("'%s', '%s', '%s', tranData, sing_quote, double_sing_quote);
strSQLText += sqlTxtParams;
----My sql function(fn_stripsingleQuote10) to replace single quote
USE [cabinet]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[fn_stripsingleQuote10](
#strip varchar(Max),#patern varchar(5),#replace varchar(5)
)
returns varchar(Max) as begin
declare #CleanString varchar(Max)
SET #CleanString=(REPLACE(#strip,#patern, #replace))
return #CleanString
end
sample output:
ex:
declare #returnType as varchar(max) EXEC #returnType = CABINET..fn_stripsingleQuote10 'fsds'd','''',''''''
I feel the way i am invoking the function is not proper.Please provide a solution .
Strictly speaking you're looking for QUOTENAME, which does exactly what you're asking:
'quote_character' Is a one-character string to use as the delimiter.
Can be a single quotation mark ( ' ), a left or right bracket ( [ ] ),
or a double quotation mark ( " ).
However, it is very very likely that your code is exposed to SQL Injection right now and you should actually use a parameter. It is almost never required to concatenate input into the resulted executed SQL.
I want to map a SQL Server stored procedure with MyBatis, using annotations.
#Select(value = "{call sp_cen_obliczcene(" +
"#{wytworId, mode=IN, jdbcType=NUMERIC}, " +
"#{rodzajCenyId, mode=IN, jdbcType=NUMERIC}, " +
"#{walutaId, mode=IN, jdbcType=NUMERIC}, " +
"#{jmId, mode=IN, jdbcType=NUMERIC}, " +
"#{ilosc, mode=IN, jdbcType=DECIMAL}, " +
"#{data, mode=IN, jdbcType=DATE})}")
#Result(property = "kwota", column = "kwota", javaType = BigDecimal.class, jdbcType = JdbcType.DECIMAL)
#Options(statementType = StatementType.CALLABLE)
public DtoCena dajCene(CriteriaCena parametry);
The procedure selects one row - I am interested in one column. Now, I've mapped a procedure before, only I had multiple rows and selected more then one column from them. Everything worked perfectly fine. When I mapped new procedure, in a similar way I got an error:
### The error occurred while setting parameters
### SQL: {call sp_cen_obliczcene(?, ?, ?, ?, ?, ?)}
### Cause: java.lang.NullPointerException
I started the SQL Profiler and saw that the procedure is called properly with the given parameters. I've noticed that the procedure I'm mapping is executing other procedures. They're performing some updates. When I changed my annotation to #Update I got an other error: that Integer cannot be cast to DtoCena type. I changed the return value of the method to Integer and I got no errors but as you can guess it did not return what I was looking for.
The question is, can I map a stored procedure which updates tables AND returns a ResultSet? I can do this using JDBC, but is this possible with MyBatis? Am I doing something wrong when using the #Select annotation?
Looks like the #Update returns the affected row count ...
Anyway, I don't think the issue is related to calling stored procedure, this is merely a mapping issue that would occur with simple select.
You must use #Result annotation inside #Results annotation, otherwise it is ignored.
Here is a simplified, yet functional, code:
#Select("select 'hello' as h, 1 as n from dual")
#Results({
#Result(column="n")
})
Integer test();
Just add a property attribute and change return type to retrieve result into an object.
I am running an insert command on db2 like the following:
insert into uinfo.transaction (TRANSACTION_ID, DATE,TIME,ID,USER,DESC) values
(14,20110311,36909,97,2497580,'Note:9045-02 2=34 ///' 2eq034d,xw d""::: 214l 23e;l2')
It gave an error saying, During SQL processing it returned:
SQL0103N The numeric literal "2034d" is not valid. SQLSTATE=42604
So, I tried escaping the ' as following:
insert into uinfo.transaction (TRANSACTION_ID, DATE,TIME,ID,USER,DESC) values
(14,20110311,36909,97,2497580,'Note:9045-02 2=34 ///\' 2eq034d,xw d""::: 214l 23e;l2')
It still fails saying the same thing. During SQL processing it returned:
SQL0103N The numeric literal "2034d" is not valid. SQLSTATE=42604
Any idea what is wrong above and can I overcome this?
To include ' in a string you need to double it. E.g.: 'ab''cd'.
For details read the Character string constants section on http://publib.boulder.ibm.com/infocenter/db2luw/v9r8/index.jsp?topic=/com.ibm.db2.luw.sql.ref.doc/doc/r0000731.html.
I have several variables in an SSIS package that I would like inserting into a table.
example:-
#financialMonth, #Status, #Comments
The Variables have been populated along the way with values based on lookups, filename, dates, etc, and I want to store them in a results table.
Is using the execute SQL task the way to do this ?
Do I need to call a sproc and pass those variales as parameters ?
I've tried putting the following T-SQL into the SQLStatement property
INSERT INTO FilesProcessed
(ProcessedOn, ProviderCode, FinancialMonth,
FileName, Status, Comments)
SELECT GETDATE(), 'ABC' , 201006,
'ABC_201005_Testology.csv',
'Imported','Success'
I tried hardcoding the values above to get it to work
These are the columns on the table I'm inserting into
Column_name Type Computed Length
fileID int no 4
ProcessedOn datetime no 8
ProviderCode nchar no 6
FinancialMonth int no 4
FileName nvarchar no 510
Status nvarchar no 40
Comments nvarchar no 510
This is the Expression code that feeds the SQLStatementSource property
"INSERT INTO FilesProcessed (ProcessedOn, ProviderCode, FinancialMonth,
FileName, Status, Comments) SELECT GETDATE() AS ProcessedOn, '"
+ #[User::providerCode] + "' , "
+ (DT_STR,6,1252)#[User::financialMonth] + ", '"
+ #[User::fileName] + "', 'Imported' AS Status,'Successfully' AS Comments "
Unfortunately I'm missing something, and can't quite get it to work.
The Error message I'm getting is ...
Error: 0xC002F210 at Log entry in
FilesProcessed, Execute SQL Task:
Executing the query "INSERT INTO
FilesProcessed (ProcessedOn,
ProviderCode, FinancialMonth,
FileName, Status, Comments) SELECT
GETDATE(), 'ABC' , 201006,
'DAG_201005_Testology.csv',
'Imported','Successfully'" failed with
the following error: "An error
occurred while extracting the result
into a variable of type (DBTYPE_I2)".
Possible failure reasons: Problems
with the query, "ResultSet" property
not set correctly, parameters not set
correctly, or connection not
established correctly.
Please
a). Advise whether the Execute SQL Task is the way to do what I want to do.
b). Give me any pointers or pitfalls to look out for and check.
Thanks in advance.
OK, here is what I did.
I created an Execute SQL task and configured, thus :-
General Tab
ConnectionType = OLE DB
SQLSourceType = Direct Input
SQLStatement = (left blank)
BypassPrepare = True
ResultSet = None
Parameter Mapping
(none - leave blank)
Result Set
(none - leave blank)
Expressions
SQLStatementSource = "INSERT INTO FilesProcessed (ProcessedOn, ProviderCode, FinancialMonth, FileName, Status, Comments) SELECT GETDATE(), '" + #[User::providerCode] + "' , " + (DT_STR,6,1252)#[User::financialMonth] + ", '" + #[User::fileName] + "', 'Import - Success', '" + #[User::fileComments] + "'"
Then as long as I set up the variables and populate them in the variables window (the Expression editor will not let you save an expression that references a variable that does not exist. Keep notepad handy to store the contents while you go back and edit the variables window, and add new variables in ;)
Build the expression slowly, using the Parse expression button regularly to check.
make sure that the data types of the VALUES match the destination column data types.
see: http://social.msdn.microsoft.com/forums/en-US/sqlintegrationservices/thread/e8f82288-b980-40a7-83a6-914e217f247d/
A couple of speculative suggestions
The Error message says An error occurred while extracting the result into a variable of type (DBTYPE_I2). But this is a straight insert statement. There shouldn't be a result except for rows affected. Do you have any parameter mappings erroneously set to Output?
What if you try and run the SQL Query from the error message directly in management studio? Does that give you an error?
In the above table definition FinancialMonth as int datatype as
FinancialMonth int no 4
while inseting casting as :
(DT_STR,6,1252)#[User::financialMonth]
I think it's purely a datatype mismatch with the target table definition.