PL/SQL函数
examples:“
构造一个邮件地址
v_mailing_address :=
v_name||CHR(10)||
v_address||CHR(10)||v_state||
CHR(10)||v_zip;
转换员工姓名为小写
v_ename := LOWER(v_ename);
转换函数:
TO_CHAR、TO_DATE、TO_NUMBER、
BEGIN
SELECT
TO_CHAR(hiredate,
‘MON. DD, YYYY‘)
FROM
emp;
END;
使用TO_CHAR转换函数
v_comment
:= USER||‘: ‘||TO_CHAR(SYSDATE);
PL/SQL操作符
逻辑操作符(Logical)
算术操作符(Arithmetic)
连接(Concatenation)
括号(Parentheses to
control order of
operations)
指数算符(**)
PL/SQL练习
DECLARE(声明变量)
V_SAL
NUMBER(7,2) := 60;
V_COMM NUMBER(10,2) := V_SAL /
.20;
V_MESSAGE
VARCHAR2(255) := ‘ eligible for commission‘;
BEGIN()
DECLARE
V_SAL NUMBER(7,2) := 50;
V_TOTAL_COMP NUMBER(10,2) := V_SAL + V_COMM;
BEGIN
V_MESSAGE :=
‘CLERK not‘||V_MESSAGE;
DBMS_OUTPUT.PUT_LINE(‘V_SAL=‘||V_SAL);
DBMS_OUTPUT.PUT_LINE(‘V_COMM=‘||V_COMM);
DBMS_OUTPUT.PUT_LINE(‘V_TOTAL_COMP=‘||V_TOTAL_COMP);
DBMS_OUTPUT.PUT_LINE(‘V_MESSAGE=‘||V_MESSAGE);
END;
DBMS_OUTPUT.PUT_LINE(‘V_SAL=‘||V_SAL);
DBMS_OUTPUT.PUT_LINE(‘V_COMM=‘||V_COMM);
DBMS_OUTPUT.PUT_LINE(‘V_MESSAGE=‘||V_MESSAGE);
V_MESSAGE :=
‘SALESMAN ‘||V_MESSAGE;
DBMS_OUTPUT.PUT_LINE(‘V_MESSAGE=‘||V_MESSAGE);
END;