我想在C#程序中将HEX字符串作为参数传递给 oracle存储过程。存储过程以df['date from'] = pd.to_datetime(df['date from'])
df['date to'] = pd.to_datetime(df['date to'])
d = {'date from':['min', 'idxmin'], 'date to':['max', 'idxmax']}
df1 = df.set_index('Subjectname').groupby(['id','name']).agg(d)
df1.columns = df1.columns.map('_'.join)
d1 = {'date from_min':'from','date to_max':'to',
'date from_idxmin':'subject from','date to_idxmax':'subject to'}
cols = ['from','to','subject from','subject to']
df1 = df1.rename(columns=d1).reindex(columns=cols).reset_index()
print (df1)
id name from to subject from subject to
0 1188 Cera 2016-01-08 2016-09-30 math math
1 1199 ron 2017-01-06 NaT english NaN
2 1288 Snow 2017-01-01 NaT tally NaN
3 1433 sansa 2016-01-25 2017-01-16 tally tally
4 1522 stark 2016-01-01 NaT phy NaN
5 1722 sid 2017-01-06 2018-03-31 history history
6 1844 amy 2016-01-01 2017-10-11 science adv
7 2100 arya 2016-01-08 2017-05-31 english math
作为输入参数。因此,我需要将HEX转换为RAW,然后将RAW转换为varchar2
。以下代码显示了这个想法。
varchar2
目前,此代码无法工作。谁能给我有关如何正确执行操作的建议。
答案 0 :(得分:0)
对于 Oracle ,请尝试使用匿名块(begin..end;
语法,而不是call
):
//DONE: do not forget to dispose IDsiposable
using (OracleCommand cmd = new OracleCommand()) {
cmd.Connection = conn;
cmd.CommandType = CommandType.Text; // redundant, can be dropped
cmd.CommandText =
@"begin
checking(utl_raw.cast_to_varchar2(hextoraw(:in_data)), :return_cde);
end";
// 5000 - be careful - in SQL Oracle can operate with VarChar2 up to 4000;
// in PL/SQL, however, the limit is 32000
cmd.Parameters.Add("in_data",
OracleDbType.Varchar2,
5000,
"000102030405060708090A0B0C0D",
ParameterDirection.Input);
cmd.Parameters.Add("return_cde",
OracleDbType.Varchar2,
8,
"OK",
ParameterDirection.InputOutput);
cmd.ExecuteNonQuery();
return_cde = cmd.Parameters["return_cde"].Value.ToString();
}