on 06-13-2014 5:39 PM
Specifically I'm trying to use a table type definition in my function.
CREATE TYPE "MYSCHEMA"."TT_MYTABLE" AS TABLE (
"Field" varchar(12)
)
CREATE FUNCTION "MYSCHEMA"."MYFUNCTION"()
RETURNS TABLE ("MYSCHEMA"."TT_MYTABLE")
LANGUAGE SQLSCRIPT
...
All the function examples use an actual field definitions and not an predefined table type. I've tried the above and a bunch of other variations but I get a syntax error on all of them.
This is the documentation page;
http://help.sap.com/saphelp_hanaplatform/helpdata/en/20/d42e77751910149f0ff6b879b1290f/content.htm
They don't show any examples using the table types and I can't seem to make sense of " <datatype> ::= <sql_type> | <table_type>".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kumar,
Neither one of those pages shows how to use a table type definition. I'm going to be creating a number of functions that return the same table definition. That's why I want to use a table type instead of actually defining the table in each function. That keeps the table definition on one place for all the functions that use it.
Joe Goldthwaite.
If you read the grammar correctly then I think it is not possible. Table UDF does not allow return table type that refers to another structure type definition but only elementary sql_type
I think what grammar you refering is from input parameters
Table Functions must return a table whose type is defined by <return_table_type>. And Scalar Funcitons must return scalar values specified in <return_parameter_list>.
Defines the output parameters
<return_table_type> ::= TABLE ( <ret_column_list> )
Defines the structure of the returned table data.
<ret_column_list> ::= <ret_column_elem>[{, <ret_column_elem>}...]
Defines the list of columns returned from the function.
<ret_column_elem> ::= <column_name> <sql_type>
<column_name> ::= <identifier>
Thanks Sagar. I appreciate the input. It turns out you can do it and I was able to figure it out. You just leave off the TABLE and declaration like this:
CREATE FUNCTION MY_SCHEMA.MY_FUNCTION()
RETURNS MY_SCHEMA.TT_MY_TABLE_TYPE
Where TT_MY_TABLE_TYPE is a predefined table type. It works like a charm.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
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.