README.default_parameters 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. SQL Language Extension: default paremeters in stored procedures
  2. Function:
  3. allow input parameters of stored procedures to have optional default values
  4. Autor:
  5. Vlad Horsun <horsun at kdb.dp.ua>
  6. Syntax:
  7. same as default value definition of column or domain, except that
  8. you can use '=' in place of 'DEFAULT' keyword. Parameters with default values
  9. must be last in parameter list i.e. not allowed to define parameter without
  10. default value after parameter with default value. Caller must set first few
  11. parameters, i.e. not allowed set param1, param2, miss param3, set param4...
  12. Default values substitution occurs at run-time. If you define procedure with
  13. defaults (say P1), call it from another procedure (say P2) and skip some last
  14. parameters (with default value) then default values for P1 will be substituted
  15. by the engine at time of the beginning of execution P1. Then if you change
  16. default values for P1 it is not need to recompile P2. But it is still necessary
  17. to disconnect all client connections, for more details see IB6 Beta documentation
  18. "Data Definition Guide", section "Altering and dropping procedures in use"
  19. Examples:
  20. CONNECT ... ;
  21. CREATE PROCEDURE P1 (X INTEGER = 123)
  22. RETURNS (Y INTEGER)
  23. AS
  24. BEGIN
  25. Y = X;
  26. SUSPEND;
  27. END;
  28. COMMIT;
  29. SELECT * FROM P1;
  30. Y
  31. ============
  32. 123
  33. EXECUTE PROCEDURE P1;
  34. Y
  35. ============
  36. 123
  37. CREATE PROCEDURE P2
  38. RETURNS (Y INTEGER)
  39. AS
  40. BEGIN
  41. FOR SELECT Y FROM P1 INTO :Y
  42. DO SUSPEND;
  43. END;
  44. COMMIT;
  45. SELECT * FROM P2;
  46. Y
  47. ============
  48. 123
  49. ALTER PROCEDURE P1 (X INTEGER = CURRENT_TRANSACTION)
  50. RETURNS (Y INTEGER)
  51. AS
  52. BEGIN
  53. Y = X;
  54. SUSPEND;
  55. END;
  56. COMMIT;
  57. SELECT * FROM P1;
  58. Y
  59. ============
  60. 5875
  61. SELECT * FROM P2;
  62. Y
  63. ============
  64. 123
  65. COMMIT;
  66. CONNECT ... ;
  67. SELECT * FROM P2;
  68. Y
  69. ============
  70. 5880
  71. Notes:
  72. default sources and BLR's are kept in RDB$FIELDS