plsql中declare用法、number用法、字串拼接用法(||),as關鍵字用法
declare:用於plsql中的宣告變數,和begin連用,和儲存過程結構相似
declare
v_sal number(7,2):=60000;--宣告變數v_sal 型別為number(7,2)前面的7表示總共允許7個字元長,稱為寬度。後面2是保留小數點後面兩位,稱為精度。
v_comm2 number(7,2):=v_sal*0.20;
v_aa number(7,2):=100;
v_message varchar2(255):='eligible for commission';
begin
declare
v_sal number(7,2):=10;
v_comm number(7,2):=0;
v_total_comp number(7,2):=v_sal+v_comm;
begin
v_message:='clerk not'||v_message;
v_comm:=v_sal*0.30;
v_aa:=v_aa*0.30;
DBMS_OUTPUT.PUT_LINE ('2:'||TO_CHAR(v_aa));--dbms_output.put_line 輸出資料括號裡的||代表字串的拼接
DBMS_OUTPUT.PUT_LINE ('1:'||TO_CHAR(v_comm2));
end;
v_message:='salesman'||v_message;
DBMS_OUTPUT.PUT_LINE (TO_CHAR(v_comm2));
end;
select employee_ID as employees,first_name||last_name as "employee Name",Department_ID as "departement",salary as "Salary",email as "Email",phone_number as "phone",hire_date as "ehire date",job_id as "job Id" from employees;
select employee_ID employees,first_name||last_name "employee Name",Department_ID "departement",salary "Salary",email "Email",phone_number "phone",hire_date "ehire date",job_id "job Id" from employees;
以上兩句都能實現以下效果,plsql中取別名最好不要用as,||符號是拼接字串