Loops. They're so ... well ... loopular. I mean, come on, do we really need them? Do we? If you think about it, they're nothing but crutches for the weak. Kinda like case statements or switch blocks. No, us highly-paid consultants don't need any of that. In fact, here's a perfect example of how to write PL/SQL. It's from the "professional services" division of a company that shall remain nameless. Jeff Atwood knows what good code is like.
-- ################################################################# -- Start Get Domain ID -- ################################################################# PROCEDURE ps_getdomainid( domainin IN PSUSERTEMP.DOMAIN%TYPE, domainid_inout IN OUT DRDOMAIN.ID%TYPE, flag_inout IN OUT PLS_INTEGER ) IS firstplace PLS_INTEGER :=0; secondplace PLS_INTEGER :=0; thirdplace PLS_INTEGER :=0; fourthplace PLS_INTEGER :=0; fifthplace PLS_INTEGER :=0; sixthplace PLS_INTEGER :=0; seventhplace PLS_INTEGER :=0; eigthplace PLS_INTEGER :=0; domainlength PLS_INTEGER :=0; firststring VARCHAR2(40) := NULL; secondstring VARCHAR2(40) := NULL; thirdstring VARCHAR2(40) := NULL; fourthstring VARCHAR2(40) := NULL; fifthstring VARCHAR2(40) := NULL; sixthstring VARCHAR2(40) := NULL; seventhstring VARCHAR2(40) := NULL; eigthstring VARCHAR2(40) := NULL; firstchilddomainflag PLS_INTEGER; secondchilddomainflag PLS_INTEGER; thirdchilddomainflag PLS_INTEGER; fourthchilddomainflag PLS_INTEGER; fifthchilddomainflag PLS_INTEGER; sixthchilddomainflag PLS_INTEGER; seventhchilddomainflag PLS_INTEGER; eigthchilddomainflag PLS_INTEGER; firstdomainid DRDOMAIN.ID%TYPE; seconddomainid DRDOMAIN.ID%TYPE; thirddomainid DRDOMAIN.ID%TYPE; fourthdomainid DRDOMAIN.ID%TYPE; fifthdomainid DRDOMAIN.ID%TYPE; sixthdomainid DRDOMAIN.ID%TYPE; seventhdomainid DRDOMAIN.ID%TYPE; eigthdomainid DRDOMAIN.ID%TYPE; BEGIN domainlength := LENGTH(domainin); firstplace := INSTR(domainin, '|', 1, 1); IF firstplace != 0 THEN secondplace := INSTR (domainin, '|', 1, 2); END IF; IF secondplace != 0 THEN thirdplace := INSTR (domainin, '|', 1, 3); END IF; IF thirdplace != 0 THEN fourthplace := INSTR (domainin, '|', 1, 4); END IF; IF fourthplace != 0 THEN fifthplace := INSTR (domainin, '|', 1, 5); END IF; IF fifthplace != 0 THEN sixthplace := INSTR (domainin, '|', 1, 6); END IF; IF sixthplace != 0 THEN seventhplace := INSTR (domainin, '|', 1, 7); END IF; IF firstplace != 0 AND firstplace != domainlength THEN firststring := SUBSTR(domainin, 1, (firstplace-1)); ELSIF firstplace = domainlength THEN firststring := SUBSTR (domainin, 1, (firstplace -1 )); ELSIF firstplace = 0 AND domainlength !=0 THEN firststring := domainin; GOTO get_domain_id; END IF; IF secondplace != 0 AND secondplace != domainlength THEN secondstring := SUBSTR(domainin, (firstplace+1), (secondplace - firstplace-1)); ELSIF secondplace = domainlength THEN secondstring := SUBSTR (domainin, (firstplace+1), (secondplace-firstplace -1 )); ELSIF secondplace = 0 AND firstplace != 0 THEN secondstring := SUBSTR (domainin, (firstplace+1), (domainlength - firstplace)); GOTO get_domain_id; END IF; IF thirdplace != 0 AND thirdplace != domainlength THEN thirdstring := SUBSTR(domainin, (secondplace+1), (thirdplace - secondplace -1)); ELSIF thirdplace = domainlength THEN thirdstring := SUBSTR (domainin, (secondplace+1), (thirdplace-secondplace -1 )); ELSIF thirdplace = 0 AND secondplace != 0 THEN thirdstring := SUBSTR (domainin, (secondplace + 1), (domainlength - secondplace)); GOTO get_domain_id; END IF; IF fourthplace != 0 AND fourthplace != domainlength THEN fourthstring := SUBSTR(domainin, (thirdplace+1), (fourthplace - thirdplace - 1)); ELSIF fourthplace = domainlength THEN fourthstring := SUBSTR (domainin, (thirdplace+1), (domainlength - thirdplace -1 )); ELSIF fourthplace = 0 AND thirdplace != 0 THEN fourthstring := SUBSTR (domainin, (thirdplace + 1), (domainlength - thirdplace)); GOTO get_domain_id; END IF; IF fifthplace != 0 AND fifthplace != domainlength THEN fifthstring := SUBSTR(domainin, (fourthplace+1), (fifthplace - fourthplace - 1)); ELSIF fifthplace = domainlength THEN fifthstring := SUBSTR (domainin, (fourthplace+1), (domainlength - fourthplace -1 )); ELSIF fifthplace = 0 AND fourthplace != 0 THEN fifthstring := SUBSTR (domainin, (fourthplace + 1), (domainlength - fourthplace)); GOTO get_domain_id; END IF; IF sixthplace != 0 AND sixthplace != domainlength THEN sixthstring := SUBSTR(domainin, (fifthplace+1), (sixthplace - fifthplace - 1)); ELSIF sixthplace = domainlength THEN sixthstring := SUBSTR (domainin, (fifthplace+1), (domainlength - fifthplace -1 )); ELSIF sixthplace = 0 AND fifthplace != 0 THEN sixthstring := SUBSTR (domainin, (fifthplace + 1), (domainlength - fifthplace)); GOTO get_domain_id; END IF; IF seventhplace != 0 AND seventhplace != domainlength THEN seventhstring := SUBSTR(domainin, (sixthplace+1), (seventhplace - sixthplace - 1)); ELSIF seventhplace = domainlength THEN seventhstring := SUBSTR (domainin, (sixthplace+1), (domainlength - sixthplace -1 )); ELSIF seventhplace = 0 AND sixthplace != 0 THEN seventhstring := SUBSTR (domainin, (sixthplace + 1), (domainlength - sixthplace)); GOTO get_domain_id; END IF; IF eigthplace != 0 AND eigthplace != domainlength THEN eigthstring := SUBSTR(domainin, (seventhplace+1), (eigthplace - seventhplace - 1)); ELSIF eigthplace = domainlength THEN eigthstring := SUBSTR (domainin, (seventhplace+1), (domainlength - seventhplace -1 )); ELSIF eigthplace = 0 AND seventhplace != 0 THEN eigthstring := SUBSTR (domainin, (seventhplace + 1), (domainlength - seventhplace)); GOTO get_domain_id; END IF; IF eigthplace != domainlength AND eigthplace !=0 THEN eigthstring := SUBSTR (domainin, (eigthplace+1), (domainlength - eigthplace )); END IF; <> NULL; IF firststring IS NOT NULL THEN ps_validatedomain ( firststring, firstdomainid, firstchilddomainflag); IF firstchilddomainflag =0 THEN flag_inout := 0; GOTO end_of_programm; END IF; END IF; IF secondstring IS NULL AND firstchilddomainflag = 1 THEN domainid_inout := firstdomainid; flag_inout := 1; GOTO end_of_programm; ELSIF secondstring IS NOT NULL AND firstchilddomainflag =1 THEN ps_childdomainid(firstdomainid, secondstring, seconddomainid, secondchilddomainflag); IF secondchilddomainflag = 0 THEN flag_inout:=0; GOTO end_of_programm; END IF; END IF; IF thirdstring IS NULL AND secondchilddomainflag = 1 THEN domainid_inout :=seconddomainid; flag_inout := 1; GOTO end_of_programm; ELSIF thirdstring IS NOT NULL AND secondchilddomainflag = 1 THEN ps_childdomainid(seconddomainid, thirdstring, thirddomainid, thirdchilddomainflag); IF thirdchilddomainflag = 0 THEN flag_inout :=0; GOTO end_of_programm; END IF; END IF; IF fourthstring IS NULL AND thirdchilddomainflag = 1 THEN domainid_inout := thirddomainid; flag_inout := 1; ELSIF fourthstring IS NOT NULL AND thirdchilddomainflag = 1 THEN ps_childdomainid(thirddomainid, fourthstring, fourthdomainid, fourthchilddomainflag); IF fourthchilddomainflag = 0 THEN flag_inout := 0; GOTO end_of_programm; END IF; END IF; IF fifthstring IS NULL AND fourthchilddomainflag = 1 THEN domainid_inout := fourthdomainid; flag_inout := 1; ELSIF fifthstring IS NOT NULL AND fourthchilddomainflag = 1 THEN ps_childdomainid(fourthdomainid, fifthstring, fifthdomainid, fifthchilddomainflag); IF fifthchilddomainflag = 0 THEN flag_inout := 0; GOTO end_of_programm; END IF; END IF; IF sixthstring IS NULL AND fifthchilddomainflag = 1 THEN domainid_inout := fifthdomainid; flag_inout := 1; ELSIF sixthstring IS NOT NULL AND fifthchilddomainflag = 1 THEN ps_childdomainid(fifthdomainid, sixthstring, sixthdomainid, sixthchilddomainflag); IF sixthchilddomainflag = 0 THEN flag_inout := 0; GOTO end_of_programm; END IF; END IF; IF seventhstring IS NULL AND sixthchilddomainflag = 1 THEN domainid_inout := sixthdomainid; flag_inout := 1; ELSIF seventhstring IS NOT NULL AND sixthchilddomainflag = 1 THEN ps_childdomainid(sixthdomainid, seventhstring, seventhdomainid, seventhchilddomainflag); IF seventhchilddomainflag = 0 THEN flag_inout := 0; GOTO end_of_programm; END IF; END IF; IF eigthstring IS NULL AND seventhchilddomainflag =1 THEN domainid_inout := seventhdomainid; flag_inout := 1; ELSIF eigthstring IS NOT NULL AND seventhchilddomainflag = 1 THEN ps_childdomainid(seventhdomainid, eigthstring, eigthdomainid, eigthchilddomainflag); IF eigthchilddomainflag = 0 THEN flag_inout := 0; GOTO end_of_programm; ELSIF eigthchilddomainflag = 1 THEN domainid_inout := eigthdomainid; flag_inout :=1; END IF; END IF; <<end_of_programm>> NULL; END ps_getdomainid;
We've got some great logos in already. I'm going to put up a voting thing soon, so make sure to get your logo idea in. Details here.
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!