一道經典plsql程式設計練習題

2021-08-25 09:43:25 字數 2152 閱讀 6943

最近在學plsql,苦於找不到練習題,所以自己寫了乙個用於練習.要求如下:

查詢scott使用者的

emp表中的所有資料,如果

job為

工資大於

2500

,則下調百分之

10;如果小於

則增加百分之

10,如果

job為

工資小於

則上調百分之

10;最後符合條件的人

.插入到

test

表中.並且列印符合條件的人數的個數.

test

表結構如下

:ename varchar

sal number

大家可以做來練習一下.以下是我的答案:

create or replace procedure test_update_all as  

type emplist is table of emp%rowtype;

empl emplist;

coun number(3):=0;

state number(1);

procedure one_record(name_emp in emp.ename%type,job_name in emp.job%type,sal_emp in out emp.sal%type,coun in out number,sal_state in out number)

as

up_reails number(2,2):=0;

low_reails number(2,2):=0;

begin

case

when job_name='manager'

then

if sal_emp>=2500 then

low_reails:=.1;

dbms_output.put_line(name_emp||' 工資大於2500 過高 ,下調百分之'||low_reails*100);

sal_state:=1;

coun:=coun+1;

elsif sal_emp<2500 then

low_reails:=.1;

dbms_output.put_line(name_emp||' 工資大於2500 過低 ,上調百分之'||up_reails*100);

sal_state:=1;

coun:=coun+1;

end if;

when job_name='salesman' then

if sal_emp<1500 then

begin

low_reails:=.1;

dbms_output.put_line(name_emp||' 工資大於1500 過低 ,上調百分之'||low_reails*100);

sal_state:=1;

coun:=coun+1;

end;

end if;

else

dbms_output.put_line(name_emp||'不符合條件,不進行更改');

end case;

sal_emp:=sal_emp*(1+up_reails-low_reails);

end one_record;

begin

select * bulk collect into empl from emp;

for i in empl.first..empl.last loop

state:=0;

one_record(empl(i).ename,empl(i).job,empl(i).sal,coun,state);

if state =1 then

dbms_output.put_line(empl(i).ename||'的薪金更改為'||empl(i).sal);

insert into test values(empl(i).ename,empl(i).sal);

end if;

end loop;

dbms_output.put_line('更改的人數為:'||coun);

end;

PLSQL 練習題目

1.sql練習 查詢emp表各個部門的總工資 select deptno,sum sal from emp group by deptno 2.sql練習 找到emp表中部門總工資最高的那個部門 select from select deptno,sum sal sum sal from emp g...

一道互動練習題

的做法 考慮逐位確定 對於每個位置,往後列舉有沒有位置可以使得正確位置更多,如果有,那麼有兩種情況,1是這個位置被放到了正確的位置,2是這個位置本來應該放的數被放來了 這裡的重點是我們需要區分1和2 具體的做法是記下讓這個位置答案正確位置數變大的2個位置,將其和i一起移位 這裡是手繪示意圖.即把p1...

一道fft練習題

考場上想到的o n 2 o n 2 o n2 暴力 記f i j f i j f i j 表示前i個位置,長度為j的連擊出現的期望次數 記g i j g i j g i j 表示第到i個位置為止,目前連擊次數為j的概率 轉移時有一些細節 include using namespace std con...