Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. use Win32::ODBC;
  2.  
  3. $db= new Win32::ODBC("DSN=datasourcename;UID=username;PWD=passwrd")
  4. || die "Error: " . Win32::ODBC::Error();
  5.  
  6. $db->Sql("SELECT emp_Id, emp_name, salary FROM Sample.Emp");
  7.  
  8. while($db->FetchRow())
  9. {
  10. @values = $db->Data;
  11. print @values;
  12. }
  13. $db->Close();
  14.  
  15. PROCEDURE sp_rank(p_cursorVar out CursorType)
  16. is
  17. begin
  18. open p_cursorVar for
  19. select emp_id, emp_name from emp;
  20.  
  21. End sp_rank;
  22.  
  23. #!/usr/bin/perl
  24.  
  25. use strict;
  26. use warnings;
  27. use DBI;
  28.  
  29. my $datasource = "datasourcename";
  30. my $username = "foobar";
  31. my $password = "secret";
  32. # connect to your database with a database handle
  33. my $dbh = DBI->connect("DBI:Oracle:$datasource",$username,$password) or die $DBI::errstr();
  34. # create a statement handle for database interaction
  35. my $sth = $dbh->prepare("SELECT emp_Id, emp_name, salary FROM Sample.Emp");
  36. $sth->execute();
  37. # fetch the rows and print them
  38. while($sth->fetchrow_arrayref()){
  39. @values = @$_;
  40. print @values;
  41. }
  42. # never forget to close your statement handle
  43. $sth->finish();
  44.  
  45. # using your stored procedure
  46. # overwrite your finished statement handle with a new one
  47. $sth = $dbh->prepare("sp_rank()");
  48. $sth->execute();
  49. # fetch all your data into an array hashref structure. the column names in your DB are the keys in the hashref
  50. my $data = $sth->fetchall_arrayref({});
  51. $sth->finish();
  52.  
  53. $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement