This action might not be possible to undo. Are you sure you want to continue?
PL/SQL Evangelist Quest Software email@example.com
Copyright 2006 Steven Feuerstein - Page 1
And Oracle says....
ANYTHING STEVEN SAYS ABOUT Oracle 11g "is intended to outline Oracle's general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle's products remains at the sole discretion of Oracle.
Copyright 2006 Steven Feuerstein - Page 2
Eleven Years Writing Ten Books on the Oracle PL/SQL Language
Copyright 2006 Steven Feuerstein - Page 3
Download the training materials and supporting scripts: – http://oracleplsqlprogramming. Copyright 2006 Steven Feuerstein .How to benefit most from this presentation Watch.html – "Demo zip": all the scripts I run in my class available at http://oracleplsqlprogramming.sql Use these materials as an accelerator as you venture into new territory and need to apply new techniques.com/downloads/demo. listen.Page 4 .zip filename_from_demo_zip.com/resources. ask questions.
Copyright 2006 Steven Feuerstein . 8. Never read someone else's code. 7. 5. Never ask for help 2. Never fix bugs that users haven't found. Code for today.Ten things you should never do with PL/SQL 1. 3. 4. Never skip the coffee. Never let anyone else read your code. 9. 6b. Never share what you learn. 10. 6a. Never worry about tomorrow. Never say never. Never assume an Oracle bug will be fixed. Never hide the details in your code. Never doubt the gurus.Page 5 .
Software programmers are highly educated and very smart people. Copyright 2006 Steven Feuerstein . If we ask for help. Never ask for help. all right…. If we ask for help.Page 6 . Oh. we lose the respect of our peers. We are expected to have all the answers and maintain total control over The Machine. we show weakness.1.
ask for help.ALWAYS ask for help! By asking others for help.Page 7 . By asking for help. Copyright 2006 Steven Feuerstein . you solve your problems sooner. Leave ego out of programming! I suggest that you follow the 30 Minute Rule: If you cannot fix the problem in 30 minutes. strengthening the team. you make them feel good.
– Gone is our creativity. improves our productivity.2. Without coffee (and its close cousins. – And actually talk to other human beings. Copyright 2006 Steven Feuerstein . Oh. the world of programming would crumble. all right…. and gives us an excuse to get up from our desks.Page 8 . Diet Coke and Red Bull). discipline and motivation. Coffee helps us focus. Never skip the coffee.
exercise.Page 9 . Generally. we need to take care of our host body. Wait. – Coffee dehydrates you and a dehydrated brain just doesn’t work as effectively. But drink lots (and lots more) water. so that our brain can keep on earning that big fat paycheck! – Stretch. don't go cold turkey on caffeine. Copyright 2006 Steven Feuerstein .ALWAYS skip the coffee. don't leave! OK. and so on. take frequent breaks.
Copyright 2006 Steven Feuerstein . all right…. Who has the time to let anyone else know about the great stuff you've been doing? What's in it for me? Oh.3. If someone takes your code and tries to use it. Never share what you learn. Knowledge is power and leads to higher consulting rates.Page 10 . they will probably just mess it up.
Don't repeat history. OUGs are a great sharing mechanism. Etc. Copyright 2006 Steven Feuerstein . No human is an island. but we need to instill sharing in our every day perspective on our work.ALWAYS share what you learn. Set up mechanisms for sharing within your team and your company.Page 11 . And only share what is legally yours to share. Give and ye shall receive.
html OTN Best Practice PL/SQL http://www.com/index.htm Copyright 2006 Steven Feuerstein .com/pipelines/dba/PLVision/plvision.Free resources for PL/SQL developers Oracle Technology Network PL/SQL page http://www.com – my PL/SQL portal http://oracleplsqlprogramming.com or http://unittest.oracle.com/technology/pub/columns/plsql/index.jspa PL/Vision http://quest-pipelines.com/ Quest Code Tester for Oracle http://www.Page 12 .inside.com/ Quest Pipelines http://quest-pipelines.unit-test.oracle.html Oracle documentation http://tahiti.com/technology/tech/pl_sql/index.quest.oracle.com/ OraclePLSQLProgramming.
Never doubt the gurus. Surely if a person has written a book on a subject. – How can you write code without someone telling you what is right and what is wrong? Oh. they should not be challenged. then the common. If everyone questions the gurus and experts. all right…. everyday programmer will be lost.Page 13 .4. Copyright 2006 Steven Feuerstein .
show_memory. but otherwise….sp Copyright 2006 Steven Feuerstein . not now . operating system. You need to take the advice of experts with a grain of salt. Not here.Page 14 plvtmr.ot emplu. version.pkg tmr. you are best off ignoring them in the future. And if a "guru" is not ready to learn from others or admit that they made a mistake. may not work for you in your environment.pkg . – Especially when they appear in books that may be out of date. – What worked for him or her. etc.ALWAYS challenge the gurus. Yet another motivation to encapsulate.
Hiding isn't very friendly – and aren't we supposed to share? If you hide details of your implementation. Copyright 2006 Steven Feuerstein . all right….Page 15 . then people who debug your code have more trouble finding the lines causing the problem.5. Hiding details means taking time away from the critical task of implementing business requirements. Never hide the details in your code. Oh.
Page 16 . Aim for a Single Point of Definition (SPOD). Humans can only handle so much complexity at once. Information hiding encourages reuse. – Avoid hard-coded declarations and literal values. Can you go overboard with "hiding"? – I suppose so.ALWAYS hide the details in your code. Copyright 2006 Steven Feuerstein . – Hide business rules and formulas in functions. but it isn't exactly the biggest problem we face.
END. BEGIN SELECT last_name || '. .Nicely exposed code? The following block of code is easy to understand. Copyright 2006 Steven Feuerstein ..' || first_name INTO l_name FROM employee WHERE employee_id = employee_id_in. – But what price is paid? CREATE OR REPLACE PROCEDURE process_employee ( employee_id_in IN number) IS l_name VARCHAR2(100)..Page 17 .
Let’s SPODify some code.Page 18 .last_name%TYPE.employee_id%TYPE ) RETURN fullname_t..fullname ( employee_id_in).. END. BEGIN SELECT last_name || '. CREATE OR REPLACE PACKAGE employee_rp AS SUBTYPE fullname_t IS VARCHAR2 (200). END.fullname_t. BEGIN l_name := employee_rp.Retrieval function FUNCTION fullname ( employee_id_in IN employee.first_name%TYPE ) RETURN fullname_t. CREATE OR REPLACE PROCEDURE process_employee ( employee_id_in IN number) IS l_name VARCHAR2(100). ..The formula FUNCTION fullname ( l employee.. -. -.. l_name employee_rp. f employee.' || first_name INTO l_name FROM employee WHERE employee_id = employee_id_in. Copyright 2006 Steven Feuerstein .. . END.
. END. Quest CodeGen Utility's error management framework www.record_and_stop. ' No company for id ' || TO_CHAR (v_id)). redundant. exposed. hidden. or. 'fixdebt'. 'No company for id ' || TO_CHAR ( v_id ) ..record_and_continue (SQLCODE. WHEN OTHERS THEN errpkg. END.net Copyright 2006 Steven Feuerstein .qcgu. SQLERRM. Hard-coded. RAISE. SYSDATE. EXCEPTION WHEN NO_DATA_FOUND THEN errpkg. SYSDATE. clunky. 'fixdebt'. WHEN OTHERS THEN INSERT INTO errlog VALUES (SQLCODE.Page 19 Declarative. USER ). flexible. USER ). productive..And more spodification: error handling WHEN NO_DATA_FOUND THEN INSERT INTO errlog VALUES ( SQLCODE .
"). simply describing the action desired ("Fetch every row in this cursor. Stay as far away from the "physical" details as possible.Page 20 . Another variation on this theme. – Write less code. A great example of this is the cursor FOR loop.sql Copyright 2006 Steven Feuerstein .Always use the highest level construct available. – And Oracle can then automatically optimize the code! Oracle Database 10g_optimize_cfl.
6a. Never let anyone else read your code.Page 21 . – So there. – There are no free lunches nor free rides in programming. and you like being the expert. Let your co-workers go find their own area of expertise. Copyright 2006 Steven Feuerstein . You expended major effort getting everything just right. You spent a lot of time learning in depth the requirements. You're the expert.
– What could they possibly learn from you? You already know the best way to do everything. Never read someone else's code.6b. Your co-workers already know the best way to do everything.Page 22 . That's just plain rude. Copyright 2006 Steven Feuerstein . all right…. – What could you possibly learn from a co-worker's code? Oh.
Go extreme? XP pair programming.. and eagerly left out of code reviews. probably quite hard to work with. – Toad's CodeXpert – Other IDEs do “lint checking” – Oracle PL/SQL built-in compile-time warnings framework Copyright 2006 Steven Feuerstein .ALWAYS look at others' code and ask others to look at yours. then you are arrogant. Code review is a proven method of improving code quality and reducing bugs. If you think you can't learn from others.Page 23 . Automate code review..
Page 24 . Never worry about tomorrow. anyway? – I am too busy dealing with the bugs in front of my nose. Copyright 2006 Steven Feuerstein . – They're never going to actually use this stuff in production. all right…. – Let’s just knock this together and get it out the door. Oh. Version 1 is going to be completely rewritten for Version 2.7. Code for today! Who's got time to think about tomorrow. I am just building a throw-away prototype.
– How and where will SQL statements be written? – Provide a standard error mgt API to all developers.ALWAYS code for tomorrow. – Build instrumentation (tracing) into you code. But don't build programs that you think maybe someday another person may need. – Critical to make our code readable. Copyright 2006 Steven Feuerstein . Our programs will be around for years. – That just leads to code bloat.Page 25 . Set clear standards before starting. maintainable and testable.
com/code-tester-for-oracle .qcgu.High level checklist for "coding for tomorrow" Don't write SQL in the application layer. Copyright 2006 Steven Feuerstein .net Quest Code Tester www. Add tracing calls to critical. Build strong regression tests. Use a standard error mgt package.quest.Page 26 Quest CodeGen Utility www. Standardize block structure and headers. complex parts of your application. – Generate table APIs and other elements. – Make sure there are no repetitions of the same logical statement.
– And everyone is happy. really fast. Never fix bugs that users haven't found.8. Doing things "just because" can be a real time waster. – Why spend lots of time and effort fixing bugs that the users may never even find? Just in time bug fixing – the way to go! – Get applications in users' hands rapidly. – Stand ready to fix bugs really. Oh. Copyright 2006 Steven Feuerstein . all right….Page 27 .
yeah.http://www.com/index.htm – Quest Code Tester for Oracle – www.quest. Big news.ALWAYS test proactively and thoroughly. very exciting! – utPLSQL .ToadWorld. – We need a test repository.jspa Copyright 2006 Steven Feuerstein .http://utplsql. Of course! The question is how to do it.apollo-pro.sourceforge. yeah.com/help/pl_unit. Yeah.net/ – PLUnit .inside.com or http://unittest. automated run and results verification You need better tools…and the choices are limited but getting very.Page 28 .
9. all right…. Oh. A bug today is a bug tomorrow. I don't have time to do anything but find a solution and keep on moving. – Everything else is wishful thinking. I will leave it to my descendents to sort it all out. Copyright 2006 Steven Feuerstein .Page 29 . Never assume an Oracle bug will be fixed.
Page 30 . Let's look at an example: "Does a file exist?" Copyright 2006 Steven Feuerstein ." When you need a workaround… – Encapsulate the workaround.ALWAYS assume a bug will be fixed. Let's be positive. shall we? Avoid mythological code whenever possible. – Document the workaround. – "Once upon a time. – Include explanation of how to remove the workaround when the bug is fixed. there was a bug….
fgetattr (LOCATION . file_length PLS_INTEGER .FGETATTR program does the trick. fexists . file_length .Does a file exist? The UTL_FILE.log' fgetattr_rec. END.file_length fgetattr_rec.fexists fgetattr_rec.. whether or not the file exists. Or does it? DECLARE TYPE fgetattr_t IS RECORD ( fexists BOOLEAN .fexists THEN . the fexists parameter is always set to TRUE. Copyright 2006 Steven Feuerstein . there is/was a bug: In Oracle 9iR2.block_size . => => => => => 'TEMP' 'trace.. IF fgetattr_rec. block_size PLS_INTEGER ). filename .Page 31 Unfortunately. BEGIN UTL_FILE. block_size ). fgetattr_rec fgetattr_t.
But if everyone puts the fix/workaround in their code. Copyright 2006 Steven Feuerstein .Quick! Share that knowledge! I could send an email to our entire team.Page 32 . explaining the problem and providing the code they should use instead. how can we ever go back and back out the workaround when the problem is fixed? Plus…many times. workarounds no longer work in patched versions of software.
Page 33 . */ END fexists. END IF. ELSE RETURN TRUE. /* WORKAROUND END 2174036 */ Include the code to be used when the workaround is no longer necessary. /* Document the workaround.fexists. remove the IF statement and uncomment this: RETURN fgetattr_rec. WORKAROUND START 2174036 fexists is always returned TRUE.block_size = 0 THEN RETURN FALSE. including the bug number...A workaround for fgetattr Here is an alternative: provide the workaround to everyone in the form of a function. but non-existent file has ZERO file_length and block_size */ IF fgetattr_rec. Copyright 2006 Steven Feuerstein . /* WORKAROUND FIX 2174036 When the bug is fixed.file_length = 0 AND fgetattr_rec. .
10. The only sentences in which the words "never" and "always" should be mentioned in regards to code are: Things will never stay the same. Never say never.Page 34 . Anything else is a bug in the making! Copyright 2006 Steven Feuerstein . Things will always be changing.
Florida Featuring the world's SECOND PL/SQL Test a Thon! The ODTUG Seriously Practical Oracle PL/SQL Programming Conference The Second OPP 2007 of the year will be held in NYC this Fall.odtugopp.com or call 910-452-7444 Copyright 2006 Steven Feuerstein . And we will hold a test-a-thon there as well. For more information visit www.odtug.ODTUG Kaleidoscope June 18 – 21. www. 2007 Hilton Daytona Beach Oceanfront Resort Daytona.Page 35 .com.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.