在列名中搜索字符串并返回该列的值列表 Anylogic [英] Search table for string in column name and return list of values for that column Anylogic

查看:29
本文介绍了在列名中搜索字符串并返回该列的值列表 Anylogic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表.我想使用列名的字符串column_n"在表中搜索该列中的值(任何字符串列名的代码都需要相同).代码需要返回该列中所有值的列表(按照它们在列中出现的顺序).

I have the table below. I want to use the string of the column name, "column_n", to search the table for the values in that column (code needs to be the same for any string column name). The code needs to return a list of all the values from that column (in the same order as they appear in the column).

我尝试在 Anylogic 中执行此操作,但软件需要在代码中写入列的名称(即 selectFrom(db).list(db.column_1) ).需要能够为任何列名动态执行此操作.

I tried doing this in Anylogic but the software requires to write the name of the column in the code (i.e. selectFrom(db).list(db.column_1) ). Need to be able to do this dynamically for any column name.

<头>
activity_idcolumn_1column_2...column_n
活动1123
activity2011
activity3400
activity4124

推荐答案

使用 AnyLogic 数据库查询的 SQL 形式,而不是您在此处使用的 QueryDSL 样式;然后您可以轻松地将所需的列名组装"到 SQL 字符串中.例如

Use the SQL form of AnyLogic database queries instead of the QueryDSL style you're using here; then you can easily just 'assemble' the required column name into the SQL string. For example

List<Integer> intColValues = selectValues("SELECT " + colName + " FROM table_1;");

例如,colName 是包含上述代码的函数的 (String) 参数.

where, for example, colName is the (String) argument to a function including the code above.

这篇关于在列名中搜索字符串并返回该列的值列表 Anylogic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆