-
Notifications
You must be signed in to change notification settings - Fork 0
PL SQL Quick Tips
set serveroutput on
DBMS_OUTPUT.PUT_LINE('hi' || myVariable);
Prevent Null output
DBMS_OUTPUT.PUT_LINE(NVL(n_var2, 'No Name'));
Limit digits
myVariable NUMBER(2,4) := 12.1234;
Set Variable type (VARCHAR or NUMBER) automatically
n_var2 STUDENT.STUDENT.first_name%TYPE;
Ask User Input
-- the '&' tells the compiler to ask user for input.
myCost NUMBER :=&input;
Output value formatted with $
select to_char(sum(revenue), '$999,999.99' )
into revenue
from student.course_revenue;
DBMS_output.put_line('Total Revenue is: ' || revenue);
Concatenate two values into one field
select to_char(lastname || ', ' || firstname)
into name
from student.student
where firstname = 'Chad' and lastname = 'Jensen';
DBMS_output.put_line(name);
Count up to 5
FOR Count IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE(Count);
END LOOP;
Loop Backwards
FOR Count IN reverse 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(Count);
END LOOP;
IF myValue < 10 THEN
DBMS_OUTPUT.PUT_LINE('Value is less than 10);
ELSIF n_avgSal > 10 THEN
DBMS_OUTPUT.PUT_LINE('Value is greater than 10);
ELSE
DBMS_OUTPUT.PUT_LINE('Value is 10);
END IF;
Exceptions: https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm
Code examples contained herein are created by Chad Jensen (@cbjjensen) and/or Josh Kennedy (@JoshuaKennedy) and are placed in the public domain.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE CODE.