Skip to content

Instantly share code, notes, and snippets.

@myleftboot
Created May 11, 2012 22:20
Show Gist options
  • Save myleftboot/2662763 to your computer and use it in GitHub Desktop.
Save myleftboot/2662763 to your computer and use it in GitHub Desktop.
SQL code in need of a decode. Try to do as much computation within the sql as is reasonably possible.
FUNCTION get_printed_status
RETURN varchar2 IS
v_order status orders.printed%TYPE;
v_status varchar2(30);
BEGIN
SELECT printed
INTO v_order_status
FROM orders
WHERE order_no = p_order_no;
IF v_order_status = 0 OR v_order_status IS NULL THEN
v_status = 'NOT PRINTED';
ELSIF v_order_status = 2 THEN
v_status = 'ON HOLD';
ELSIF v_order_status = 1 THEN
v_status = 'PRINTED';
ELSE
v_status = 'UNKNOWN';
END IF;
RETURN v_order_status;
END get_printed_status;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment