Основы (асослар)


Download 0.95 Mb.
bet6/58
Sana28.12.2022
Hajmi0.95 Mb.
#1011518
1   2   3   4   5   6   7   8   9   ...   58
Bog'liq
PL-SQL Маъруза матни

BIN_INT

CHAR

DATE

LONG

NUMBER

PLS_INT

RAW

UROWID

VARCHAR2

BIN_INT
CHAR
DATE
LONG
NUMBER
PLS_INT
RAW
UROWID
VARCHAR2

X


X
X

X


X

X
X
X


X
X
X
X

X


X

X
X
X

X
X
X

X


X
X

X


X

X
X

X

X


X

X


X

X


X

X
X
X
X
X
X
X
X





Ўзгарувчи ва ўзгармасларни эълон қилиш


Сизнинг дастурингиз қийматларни ўзгарувчилар ва ўзгармасларда сақлайди. Сиз ўзгарувчи ва ўзгармасларни PL/SQL блоки, қисмдастур ва пакетларнинг эълон қилиш қисимида эълон қилишингиз мумкин.


birthday DATE;


emp_count SMALLINT := 0;
pi REAL := 3.14159;
radius REAL := 1;
area REAL := pi * radius**2;
birthday DATE;
birthday DATE := NULL;
credit_limit CONSTANT REAL := 5000.00;
blood_type CHAR := 'O';
blood_type CHAR DEFAULT 'O';
hours_worked INTEGER DEFAULT 40;
employee_count INTEGER := 0;
acct_id INTEGER(4) NOT NULL := 9999;
credit REAL(7,2);
debit credit%TYPE;
balance NUMBER(7,2);
minimum_balance balance%TYPE := 10.00;
my_dname scott.dept.dname%TYPE;

%ROWTYPE ишлатиш


%ROWTYPE атрибути жадвал қатори кўринишидаги ёзув турини эълон қилишга имкон беради:


DECLARE
emp_rec emp%ROWTYPE;


CURSOR c1 IS SELECT deptno, dname, loc FROM dept;
dept_rec c1%ROWTYPE;
............................................................
emp_rec.ename := 'JOHNSON';
emp_rec.sal := emp_rec.sal * 1.15;
..............................................................
CREATE PACKAGE emp_actions AS
CURSOR c1 RETURN emp%ROWTYPE; -- declare cursor specification
...
END emp_actions;

CREATE PACKAGE BODY emp_actions AS


CURSOR c1 RETURN emp%ROWTYPE IS -- define cursor body
SELECT * FROM emp WHERE sal > 3000;
...
END emp_actions;

Езувни ҳамма майдончаларини бирданига 2 хил вариантда тўлдириш мумкин.


I вариант:
DECLARE
dept-rec1 dept % ROWTYPE:
dept-rec2 dept % ROWTYPE;
CURSOR C1 IS SELECT deptno, dname, loc FROM dept;
dept-rec3 C1 % ROWTYPE;
dept-rec4 C1 % ROWTYPE;
BEGIN ...
dept-rec 1: = dept-rec 2;
dept-rec 4: = dept-rec 3;
END
dept-rec 2: = dept-rec 3; нотўғри!

II вариант:


А) DECLARE
dept-rec dept % ROWTYPE
...
BEGIN
SELECT deptno, dname , loc INTO dept-rec FROM dept WHERE deptno =30;
...
Б) INSERT INTO dept VALVES (dept-rec1 ); -- нотўғри


Хамроҳ номларни ишлатиш


Ифодалар қатнашган курсор қаторларига мурожаат қилиш қилиш учун , уларни олдин албатта содда ҳамроҳ номлаш зарур:


DECLARE
CURSOR my_cursor IS SELECT sal + NVL (comm,0) wages, ename
FROM emp:
my-rec my_cursor % ROWTYPE;
BEGIN
OPEN my_cursor;
LOOP
FETCH my_cursor INTO my-rec
EXIT WHEN my_cursor % NOT FOUND;
IF my_rec.wages > 2000 THEN.
INSERT INTO temp VALVES (NULL, my_rec.wages, my-rec.ename);
END IF;
END LOOP:
CLOSE my_cursor;
END

Download 0.95 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   58




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling