如何编写参数化的Oracle插入查询? [英] How to write parameterized oracle insert query?

查看:177
本文介绍了如何编写参数化的Oracle插入查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Oracle作为我的后端和我写插入查询如下,我不知道是不是正确的方法都没有,

I am using oracle as my back end and i write insert query as follows, i don't know is it correct way are not,

insert into Emp_table (SL_NO,empane,empid,salaray) values(1,'sree',1002 ,:salary);



在这里查询我正在计算工资与存储过程和获取我的输出参数的工资,所以我有传递到我的插入查询我这样怎么能写。如果我写这样如我得到下面的错误

here in query i am calculating salary with stored procedure and getting as my out parameter salary so i has to pass that to my insert query so how can i write. if i write like as shown i am getting below errors

ORA-06550: line 1, column 175:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored

好心帮我。

推荐答案

假设工资金额为20000 ,你可以试试这个代码:

Assuming salary amount is 20000, You can try this code:

var commandText = "insert into Emp_table (SL_NO,empane,empid,salaray) values(:SL_NO,:empane,:empid,:salary)";

using (OracleConnection connection = new OracleConnection(connectionString))
using (OracleCommand command = new OracleCommand(commandText, connection))
{
    command.Parameters.AddWithValue("SL_NO", 1);
    command.Parameters.AddWithValue("empane", "sree");
    command.Parameters.AddWithValue("empid", 1002);
    command.Parameters.AddWithValue("salaray", 20000);
    command.Connection.Open();
    command.ExecuteNonQuery();
    command.Connection.Close();
}

这篇关于如何编写参数化的Oracle插入查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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