Oracle Academy Lead Adjunct Prof. Carmen Popescu Oracle Academy Lead Adjunct
Forma generala a comenzii SELECT SELECT expresii FROM tabele WHERE conditii In clauza select pot aparea coloane, sau expresii Ordinea operatorilor: * / + - Operatorii logici: AND, OR (in aceasta ordine)
BETWEEN SELECT * from employees WHERE department_id BETWEEN 10 AND 30 department_id >=10 AND department_id<=30 Departamentul 20 ESTE afisat
IN SELECT * from employees WHERE department_id IN (10,30) department_id=10 OR department_id=30 Departamentul 20 NU ESTE afisat
NULL 5+NULL => NULL La ordonare crescatoare valorile NULL sunt puse la sfarsit La ordonare descrescatoare NULL apare la inceput
ALIAS DE COLOANA (AS) SELECT salary+0.25*salary FROM employees AS ”New Salary” AS New Salary => EROARE
ALIAS DE COLOANA (AS) SELECT first_name||’ ’||last_name AS Numele FROM employees AS ”Numele”
ALIAS DE COLOANA (AS) Ghilimelele la alias sunt obligatorii cand: Aliasul e compus din doua sau mai multe cuvinte Dorim ca aliasul sa fie scriscu litere mici
DESCRIBE
LIKE SELECT * from employees WHERE first_name LIKE ’%a%’ afiseaza toate persoanele cu un ’a’ oriunde in prenume WHERE first_name LIKE ’_ _a%’ afiseaza persoanele cu un a pe a treia pozitie din nume % - oricate caractere (inclusiv nici unul) _ - un singur caracter
LIKE SELECT * from employees WHERE job_title LIKE ’%\_ _ _’ ESCAPE ’\’ afiseaza persoanele pt. care in job_title, dupa caracterul _ mai exista exact doua caractere Cu clauza ESCAPE am precizat ca% sau _ precedate de \ vor fi tratate ca si caractere normale ce trebuie sa apara in text nu ca wildchar.
ORDER BY SELECT * FROM employees ORDER BY last_name ASC, salary DESC SELECT first_name,salary, department_id FROM employees ORDER BY 2 Se sorteaza dupa a doua expresie din clauza SELECT, adica dupa salary