on 03-12-2014 7:56 AM
Hi all.
Is it possible to put the output of the "EXECUTE IMMEDIATE" command in a local table so that the ouput can be accessed through other procedures.
Regards,
Andila
Hi Andila,
You can do that as mentioned by peter in the above reply.
But why do you want to persist the information into a Table?
Also would want to understand if you are having a Varied "select column" list and using EXECUTE IMMEDIATE for the same?
if not you can use "EXEC" and then use a local temporary table to hold the result which returns the value to your Table Type which can be further utilized by other procedures calling this procedure.
Can you be more clear on the requirement on why you want to do this?
Regards,
Krishna Tangudu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok are you creating through .hdbprocedure?
Then you have to enable some settings as mentioned in this thread
Then define a procedure with "WRITE" mode and then you can use Temporary Table. Also have a look on this thread where patrick faced a similar issue of authorization because he didnt grant access to the schema he is working on to _SYS_REPO user
Regards,
Krishna Tangudu
Hi Andila, well you could just make your dynamic sql statement an insert statement based on your select. See example below
create column table test_table_1
(
"COL1" nvarchar(10),
"COL2" nvarchar(10)
);
CREATE PROCEDURE INSERT_P()
LANGUAGE SQLSCRIPT AS
sql_string NVARCHAR(2000) := '';
BEGIN
sql_string := 'insert into test_table_1 (select ''val1'', ''val2'' from dummy) ';
EXECUTE IMMEDIATE (:sql_string);
END;
call insert_p();
select * from test_table_1;
However you may want to investigate other options instead of using dynamic SQL as this is not a recommended approach. Less optimized compared to standard sql.
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andila,
You can use Local Temporary table and store your result there by using EXEC or even EXECUTE IMMEDIATE
Which can be further captured via Table Type.
I would say you can go for EXEC.
Sample Code below:
DROP PROCEDURE SAMPLE_PROC;
CREATE PROCEDURE TEMPTABLE(OUT OUTTAB TT_EMPLOYEE)
AS
BEGIN
DECLARE QUERY VARCHAR (200);
CREATE LOCAL TEMPORARY TABLE #TEMPTABLE ( "ID" INTEGER, "NAME" VARCHAR(30));
SQL_QUERY := 'insert into #TEMPTABLE (Select ID,NAME from EMPLOYEE )';
EXEC (:QUERY);
OUTTAB = SELECT * FROM #TEMPTABLE;
DROP TABLE #TEMPTABLE;
END;
Regards,
Krishna Tangudu
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.