SAP DBTech JDBC: [1306]: return type mismatch:Procedure ARRAY_UNNEST_SIMPLE: Attribute name "id" different from Attribute name: ":ARRID" - hana

Hello everyone I am learning about SAP HANA. I'm having trouble at this error, I've been trying to figure out how to fix it but I haven't figured it out yet, I hope everyone will help. Thank you all.
DROP TYPE ttype;
CREATE TYPE ttype AS TABLE("ID" INT , "NAME" NVARCHAR(10));
CREATE PROCEDURE ARRAY_UNNEST_SIMPLE(OUT rst ttype)
AS
BEGIN
DECLARE arrid INTEGER ARRAY = ARRAY (1,2);
DECLARE arrname NVARCHAR(10) ARRAY = ARRAY('name1', 'name2', 'name3');
rst = UNNEST(:arrid, :arrname);
END;

It looks like the error is due to the mismatch of the column names that result from the UNNEST operation and the declared return table variable.
You can provide column names via the AS ... command parameter:
rst = UNNEST(:arrid, :arrname) AS (“ID”, “NAME”)

Related

Invalid data type for parameter passed in the cursor in SAP HANA

Can anybody help me,as I want to declare a cursor with a variable which is of table type and I am getting invalid data type for parameter. In a stored procedure in SAP HANA
Create TYPE "TT_GUID" AS TABLE ( "guid" VARCHAR(32));
DECLARE CURSOR C_cursor( var_guid "TT_GUID") FOR
Select zval_001,zval_002
FROM "table1"
Where "guid" = :var_guid ;

Token unknown error in update Trigger

Here's the update trigger I'm trying to create for a view. It's pretty clear what I'm trying to achieve:
SET TERM !! ;
CREATE TRIGGER SST_Insert FOR SpaceSpaceTypes
BEFORE INSERT AS
DECLARE VARIABLE NEW_TYPE_ID;
BEGIN
NEW_TYPE_ID=(SELECT MAX(type_id) FROM SpaceTypes WHERE type_name=NEW.type_name);
INSERT INTO Space values (NEW.address,NEW.company_id,NEW.area,NEW_TYPE_ID);
END!!
SET TERM ; !!
I've tried different combos of !!'s and ;'s. I tried dropping a variable. It didn't help. The error for the query above is:
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 3, column 29
-;
The problem is with this line:
DECLARE VARIABLE NEW_TYPE_ID;
You haven't specified the type of NEW_TYPE_ID, so the statement is incomplete and the semi-colon is unexpected at that position, which causes a token unknown error.
The syntax of DECLARE VARIABLE is:
DECLARE [VARIABLE] <varname>
{<datatype> | <domain> | TYPE OF {<domain> | COLUMN <rel.col>}
[NOT NULL] [CHARACTER SET <charset>] [COLLATE <collation>]
[{DEFAULT | = } <initvalue>];
So at minimum you need to use:
DECLARE VARIABLE NEW_TYPE_ID INTEGER;
Or more advanced:
DECLARE VARIABLE NEW_TYPE_ID TYPE OF COLUMN SpaceTypes.type_id;
The best option was to leave it as
SET TERM !! ;
CREATE TRIGGER SST_Insert FOR SpaceSpaceTypes
BEFORE INSERT AS
BEGIN
INSERT INTO Space values (NEW.address,NEW.company_id,NEW.area,(SELECT MAX(type_id) FROM SpaceTypes WHERE type_name=NEW.type_name));
END!!
SET TERM ; !!

Sybase SQL QUERY - error while executing stored procedure

When I try to execute this stored procedure im getting this error"Database Connector Error: 'Implicit conversion from datatype 'CHAR' to 'INT' is not allowed. Use the CONVERT function to run this query" how come? how can I fix this? thanks
this is the query im using to execute the SP:
CREATE PROCEDURE TestProc2(#store char(4))
AS
BEGIN
SELECT * FROM stores WHERE stor_id=#store
END
exec TestProc2 #store = "7066"
sp_help stores
stor_id, char, 4
stor_name, varchar, 40
stor_address,varchar, 40
city, varchar, 20
state, char, 2
country, varchar, 12
postalcode, char, 10
payterms, varchar, 12
the column is set as char(4) so I don't think there is a mismatch with the query and data types
BTW I tried("7066") with single quotes, with double and without quotes, I still get the same sql error. please help
PS Im using sybase thanks! also below is a screenshot of the error.
any other info you guys need to help me? thanks
http://tinypic.com/r/2n24huq/8
It looks like the stor_id field in the stores table is an int. Change your stored procedure to accept an int instead of a char(4).
CREATE PROCEDURE TestProc2(#store int)
AS
BEGIN
SELECT * FROM stores WHERE stor_id=#store
END

How to update a boolean field in Oracle table

I am a novice Oracle user. I wanted to update a boolean field in my table for one of the record. Which one of these statements is correct ?
update MyTable set myBooleanColumn = 1 where UserId= 'xx12345';
or
update MyTable set myBooleanColumn = '1' where UserId= 'xx12345';
any help is greatly appreciated!! thanks !
It depends on how the field is defined.
If its defined as a CHAR(1) field, then you can store 'Y'/'N' or 'T'/'F' in it. To update the field, you'd use the quotes as it would be a string literal.
UPDATE TestTable set myCharBooleanColumn = 'Y';
If the field is defined as NUMERIC, then the convention is 0=false and 1 or -1 is true (I've seen both).
UPDATE TestTable set myNumericBooleanColumn = 1;
Many people will advocate the CHAR(1) approach, but in the real world - you see both. It depends on how the boolean is implemented.
You can read more in Oracle's docs on Datatypes
http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm
There is no such thing as a Boolean field in Oracle so your field is either a numeric field or a character field. If it's a numeric field you don't need to quote the number; if it's a character field you should quote the string.
You can find out the type of the column by querying USER_TAB_COLUMNS:
select *
from user_tab_columns
where table_name = 'MYTABLE'
and column_name = 'MYBOOLEANCOLUMN'
or by describing the table.
There is nothing as Boolean field in Oracle.
The best what you can do is to create the table like this:-
create table ABC(bool char(1) check (bool in ('N','Y'));
Then simple update like
UPDATE ABC set bool = 'Y';
WHY TAKING CHAR?
There is no support for BOOLEAN, BIT, or TINYINT data types so char would be the best as it takes 1 byte

bit Data type usage in Stored procedure

I want to capture Radio button values in db so i created table with datatype bit
But the problem when am create stored Procedure as
CREATE PROCEDURE Mt_Vacancy_mainPreference_insert
(
#post_name varchar(20),#preference varchar(20),gender bit,No_of_vac int
)
AS
Begin
insert into Mt_Vacancy_mainPreference values(#post_name, #preference, #gender, #No_of_vac)
end
RETURN
It says Incorrect Sytax near gender
Must produce scal value
What is the problem
You are missing the # prefix for your last 2 parameter names.
You forgot to decorate the input variables;
gender bit,No_of_vac int
Should be
#gender bit, #No_of_vac int