其中 table 包含列
Which table contains column
有建立select语句的程序,例如
public void GetLog(DataSet dataSet, string tableName, string userCase){
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
tmpSql = @"select * from table1 t1
join table2 on t1.key=t2.key
where 1=1 and "+userCase
cmd.CommandType = CommandType.Text;
adapter = new OracleDataAdapter(cmd);
adapter.SelectCommand = cmd;
adapter.Fill(dataSet, tableName);
}
两个 tables 都包含一个列,例如 "NAME",当 userCase 类似于 "name='BLABLA'" 我有例外 "ora-00918 column ambiguously defined"。我想将 table 名称添加到 userCase 中。我如何获取 table 包含此列的信息,以便将其添加到 var userCase "table1.name='BLABLA'" 中。 userCase 可以包含 table1 或 table2 中的任何列。我需要更改程序,以便它通过 sql 或 table 的名称
获取元数据
您似乎已经将 tableName 作为 Method 参数传递。如果那是包含 userCase 列的 table,那么您可以这样写:
tmpSql = @"select * from table1 t1
在 t1.key=t2.key 上加入 tablet2
其中 1=1 和 "+tableName+"."+userCase
如果您在多个 table 中有同名的列,那么计算机无法知道您指的是哪一个,除非您指定它(通过将其作为 userCase 的一部分传递,或者如上所示连接它)。如果列是单列 table,那么您无需担心。
此致,
需要换sql喜欢
tmpSql = @"select * from (select t1.key as t1_key,t2.key as t2_key, t1.name as t1_name,t2.name as t2_name..... from table1 t1
join table2 on t1.key=t2.key )
where t2_name='...'
并且条件 userCase 应该基于别名
有建立select语句的程序,例如
public void GetLog(DataSet dataSet, string tableName, string userCase){
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
tmpSql = @"select * from table1 t1
join table2 on t1.key=t2.key
where 1=1 and "+userCase
cmd.CommandType = CommandType.Text;
adapter = new OracleDataAdapter(cmd);
adapter.SelectCommand = cmd;
adapter.Fill(dataSet, tableName);
}
两个 tables 都包含一个列,例如 "NAME",当 userCase 类似于 "name='BLABLA'" 我有例外 "ora-00918 column ambiguously defined"。我想将 table 名称添加到 userCase 中。我如何获取 table 包含此列的信息,以便将其添加到 var userCase "table1.name='BLABLA'" 中。 userCase 可以包含 table1 或 table2 中的任何列。我需要更改程序,以便它通过 sql 或 table 的名称
获取元数据您似乎已经将 tableName 作为 Method 参数传递。如果那是包含 userCase 列的 table,那么您可以这样写:
tmpSql = @"select * from table1 t1
在 t1.key=t2.key 上加入 tablet2 其中 1=1 和 "+tableName+"."+userCase
如果您在多个 table 中有同名的列,那么计算机无法知道您指的是哪一个,除非您指定它(通过将其作为 userCase 的一部分传递,或者如上所示连接它)。如果列是单列 table,那么您无需担心。
此致,
需要换sql喜欢
tmpSql = @"select * from (select t1.key as t1_key,t2.key as t2_key, t1.name as t1_name,t2.name as t2_name..... from table1 t1
join table2 on t1.key=t2.key )
where t2_name='...'
并且条件 userCase 应该基于别名