cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Not able to set session variable in SAP HANA V1.0 SPS12

0 Kudos
861

Hello,

I am trying to set the session variable in SAP HANA, as described here:

SET [SESSION] Statement (Session Management)

command: SET 'MY_VAR' = 'abc';

is successful, but when I am trying to retrieve back the value using the command:

SELECT SESSION_CONTEXT('MY_VAR') FROM DUMMY;

It's returning me null value.

View Entire Topic
0 Kudos

Hi, Florian Pfeffer and Lars Breddemann thanks to both of you for your replies.

I got the Idea from your comments, and after researching little more I came to know, each query I was running in the SQL console was getting executed in a new session.

To confirm the commands are working, I created a procedure, containing both set and select commands for a session variable.

CREATE PROCEDURE "SCHEMA_NAME"."CHANGE_SESSION_VAR" (OUT sessionVar NVARCHAR(5))
AS
BEGIN
	SET 'mySessionVar' = 'jmk';
	SELECT SESSION_CONTEXT('mySessionVar') into sessionVar FROM DUMMY;
END

And it worked, as invoking this procedure is executing both the internal queries in the same session.


Thanks again for your comments.😊