0

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

我的代码:

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);
4

1 回答 1

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");
于 2013-10-02T14:31:30.857 回答