Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. ex 9
  2. create or replace trigger delaccount
  3. after delete on account
  4. for each row
  5. begin
  6. if:old.balance >0 then
  7. raise_application_error(-20001, 'You still have cash buddy');
  8. rollback;
  9. end if;
  10. end;
  11.  
  12. delete from account where accountno =1;
  13. insert into account values(5,1515151515, 0);
  14. ZADANIE 15
  15. select * from (
  16. select name,
  17. salary,
  18. dense_rank() over (order by salary desc) as rnk
  19. from person)
  20. where rnk <= 3 and rownum<=3;
  21. ZADANIE 5
  22. static void Insertexample()
  23. // inserts a new record in workplace
  24. {
  25.  
  26. string cprstring;
  27. string companystring;
  28. Console.WriteLine("Indtast cpr-number");
  29. cprstring = Console.ReadLine();
  30. Console.WriteLine("Indtast company-number");
  31. companystring = Console.ReadLine();
  32.  
  33. string sql;
  34. sql = "insert into workplace values ('"+ cprstring + "'," + companystring + ")";
  35. //OracleCommand cmd = new OracleCommand();
  36.  
  37. DbCommand cmd = dbFactory.CreateCommand();
  38. cmd.Connection = con;
  39. cmd.CommandText = sql;
  40.  
  41. // lćs tabellen person
  42. try
  43. { // ĺbn forbindelse til database
  44. con.Open();
  45. cmd.ExecuteNonQuery();
  46. Console.WriteLine("The insert is done");
  47. }
  48. catch (OracleException ex)
  49. {
  50.  
  51. if (ex.Message.Contains("ORA-02291: integrity constraint (SYSTEM.CPRFOREIGN)"))
  52. Console.WriteLine("The cpr number does not exits");
  53. if (ex.Message.Contains("ORA-02291: integrity constraint (SYSTEM.COMPANYFOREIGN)"))
  54. Console.WriteLine("The company number does not exits");
  55. if(ex.Message.Contains("ORA-00001"))
  56. Console.WriteLine("Person already exists in company");
  57.  
  58. }
  59.  
  60. finally
  61. { // luk forbindelse til databasen
  62. con.Close();
  63. }
  64.  
  65. Console.WriteLine();
  66. Console.WriteLine("---------------------------------------------------------------------");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement