如何在oracle中为现有表插入给定数量的空列 [英] how to insert given number of empty columns for existing table in oracle

查看:101
本文介绍了如何在oracle中为现有表插入给定数量的空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为x的整数变量。我想要一个选择查询,创建x个空列。我怎么写这个?我不能使用循环,因为我必须在我的应用程序中将此查询用作c#字符串。



作为一个例子,我可以创建一个空列,如下所示



  SELECT  a.str_typeid,a.str_typename,a.str_status,a.strlst_user,
a.dt_entdate, ' ' as empty_column
FROM ref_productitem_disc a







然后我想用x来表示空列数。换句话说,如何创建x个空列?

解决方案

构建emply列的c#代码。



  public   static   string  show( int  r)
{
if (r > 0
{
List< string> list = new List< string>();
for int i = 0 ; i < r; i ++)
{
list.Add( ''as emplty_column +(i + 1 ));
}

return string .Join( ,list);
}
return ;
}





  string  val = show( 5 ); 
string strquery = @ SELECT a。 str_typeid,a.str_typename,a.str_status,a.strlst_user,
a.dt_entdate
+((val == )? + val)+ @
FROM ref_productitem_disc a
;





你的strQuery将是查询。


I have an integer variable called x. I want a select query with creating x number of empty columns. How can I write this ? I can't use loop because I have to use this query as a c# string in my application.

as an example I can create one empty column as below

SELECT a.str_typeid, a.str_typename, a.str_status, a.strlst_user,
       a.dt_entdate, '' as empty_column
  FROM ref_productitem_disc a




Then I want use x to number of empty columns. In other words , how can I create x number of empty columns?

解决方案

Your c# code to construct the emply column.

public static string show(int r)
        {
            if (r > 0)
            {
                List<string> list = new List<string>();
                for (int i = 0; i < r; i++)
                {
                    list.Add("'' as emplty_column" + (i + 1));
                }

                return string.Join(",", list);
            }
            return "";
        }



string val = show(5);
            string strquery = @"SELECT a.str_typeid, a.str_typename, a.str_status, a.strlst_user,
       a.dt_entdate" + ((val == "") ? "" : ","+val) + @"
  FROM ref_productitem_disc a";



Your strQuery will the query.


这篇关于如何在oracle中为现有表插入给定数量的空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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