Last active
November 21, 2019 14:49
-
-
Save captainabap/9f9da63471e8d94da8cbe4dc53ec6884 to your computer and use it in GitHub Desktop.
Example for the MAP_MERGE Operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Anlegen der MAP-Funktion | |
CREATE FUNCTION map_table_row_count(IN iv_tabname nvarchar(30)) | |
RETURNS TABLE (tabname NVARCHAR(30), | |
rowcount INT ) | |
AS BEGIN | |
DECLARE lv_sql NVARCHAR(100); | |
DECLARE lt_result TABLE( tabname NVARCHAR(30), | |
rowcount INT ); | |
EXEC 'SELECT ''' | |
|| :iv_tabname | |
|| ''' AS tabname, ' | |
|| 'COUNT(*) as rowcount ' | |
|| 'FROM ' | |
|| :iv_tabname | |
INTO lt_result; | |
RETURN SELECT * FROM :lt_result; | |
END; | |
--Aufruf des MAP_MERGE Operators in einem Anonymen Block | |
DO BEGIN | |
lt_table = SELECT left(table_name,30) AS tabname | |
FROM m_cs_tables | |
WHERE schema_name = 'SYSTEM'; | |
lt_result = MAP_MERGE( :lt_table, | |
map_table_row_count( | |
:lt_table.tabname) ); | |
SELECT * FROM :lt_result; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment