Oracle SQL语句收集
生活随笔
收集整理的這篇文章主要介紹了
Oracle SQL语句收集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//DML語句(數據操作語言)Insert、Update、 Delete、Merge
//DDL語句(數據定義語言)Create、Alter、 Drop、Truncate
//DCL語句(數據控制語言)Grant、Revoke
//事務控制語句Commit 、Rollback、Savepoint
?
declare --定義變量 v_ename varchar2(5); v_sal number(7,2); begin --執行部分 select ename,sal into v_ename,v_sal from emp where empno=&aa; --在控制臺顯示用戶名 dbms_output.put_line('用戶名是:'||v_ename||' 工資:'||v_sal); --異常處理 exception when no_data_found then dbms_output.put_line('朋友,你的編號輸入有誤!'); end;?
--輸入雇員的姓名,返回該雇員的年薪 create function annual_incomec(name varchar2) return number is annual_salazy number(7,2); begin --執行部分 select sal*12+nvl(comm, 0) into annual_salazy from emp where ename=name; return annual_salazy; end;?
create package sp_package is procedure update_sal(name varchar2, newsal number); function annual_income(name varchar2) return number; end;?
declare c_tax_rate number(3,2):=0.03; --用戶名 v_ename varchar2(5); v_sal number(7,2); v_tax_sal number(7,2); begin --執行 select ename,sal into v_ename,v_sal from emp where empno=&no; --計算所得稅 v_tax_sal := v_sal*c_tax_rate; --輸出 dbms_output.put_line('姓名是:'||v_ename||'工資:'||v_sal||' 交稅:'||v_tax_sal); end;?
declare --定義一個pl/sql記錄類型emp_record_type,類型包含3個數據name,salary,title。說白了,就是一個類型可以存放3個數據,主要是為了好管理 type emp_record_type is record( name emp.ename%type, salary emp.sal%type, title emp.job%type); --定義了一個sp_record變量,這個變量的類型是emp_record_type sp_record emp_record_type; begin select ename, sal, job into sp_record from emp where empno =7788; dbms_output.put_line ('員工名:' || sp_record.name); end;?
declare --定義了一個pl/sql表類型sp_table_type,該類型是用于存放 emp.ename%type --index by binary_integer 表示下標是整數 type sp_table_type is table of emp.ename%type index by binary_integer; --定義了一個sp_table變量,這個變量的類型是sp_table_type sp_table sp_table_type; begin select ename into sp_table(-1) from emp where empno = 7788; dbms_output.put_line('員工名:' || sp_table(-1)); end;?
declare --定義游標sp_emp_cursor type sp_emp_cursor is ref cursor; --定義一個游標變量 test_cursor sp_emp_cursor; --定義變量 v_ename emp.ename%type; v_sal emp.sal%type; begin --執行 --把test_cursor和一個select結合 open test_cursor for select ename,sal from emp where deptno=&no; --循環取出 loop fetch test_cursor into v_ename,v_sal; --判斷是否test_cursor為空 exit when test_cursor%notfound; dbms_output.put_line('名字:'||v_ename||' 工資:'||v_sal); end loop; end; /?
--SQL%NOTFOUND 是一個布爾值。與最近的sql語句(update,insert,delete,select)發生交互,當最近的一條sql語句沒有涉及任何行的時候,則返回true。否則返回false。這樣的語句在實際應用中,是非常有用的。例如要update一行數據時,如果沒有找到,就可以作相應操作。如:beginupdate salary set bonus = 1000 where emp_id = 10;if sql%notfound thenraise e_noteffact;end if;?
--雇員表 create table scott_emp (empno number(4),--表示雇員編號,是唯一編號ename varchar2(10), --表示雇員姓名job varchar2(9),--表示工作職位mgr number(8), --表示一個雇員的領導編號hiredate date,--表示雇傭日期sal number(7,2),--表示月薪,工資comm number(7,2), --表示獎金,或者稱為傭金deptno number(2) --部門編號 )--部門表 create table scott_dept (deptno number(2), --部門編號,是唯一編號dname varchar2(14),--部門名稱loc varchar2(13) --部門設置 )--工資等級表 create table scott_salgrade (grade number, --等級名稱losal number,--此等級的最低工資hisal number --此等級的最高工資 )--獎金表 create table scott_bonus (ename varchar2(10),--雇員姓名job varchar2(9),--雇員工作sal number,--雇員工資comm number --雇員獎金(傭金) )?
-- 對于特殊符號可使用ESCAPE 標識符來查找,% 表示零或多個字符 ,_ 表示一個字符 select * from emp where ename like '%*_%' escape '*'?
轉載于:https://www.cnblogs.com/FH-cnblogs/p/5316745.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Oracle SQL语句收集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lcx 端口转发
- 下一篇: SpringMVC+hibernate+