Bilal
Bilal

Reputation: 21

Calling a stored Oracle procedure in C#

so i want to call a stored procedure(Oracle) in C#, but i don't know the exact syntax, and in addition i don't know whether it needs parameters or not, because this procedure is taking the parameters and assigning it automatically so what parameter should i pass to it?

Below is the stored procedure

create or replace procedure p_delete_tt_duration_10min is
new_status varchar2(50);
status     varchar2(20);
p_tkt      varchar2(50);

cursor prt_cursor is

 SELECT a.id,
        a.ticketno,
        to_number(a.outagedurationmin),
        a.fault_occur_time,
        a.auto_clear_time
   FROM pmp_bpm_troubleticket a
  WHERE a.fault_id IS NOT NULL
    AND a.fault_occur_time IS NOT NULL
       --and a.generatedby = 'Automatic'
    AND ((a.tt_type IN ('Cell/Sector Down',
                        '3G Cell Down Alarm',
                        '4G Cell Down Alarm') AND
        to_number(a.outagedurationmin) < 18) OR
        (a.tt_type IN ('Site Down',
                        'NodeB Down Alarm',
                        'ENodeB Down Alarm',
                        'TRX/Equipment Faulty',
                        'Processing Problem',
                        'GPRS Down',
                        'Media disconnect',
                        'Hardware Fault',
                        'Link Down') and
        to_number(a.outagedurationmin) < 10))
    AND a.fault_occur_time >= '2017-04-01 00:00:00' order by to_number(a.outagedurationmin) desc;


begin
for prt_temp in prt_cursor loop
  p_tkt := prt_temp.id;
   delete from wf_assignment t
    where t.assignment_id in
       (select id from wf_dai_ban_task a where a.primary_key = p_tkt);
commit;
delete from wf_dai_ban_task a where a.primary_key = p_tkt;
commit;
delete from wf_yi_ban_task a where a.primary_key = p_tkt;
commit;
delete from pmp_bpm_task_expand_info a where a.primary_key = p_tkt;
commit;
delete from PMP_BPM_CC_LIST a where a.primarykey = p_tkt;
commit;
delete FROM PMP_BPM_TROUBLETICKET_PROCESS D
 WHERE D.ACTIVITYID IN (SELECT W.ID
                          FROM PMP_BPM_TROUBLETICKET_ACTIVITY W
                         WHERE W.PRIMARYKEY = p_tkt);
commit;
delete from PMP_BPM_TROUBLETICKET_ACTIVITY a
 where a.primarykey = p_tkt;
commit;
delete from PMP_BPM_TROUBLETICKET a where a.id = p_tkt;
commit;

end loop;
 end;

Thanks in advance.

Upvotes: 1

Views: 1555

Answers (1)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59652

Did you check any documentation, this is pretty basic:

string constr = "User Id=scott;Password=tiger;Data Source=oracle";
OracleConnection con = new OracleConnection(constr);
con.Open();

OracleCommand cmd = new OracleCommand("BEGIN p_delete_tt_duration_10min; END;", con);
// Auto-commit changes
cmd.ExecuteNonQuery();

// Clean up
cmd.Dispose();
con.Dispose();

You can also write

OracleCommand cmd = new OracleCommand("p_delete_tt_duration_10min", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();

Upvotes: 2

Related Questions