Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Using dymanic table name for running select queries

$
0
0

Hi there. Currently got a problem with performing the following task:

     Perform fulltext search on all tables that have created fulltext indexes in specific schema. Result should look like this:

          <TABLE_NAME1>                <ID_FROM_TABLE>

          <TABLE_NAME1>                <ID_FROM_TABLE>

          <TABLE_NAME2>                <ID_FROM_TABLE>

          <TABLE_NAME2>                <ID_FROM_TABLE>

     At the moment all tables have the same ID column UOI_ID.

 

What I've tried so far is the following:

 

PROCEDURE "tuser"."dam.test.db.procedures::textSearch" ( in keyword NVARCHAR(300), out search_results "tuser"."dam.test.db::tuser.procedures.tt_search_results" )

  LANGUAGE SQLSCRIPT

  SQL SECURITY INVOKER

  DEFAULT SCHEMA "tuser"

  AS

BEGIN

/*****************************

  Write your procedure logic

*****************************/ 

 

  DECLARE counter Integer := 1;

  DECLARE row_count Integer;

  DECLARE table_name NVARCHAR(300);

  DECLARE schema_name NVARCHAR(300) := 'tuser';

 

  indexed_tables = SELECT row_number() OVER (ORDER BY "TABLE_NAME") AS ROW_NUMBER, "TABLE_NAME"

       FROM (

            SELECT DISTINCT "TABLE_NAME"

                 FROM "SYS"."FULLTEXT_INDEXES"

                      WHERE "SCHEMA_NAME" = :schema_name

       );

 

  SELECT COUNT(*) INTO row_count FROM :indexed_tables;

 

  WHILE counter < row_count + 1 DO

 

       SELECT '"tuser"."'||"TABLE_NAME"||'"' INTO table_name FROM :indexed_tables WHERE "ROW_NUMBER" = :counter;

 

       temporary_results = SELECT :table_name AS TABLE_NAME, "OUI_ID" AS ID

            FROM :table_name

                 WHERE contains(*, :keyword, fuzzy(0.5));

 

       search_results = CE_UNION_ALL(:search_results, :temporary_results);

 

       counter := counter + 1;

 

  END WHILE;

 

END;

 

 

At this point it's impossible to perform the:

... FROM :table_name ...

 

The error is:

Could not create catalog object: scalar type is not allowed

 

Tried doing it with CE functions.

 

temporary_table = CE_COLUMN_TABLE(table_name);

 

The error is:

Dependent object not found: SqlScript; tuser.TABLE_NAME

 

So the question is: How to dynamically put table name into "FROM ..." statement?


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>