Connecting Tech Pros Worldwide Forums | Help | Site Map

Executing Oracle Stored Functions.

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#1   Sep 8 '07
Oracle Function with IN type as parameter mode.
========================================
Expand|Select|Wrap|Line Numbers
  1. create or replace function mydatefun(dt date) return varchar2
  2. as
  3. mdate varchar2(50);
  4. begin
  5. select to_char(dt,'ddspth month year') into mdate from dual;
  6. return mdate;
  7. end;
To call the above Oracle Function from VB.
================================
Expand|Select|Wrap|Line Numbers
  1. 'general declaration
  2. Dim CON As New ADODB.Connection
  3. Dim PR As New ADODB.Parameter
  4. Dim PR1 As New ADODB.Parameter
  5.  
  6. Private Sub Command1_Click()
  7. CON.Open "Provider=MSDAORA.1;Password=DEBASIS;User ID=DEBASIS;Data Source=OM;Persist Security Info=True"
  8. Dim CMD As New ADODB.Command
  9. Dim RS As ADODB.Recordset
  10. CMD.ActiveConnection = CON
  11. CMD.CommandType = adCmdText
  12. 'DT---This is the datepicker control
  13. CMD.CommandText = "select mydatefun(to_date('" & DT.Value & "','mm/dd/yyyy')) from dual"
  14. Set RS = CMD.Execute
  15. If RS.EOF = False Then
  16. If Not IsNull(RS(0)) Then
  17. Text2.Text = RS(0)
  18. Else
  19. Text2.Text = "Invalid date"
  20. End If
  21. End If
  22. CMD.Cancel
  23. CON.Close
  24. End Sub



Closed Thread