Oracle 語句收集

來源:互聯網
上載者:User

標籤:

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;    / 

 

Oracle 語句收集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.