BDII Tema01-Rez
BDII Tema01-Rez
BDII Tema01-Rez
1
Observație!
Scrieți rezolvarea direct în acest document!
2. In the following code, identify and highlight examples of these procedural constructs: variable,
conditional control, SQL statement
DECLARE
v_first_name varchar2(40);
v_last_name varchar2(40);
v_first_letter varchar2(1);
BEGIN
SELECT first_name, last_name into v_first_name, v_last_name
FROM students
WHERE student_id=105;
v_first_letter := get_first_letter(last_name);
IF 'N' > 'v_first_letter' THEN
DBMS_OUTPUT.PUT_LINE('The last name for: '||first_name||' '||last_name||' is
between A and M');
ELSE
DBMS_OUTPUT.PUT_LINE('The last name for: '||first_name||' '||last_name||' is
between N and Z');
END IF;
END;
Variable:
v_first_name varchar2(40);
v_last_name varchar2(40);
v_first_letter varchar2(1);
conditional control:
IF 'N' > 'v_first_letter' THEN
SQL statement:
v_first_letter := get_first_letter(last_name);
3. Complete the following chart defining the syntactical requirements for a PL/SQL block:
Optional or Mandatory?
4. Which of the following PL/SQL blocks execute successfully? For the blocks that fail, explain
why they fail.
A.
BEGIN
END;
-nu se executa cu succes pt ca nu exista nici o instructiune intre BEGIN si END
B.
DECLARE amount INTEGER(10);
END;
-nu se executa cu succes pt ca lipseste BEGIN, lucru care este obligatoriu intru-un bloc SQL/PL
C.
DECLARE
BEGIN
END;
-nu se executa ptc nu exista nici o instructiune, la fel ca la punctul A
D.
DECLARE amount NUMBER(10);
BEGIN
DBMS_OUTPUT.PUT_LINE(amount);
END;
-este OK
7. Create and execute a simple anonymous block that does the following:
• Declares a variable of datatype DATE and populates it with the date that is six months
from today
• Outputs “In six months, the date will be: <insert date>.”
DECLARE
v date DATE = ADD MONTH(SYSDATE, 6)
BEGIN
DBMS OUTPUT,PUT LINE (‘In six mounths, the date will be’);
DBMS OUTPUT,PUT LINE (v date);
END;