NCLOB Size Limitation while Calling Procedure #148 - hana

While calling Procedure GET_OBJECT_DEFINITION we have the output parameter OBJECT_CREATION_STATEMENT which will return the creation statement for any object passed to procedure.
The result of OBJECT_CREATIOB_STATEMENT is truncated to 1008 chars. We don't have option to limit the LOB Column Size.

Related

Why is my stored procedure query returning extra results?

I have the following query inside of a stored procedure:
CREATE PROCEDURE [s_Staff_ByLikeLastNmByLikeFirstNm]
#LastNm varchar(10),
#FirstNm varchar(10)
/*WITH ENCRYPTION*/
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SELECT
Staff.FirstNm,
Staff.LastNm
FROM
Staff
WHERE
Staff.LastNm LIKE #LastNm + '%'
AND Staff.FirstNm LIKE #FirstNm + '%'
If I input 'Christiansen' in my query for #LastNm, when I execute the stored procedure, it is returning me both 'Christiansen' and 'Christianson', and performing more of a SOUNDEX search.
How can I fix this?
If I run do a select outside of the stored procedure, I am getting the correct results.
'Christiansen' has 12 characters in it.
You have defined the parameters to the stored procedure to have a length of 10, so the value is truncated to 'Christians'.
Fix the length parameter in the declaration of the stored procedure.

Return a single value and multiple OUT parameter in Stored Procedure

I read an article about Stored Procedures which said:
A stored procedure can return a single values such as a number or text value or a result set
I am confused, because if we declare multiple OUT parameters, the we can have multiple output but it said that we can have only a single value?
EDIT:
This is The Article
In SQL Server, a stored procedure can actually return a value -- always an integer. This is usually a status value and is quite separate from the output parameters.
So you can can have:
execute #retval = usp_myproc #x1 output, #x2 output;
The returned value is generally not data, but a status.
That statement is not entirely correct.
There are three ways of returning data from a procedure to a calling program: result sets, output parameters, and return codes.
See Return Data from a Stored Procedure
This link will walk you through the 3 approaches.

Manipulate with data returned by stored procedure

I have stored procedure in SAP HANA (let's call it testProcedure) which returns data (for example col1 | col2 | col3). Unfortunately I can't modify this stored procedure.
How can I manipulate (filter it etc.) with these data after procedure execution (currently I execute it with call testProcedure()?
I'm looking for something like select * from testProcedure() where col1 = 'hello'
What you’re describing works with a user defined table function, but not with a procedure.
If your procedure uses the default result set, then there’s no way to filter or otherwise process the result set. It will just be returned to HANA studio as is.
If the result set is returned via a output parameter you could assign it to a table variable and apply filters when selecting from that table variable.

How should i throw exception error from stored procedure such as " String or binary data would be truncated. "?

SQL Server 2012. Based on the stored procedure variable length; input value is automatically trimmed and inserted to the table.
Example : I am passing a variable #name varchar(10):
#name VARCHAR(10) = null
However, on inserting the record which is more than 10 characters through stored procedure, record get inserted by trimming the characters to first 10 digit.
I am expecting to get the error exception such as
String or binary data would be truncated
How should I throw an exception error from the stored procedure?
CREATE TABLE tbl_test
(
[ID] INT,
[NAME] VARCHAR(10),
)
GO
CREATE PROCEDURE usp_test
(#name VARCHAR(10) = NULL)
AS
SET ANSI_WARNINGS ON
BEGIN
INSERT INTO tbl_test
VALUES (1, #name)
INSERT INTO tbl_test([ID], [NAME])
VALUES (2, #name)
END
The behavior depends on the ANSI_WARNINGS session setting.
With ANSI_WARNINGS ON (the default in modern Microsoft SQL Server APIs), you will get the expected "string or binary data would be truncated" error when data are inserted into a column with a shorter length. ANSI_WARNINGS ON is implicitly set by ANSI_DEFAULTS ON.
With ANSI_WARNINGS OFF, the data will be silently truncated.
However, when you pass a parameter value that is longer than the defined parameter length, the value is truncated without error or warning regardless of the session setting. This is documented behavior that may not be what one expects:
SET ANSI_WARNINGS is not honored when passing parameters in a
procedure, user-defined function, or when declaring and setting
variables in a batch statement. For example, if a variable is defined
as char(3), and then set to a value larger than three characters, the
data is truncated to the defined size and the INSERT or UPDATE
statement succeeds.
so it is important to ensure supplied values do not exceed the defined parameter length.
One way to get this to work is to make sure your parameters are longer than the table column. Doesn't have to be much longer - one character would be enough. Then if you get passed a longer string, it will still be longer inside the stored procedure.
At that point you can either test for the length being too long and raise your own error, or if you try and put it in the table you'll get an error anyway. Either way, at least you'll know.

Converting bytes to integers

I want to use the procedure sp_spaceused on a table.
This procedures returns among others the size of the tables.
example:
sp_spaceused
database_name database_size unallocated space
db_test 216001.00 MB 196366.74 MB
After I perform a compression I want to recall the function in order to find the compression percentage.
I call again sp_spaceused.
How can I represent database_size internally in order to perform a division?
You can actually store the results of the stored procedure in a table. Once you have them in a table you can manipulate it however you need. To get stored procedure results into a table, you would first need to make a table with columns that match the resultset of the stored procedure. Then do an insert statement for the table but instead of a query or a value list, execute the stored procedure. Note, that this will only get the first resultset of a stored procedure into a table. For example, you could do:
create table HoldSpaceUsed
(
database_name sysname,
database_size varchar(100),
[unallocated space] varchar(100)
)
insert HoldSpaceUsed
exec sp_spacesused
After you execute the above statements the HoldSpaceUsed table will contain the stored procedure results. Remember that the database_size field has the 'MB' representing the database size is in megabyts, so you would need to trim out the 'MB' text so you have just the number and then you can use it however you need.