The important thing is to recognise and resist the temptation of the Utilities package. The name itself (and similarly vague synonyms like helper or utils) should be a red flag. When we find ourselves about to type create or replace package utilities we need to stop and think: what would be a better name for this package? Consider whether there are related functions we might end up needing? Suppose we're about to write a function to convert a date into Unix epoch string. It doesn't take much imagine to think we might need a similar function to convert a Unix timestamp into a date. We don't need to write that function now but let's start a package dedicated to Time functions instead of a miscellaneous utils package.
Looking closely at the programs which comprise the DBMS_UTILITY package it is obviously unfair to describe them as a random selection. In fact that there seven or eight groups of related procedures.
DB Info
INSTANCE_RECORDRecord TypeDBLINK_ARRAYTable TypeINSTANCE_TABLETable TypeACTIVE_INSTANCESProcedureCURRENT_INSTANCEFunctionDATA_BLOCK_ADDRESS_BLOCKFunctionDATA_BLOCK_ADDRESS_FILEFunctionDB_VERSIONProcedureGET_ENDIANNESSFunctionGET_PARAMETER_VALUEFunctionIS_CLUSTER_DATABASEFunctionMAKE_DATA_BLOCK_ADDRESSFunctionPORT_STRINGFunction
FORMAT_CALL_STACKFunctionFORMAT_ERROR_BACKTRACEFunctionFORMAT_ERROR_STACKFunction
COMMA_TO_TABLEProceduresCOMPILE_SCHEMAProcedureCREATE_ALTER_TYPE_ERROR_TABLEProcedureINVALIDATEProcedureTABLE_TO_COMMAProceduresVALIDATEProcedure
INDEX_TABLE_TYPETable TypeLNAME_ARRAYTable TypeNAME_ARRAYTable TypeNUMBER_ARRAYTable TypeUNCL_ARRAYTable TypeCANONICALIZEProcedureGET_DEPENDENCYProcedureNAME_RESOLVEProcedureNAME_TOKENIZEProcedure
OLD_CURRENT_SCHEMAFunctionOLD_CURRENT_USERFunction
EXPAND_SQL_TEXTProcedureGET_SQL_HASHFunctionSQLID_TO_SQLHASHFunction
ANALYZE_DATABASEProcedureANALYZE_PART_OBJECTProcedureANALYZE_SCHEMAProcedure
GET_CPU_TIMEFunctionGET_TIMEFunctionGET_TZ_TRANSITIONSProcedure
WAIT_ON_PENDING_DMLFunctionEXEC_DDL_STATEMENTProcedureGET_HASH_VALUEFunctionIS_BIT_SETFunction
We can see an alternative PL/SQL code suite, with several highly cohesive packages. But there will be some procedures which are genuinely unrelated to anything else. The four procedures in the Unclassified section above are examples. But writing a miscellaneous utils package for these programs is still wrong. There are better options.
- Find a home. It's worth considering whether we already have a package which would fit the new function. Perhaps
WAIT_ON_PENDING_DML()should have gone inDBMS_TRANSACTION; perhapsIS_BIT_SET()properly belongs inUTL_RAW. - A package of their own. Why not? It may seem extravagant to have a package with a single procedure but consider
DBMS_DGwith its lone procedureINITIATE_FS_FAILOVER(). The package delivers the usual architectural benefits plus it provides a natural home for related procedures we might discover a need for in the future. - Standalone procedure. Again, why not? We are so conditioned to think of a PL/SQL program as a package that we forget it can be just a Procedure or Function. Some programs are suited to standalone implementation.
So avoiding the Utilities package requires vigilance. Code reviews can help here. Preventing the Utilities package becoming entrenched is crucial: once we have a number of packages dependent on a Utilities package it is pretty hard to get rid of it. And once it becomes a fixture in the code base developers will consider it more acceptable to add procedures to it.
1 comment:
very interesting article I feel very enthusiastic while reading and the information
provided in this article is so useful for me. Content in this article guides in clarifying some of my doubts.For additional information please visit our website.
Oracle Fusion Financial Training
Post a Comment