SlideShare una empresa de Scribd logo
1 de 35
Ten Things You Should  NEVER  Do With PL/SQL Steven Feuerstein PL/SQL Evangelist Quest Software [email_address]
And  Oracle  says.... ,[object Object]
Eleven Years Writing Ten Books   on the Oracle PL/SQL Language
How to benefit most from this presentation ,[object Object],[object Object],[object Object],[object Object],[object Object],filename_from_demo_zip.sql
Ten things you should never do with PL/SQL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
1. Never ask for help. ,[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS ask for help! ,[object Object],[object Object],[object Object],[object Object],If you cannot fix the problem in 30 minutes, ask for help.
2. Never skip the coffee. ,[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS skip the coffee. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3. Never share what you learn. ,[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS share what you learn. ,[object Object],[object Object],[object Object],[object Object]
Free resources for PL/SQL developers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.oracle.com/technology/tech/pl_sql/index.html http://www.oracle.com/technology/pub/columns/plsql/index.html http://tahiti.oracle.com/ http://oracleplsqlprogramming.com/ http://quest-pipelines.com/ http://quest-pipelines.com/pipelines/dba/PLVision/plvision.htm http://www.unit-test.com  or  http://unittest.inside.quest.com/index.jspa
4. Never doubt the gurus. ,[object Object],[object Object],[object Object],[object Object]
ALWAYS challenge the gurus. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],show_memory.sp plvtmr.pkg tmr.ot  emplu.pkg
5. Never hide the details in your code. ,[object Object],[object Object],[object Object],[object Object]
ALWAYS hide the details in your code. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nicely exposed code? ,[object Object],[object Object],CREATE OR REPLACE PROCEDURE process_employee ( employee_id_in IN number) IS l_name VARCHAR2(100); BEGIN SELECT last_name || ',' || first_name INTO l_name FROM employee WHERE employee_id = employee_id_in; ... END;
Let’s SPODify some code... l_name employee_rp.fullname_t; BEGIN l_name :=  employee_rp.fullname (  employee_id_in);  ... END; CREATE OR REPLACE PACKAGE  employee_rp AS SUBTYPE fullname_t IS  VARCHAR2 (200); -- The formula FUNCTION fullname ( l employee.last_name%TYPE, f employee.first_name%TYPE ) RETURN fullname_t; -- Retrieval function FUNCTION fullname ( employee_id_in IN employee.employee_id%TYPE ) RETURN fullname_t; END; CREATE OR REPLACE PROCEDURE process_employee ( employee_id_in IN number) IS l_name VARCHAR2(100); BEGIN SELECT last_name || ',' || first_name INTO l_name FROM employee WHERE employee_id =  employee_id_in; ... END;
And more spodification: error handling WHEN NO_DATA_FOUND THEN INSERT INTO errlog VALUES ( SQLCODE , 'No company for id ' || TO_CHAR ( v_id ) , 'fixdebt', SYSDATE, USER ); WHEN OTHERS THEN INSERT INTO errlog VALUES (SQLCODE, SQLERRM, 'fixdebt', SYSDATE, USER ); RAISE; END; EXCEPTION WHEN NO_DATA_FOUND THEN  errpkg.record_and_continue  (SQLCODE,  ' No company for id ' || TO_CHAR (v_id)); WHEN OTHERS   THEN errpkg.record_and_stop ;  END; or... Hard-coded, exposed, clunky, redundant. Declarative, hidden, flexible, productive. Quest CodeGen Utility's error management framework www.qcgu.net
Always use the highest level construct available. ,[object Object],[object Object],[object Object],[object Object],[object Object],Oracle Database 10g_optimize_cfl.sql
6a. Never let anyone else read your code. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
6b. Never read someone else's code. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS look at others' code and ask others to look at yours. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
7. Never worry about tomorrow. Code for today! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS code for tomorrow. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
High level checklist for "coding for tomorrow" ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Quest CodeGen Utility www.qcgu.net Quest Code Tester www.quest.com/code-tester-for-oracle
8. Never fix bugs that users haven't found. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS test proactively and thoroughly. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
9. Never assume an Oracle bug will be fixed. ,[object Object],[object Object],[object Object],[object Object],[object Object]
ALWAYS assume a bug will be fixed. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Does a file exist? ,[object Object],DECLARE TYPE   fgetattr_t   IS   RECORD  ( fexists   BOOLEAN ,  file_length   PLS_INTEGER ,  block_size   PLS_INTEGER ); fgetattr_rec   fgetattr_t ; BEGIN UTL_FILE . fgetattr  ( LOCATION   =>  'TEMP' ,  filename   =>  'trace.log' ,  fexists   =>  fgetattr_rec . fexists ,  file_length   =>  fgetattr_rec . file_length ,  block_size   =>  fgetattr_rec . block_size ); IF   fgetattr_rec . fexists   THEN   ... END ; Unfortunately, there is/was a bug: In Oracle 9iR2, the fexists parameter is always set to TRUE, whether or not the file exists.
Quick! Share that knowledge! ,[object Object],[object Object],[object Object]
A workaround for fgetattr ,[object Object],... /* WORKAROUND START 2174036  fexists is always returned TRUE, but non-existent file has  ZERO file_length and block_size */ IF   fgetattr_rec . file_length  = 0  AND   fgetattr_rec . block_size  = 0 THEN RETURN   FALSE ; ELSE RETURN   TRUE ; END   IF ; /* WORKAROUND END 2174036 */ /* WORKAROUND FIX 2174036 When the bug is fixed, remove the IF statement  and uncomment this: RETURN fgetattr_rec.fexists; */ END   fexists ; Document the workaround, including the bug number. Include the code to be used when the workaround is no longer necessary.
10. Never say never. ,[object Object],[object Object],Things will never stay the same. Things will always be changing.
[object Object],[object Object],[object Object],For more information visit www.odtug.com, www.odtugopp.com or call 910-452-7444 ODTUG Kaleidoscope June 18 – 21, 2007 Hilton Daytona Beach Oceanfront Resort Daytona, Florida Featuring the world's SECOND PL/SQL Test a Thon!

Más contenido relacionado

Similar a You shouldneverdo

Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
Ehtisham Ali
 
What Are We Still Doing Wrong
What Are We Still Doing WrongWhat Are We Still Doing Wrong
What Are We Still Doing Wrong
afa reg
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
Edorian
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
John Choi
 
Extreme Programming practices for your team
Extreme Programming practices for your teamExtreme Programming practices for your team
Extreme Programming practices for your team
Pawel Lipinski
 
Scottish Ruby Conference 2014
Scottish Ruby Conference  2014Scottish Ruby Conference  2014
Scottish Ruby Conference 2014
michaelag1971
 

Similar a You shouldneverdo (20)

Extreme Interview Questions
Extreme Interview QuestionsExtreme Interview Questions
Extreme Interview Questions
 
Advanced java script essentials v1
Advanced java script essentials v1Advanced java script essentials v1
Advanced java script essentials v1
 
What Are We Still Doing Wrong
What Are We Still Doing WrongWhat Are We Still Doing Wrong
What Are We Still Doing Wrong
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 
30% faster coder on-boarding when you have a code cookbook
30% faster coder on-boarding when you have a code cookbook30% faster coder on-boarding when you have a code cookbook
30% faster coder on-boarding when you have a code cookbook
 
Extreme Programming practices for your team
Extreme Programming practices for your teamExtreme Programming practices for your team
Extreme Programming practices for your team
 
Weird Plsql
Weird PlsqlWeird Plsql
Weird Plsql
 
10 things you're doing wrong in Talend
10 things you're doing wrong in Talend10 things you're doing wrong in Talend
10 things you're doing wrong in Talend
 
10 things you're doing wrong in Talend
10 things you're doing wrong in Talend10 things you're doing wrong in Talend
10 things you're doing wrong in Talend
 
Low maintenance perl notes
Low maintenance perl notesLow maintenance perl notes
Low maintenance perl notes
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
 
10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programming10 tips to save you time and frustration while programming
10 tips to save you time and frustration while programming
 
Beginners guide-to-coding-updated
Beginners guide-to-coding-updatedBeginners guide-to-coding-updated
Beginners guide-to-coding-updated
 
Clean Code Software Engineering
Clean Code Software Engineering Clean Code Software Engineering
Clean Code Software Engineering
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quo
 
Good Coding Practices with JavaScript
Good Coding Practices with JavaScriptGood Coding Practices with JavaScript
Good Coding Practices with JavaScript
 
C programming guide new
C programming guide newC programming guide new
C programming guide new
 
Scottish Ruby Conference 2014
Scottish Ruby Conference  2014Scottish Ruby Conference  2014
Scottish Ruby Conference 2014
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

You shouldneverdo

  • 1. Ten Things You Should NEVER Do With PL/SQL Steven Feuerstein PL/SQL Evangelist Quest Software [email_address]
  • 2.
  • 3. Eleven Years Writing Ten Books on the Oracle PL/SQL Language
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. Let’s SPODify some code... l_name employee_rp.fullname_t; BEGIN l_name := employee_rp.fullname ( employee_id_in); ... END; CREATE OR REPLACE PACKAGE employee_rp AS SUBTYPE fullname_t IS VARCHAR2 (200); -- The formula FUNCTION fullname ( l employee.last_name%TYPE, f employee.first_name%TYPE ) RETURN fullname_t; -- Retrieval function FUNCTION fullname ( employee_id_in IN employee.employee_id%TYPE ) RETURN fullname_t; END; CREATE OR REPLACE PROCEDURE process_employee ( employee_id_in IN number) IS l_name VARCHAR2(100); BEGIN SELECT last_name || ',' || first_name INTO l_name FROM employee WHERE employee_id = employee_id_in; ... END;
  • 19. And more spodification: error handling WHEN NO_DATA_FOUND THEN INSERT INTO errlog VALUES ( SQLCODE , 'No company for id ' || TO_CHAR ( v_id ) , 'fixdebt', SYSDATE, USER ); WHEN OTHERS THEN INSERT INTO errlog VALUES (SQLCODE, SQLERRM, 'fixdebt', SYSDATE, USER ); RAISE; END; EXCEPTION WHEN NO_DATA_FOUND THEN errpkg.record_and_continue (SQLCODE, ' No company for id ' || TO_CHAR (v_id)); WHEN OTHERS THEN errpkg.record_and_stop ; END; or... Hard-coded, exposed, clunky, redundant. Declarative, hidden, flexible, productive. Quest CodeGen Utility's error management framework www.qcgu.net
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.