正确使用oracle阅读器的方法?

时间:2013-10-01 00:29:47

标签: c# regex linq c#-4.0 oracle11g

11GR2 ......我想为每个表获取Alter语句并运行结果脚本以使两个表相同。但是我的结果如下所示,我如何才能使每个Alter语句结束;分号,看起来像我的结果?我认为问题是为每个表制作alter语句并在每个表之后放置终止符,它不会放入每个alter语句;半列终结者......有什么想法吗?

mycode的:

myCommand = "select DBMS_METADATA_DIFF.COMPARE_ALTER('TABLE','GM_X','GM_X','SCOTT','GARY') from dual";

    using (OracleCommand Command = new OracleCommand(myCommand, conn1))
   {
     using (OracleDataReader reader = Command.ExecuteReader())
   {
     reader.Read();
     string[] split = reader[0].ToString().Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

 foreach (string line in split)
   {
      RichTextBox1.AppendText(reader[0].ToString().Trim() + ";" + Environment.NewLine);
   }

结果;

ALTER TABLE " TABLE_NAME_1" MODIFY ("INVH" VARCHAR2(15));
ALTER TABLE " TABLE_NAME_2" MODIFY ("REODE" VARCHAR2(15));
ALTER TABLE " TABLE_NAME_3" MODIFY ("CUST" NOT NULL ENABLE)
  ALTER TABLE " TABLE_NAME_3" MODIFY ("CODE" VARCHAR2(14))
  ALTER TABLE " TABLE_NAME_3" MODIFY ("CODE" NOT NULL ENABLE)
  ALTER TABLE " TABLE_NAME_3" MODIFY ("E_CODE" NOT NULL ENABLE)
  ALTER TABLE " TABLE_NAME_3" MODIFY ("_GR2" NOT NULL ENABLE);

我想要这个结果:

 ALTER TABLE " TABLE_NAME_1" MODIFY ("INVH" VARCHAR2(15));
    ALTER TABLE " TABLE_NAME_2" MODIFY ("REODE" VARCHAR2(15));
    ALTER TABLE " TABLE_NAME_3" MODIFY ("CUST" NOT NULL ENABLE);
      ALTER TABLE " TABLE_NAME_3" MODIFY ("CODE" VARCHAR2(14));
      ALTER TABLE " TABLE_NAME_3" MODIFY ("CODE" NOT NULL ENABLE);
      ALTER TABLE " TABLE_NAME_3" MODIFY ("E_CODE" NOT NULL ENABLE);
      ALTER TABLE " TABLE_NAME_3" MODIFY ("_GR2" NOT NULL ENABLE);

1 个答案:

答案 0 :(得分:0)

在foreach中,您希望使用名为split的字符串遍历每个line元素。您的代码不会这样做:

   foreach (string line in split)
   {
      RichTextBox1.AppendText(reader[0].ToString().Trim() + ";" + Environment.NewLine);
   }

你没有在每次迭代中使用你刚从split中获得的那一行。你想要这个:

   foreach (string line in split)
   {
      RichTextBox1.AppendText(line + ";" + Environment.NewLine);
   }

如果只是用\n替换;\n,则甚至不需要遍历行元素。

string alterTableStatements = reader[0].ToString().Trim().Replace("\n", ";\n");