列如 表USERA NAME AGE
表USERB NAME AGE ADDRESS插入语句using (OracleConnection connection = new OracleConnection(WebConfigHelper.ConnectionString))
{
connection.Open();
OracleTransaction transaction = connection.BeginTransaction();
try
{
string strSql = "INSERT INTO USERA(NAME,AGE) VALUES('{0}','{1}') INSERT INTO USERB(NAME ,AGE, ADDRESS) VALUES('{2}','{3}','{4}')";
strSql = string.Format(strSql, "小明", "12", "小红", "15", "北京市");
OracleHelper.ExecuteNonQuery(transaction, CommandType.Text, strSql);
transaction.Commit();
return true;
}
catch (Exception e)
{
transaction.Rollback();
LogHelper.WriteLog("执行方法AddCiname时出错,异常详细:" + e.Message);
return false;
}
}想用 一个strSql 字符串完成两条Sql语句 求高手解答我这样写行不行,有其他方法嘛? 本人新手没用过
表USERB NAME AGE ADDRESS插入语句using (OracleConnection connection = new OracleConnection(WebConfigHelper.ConnectionString))
{
connection.Open();
OracleTransaction transaction = connection.BeginTransaction();
try
{
string strSql = "INSERT INTO USERA(NAME,AGE) VALUES('{0}','{1}') INSERT INTO USERB(NAME ,AGE, ADDRESS) VALUES('{2}','{3}','{4}')";
strSql = string.Format(strSql, "小明", "12", "小红", "15", "北京市");
OracleHelper.ExecuteNonQuery(transaction, CommandType.Text, strSql);
transaction.Commit();
return true;
}
catch (Exception e)
{
transaction.Rollback();
LogHelper.WriteLog("执行方法AddCiname时出错,异常详细:" + e.Message);
return false;
}
}想用 一个strSql 字符串完成两条Sql语句 求高手解答我这样写行不行,有其他方法嘛? 本人新手没用过
into test1(id,name,sex,cj)
into test2(id,name,sex,cj)
into test3(id,name,sex,cj)
select id,name,sex,cj from test ; 依据条件实现: insert all
when id <10 then
into test1(id,name,sex,cj)
when id >10 and id<50 then
into test2(id,name,sex,cj)
when id >50 and id<1000 then
into test3(id,name,sex,cj)
select id,name,sex,cj from test
我的sqlstring strSql = "insert all
INTO USERA(NAME,AGE) VALUES('{0}','{1}')
INTO USERB(NAME ,AGE, ADDRESS) VALUES('{2}','{3}','{4}')";
strSql = string.Format(strSql, "小明", "12", "小红", "15", "北京市");
这样吧
VALUES
(NAME,
AGE,
ADDRESS
) WHEN ADDRESS IS NOT NULL THEN INTO USERB
VALUES
(NAME,
AGE,
ADDRESS
)
SELECT '小明' NAME, '12' AGE ,'' ADDRESS FROM DUAL
UNION ALL
SELECT '小红' NAME , '15' AGE , '北京市' ADDRESS FROM DUAL
INSERT ALL WHEN ADDRESS IS NULL THEN INTO USERA
VALUES
(NAME,
AGE
) WHEN ADDRESS IS NOT NULL THEN INTO USERB
VALUES
(NAME,
AGE,
ADDRESS
)
SELECT '小明' NAME, '12' AGE ,'' ADDRESS FROM DUAL
UNION ALL
SELECT '小红' NAME , '15' AGE , '北京市' ADDRESS FROM DUAL ;