0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
39 visualizzazioni6 pagine
ORACLE DML data munitiply Truy van du lieu : select,insert,update, delete,merger. DDL data control language lien quan den bao mat Grant cap quyen,revoke xoa quyen. TCL Transaction control language Commit luu vao co so du lieu,rollback,savepoint.
ORACLE DML data munitiply Truy van du lieu : select,insert,update, delete,merger. DDL data control language lien quan den bao mat Grant cap quyen,revoke xoa quyen. TCL Transaction control language Commit luu vao co so du lieu,rollback,savepoint.
ORACLE DML data munitiply Truy van du lieu : select,insert,update, delete,merger. DDL data control language lien quan den bao mat Grant cap quyen,revoke xoa quyen. TCL Transaction control language Commit luu vao co so du lieu,rollback,savepoint.
Truy van du lieu : select,insert,update, delete,merger. DDL data definition language ngon ngu dinh nghia Create,alter,drop,rename,truncate,comment DCL data control language lien quan den bao mat Grant cap quyen,revoke xoa quyen TCL Transaction control lamguage Commit luu vao co so du lieu ,rollback,savepoint khoi phuc lai du lieu
Show user // chi ra user ang s kt ni Desc dba_users; //xut ra table Select username from dba_users // xuat ra cac username Select account_status from dba_users where username=hr // kiem tra trang thai Connect hr// ket noi toi user khac Alter user hr account unlock identified hr;// thay doi trang thai va password la hr Desc user_tables; // xuat cau truc du lieu cua bang Select table_name from user _table Select * from contries; 1 .Select t 1 bng Select list _column_name from table_name Select 1 as demo from dual; //Ten bang hien thi la demo Select region_id as id ,region_name as name from regions;// ten hien thi la id va name Select distinct job_id from employees // k tinh du lieu trung nhau Select count(employee_id) from employees;// dem so employ_id khong tinh truong null Select count(distinct manager_id) from employees// dem va loai bo trung lap, dung * tnh c null Select Blogs study and share as blog from dual; Or select q<blogs study and share> as blog from dual; //S dng quote ki t <>.[],(){} Select fitst_name || || Last_name as name from employee// ghp 2 ct Select first_name, salary from employee where salary >10000 and/or salary <5000; Select job_title from jobs where job_title like S%; //like S% inh dng bt u bng s v sau ty //S_l% _ thay th cho k t bt k Select .. where min_salary between 4000 and 9000; Select. Where min_salary in/ not in (4000,6000,9000) // = tp hp cc gi tr Select where manager is not null/ cu lnh is Select first_name ,salary where order by salary,first_name// mc nh l tng dnv null cui // order by 2( th t ca column), order by luon o cuoi cung Select where order by 1 asc, 2 desc; Select where order by commission_pct nulls first/last (first dung khi tng dn, last dung khi gim dn) Define name=Ducky// nh ngha bin Select &name from dual; Select firstname,salary ,manager from employee where firstname=&name; Undefined name// remove bin Select from employees where salary>&money and salary<&money//truyn vo tham s, khi su dung so khong cn du Select from employee where salary >&&money and salary <&&money// s dng && lu li gi tr bin v khng cn nhp li khi s dng Select from employees where salary >&&money Set define off/on // bt tt gi tr bin Ser verify off/on tt bt xut hin gi tri old v new Select SUM/avg(salary) from employees where job_id=it_pro; Select min(salary) asMIN, max(salary) as Max from employees where job_id=it_pro; Select deparment_id, count(*) from employees group by deparment_id;// dem so deparment_id Select max(avg(salary)) from employees group by jod_id; // toi da 2 lan group Select job_id, manager_id, count(*) from employees group by job_id,manager_id; Select job_id,avg(salary), min (salary)from employees group by job_id having min(salary)>8000;// having dieu kien, where dung cho single columm, having dung cho group column. Select first_lower(name) , upper(last_name) from employees// viet thuong , viet hoa Select initcap(viet nam )from dual; vit hoa ch ci V,N Select concat(first_name,last_name)from employees // ni 3 xu phi concat 2 ln Select sysdate from dual// tr v thi gian h thng 22-JUL-99 Desc V$nls_parameters //ch v u la view,nls national languge support Select parameter from v$nls_parameter; check tham s trong view Select value from v$nls_parameter where parameter=NLS_DATE_FORMAT; // tr v format ngy - MON-RR Alter session set nls_date_format=dd-mm-yy hh24:mi:ss // thay i nh dng ngy h thng Select start_date,add_months(start_date,3) ADD from job_history;// them vo thng, mun gim thay 3->-3 Select start_date ,months_between(start_date,end_date) from job_history //check khong cch so thang Next_day(date,#) //# l 1->7 t ch nht n th7 Last_day(date) // ngy cui cng ca thng Select city,country_name from locations, countries where locations.country_id=countries.country_id; Select city,country_name from locations l, countries c where l.country_id=c.country_id; Select city, country_name from locations natural join countries;// tm kim 2 trng ging nhau Select first_name,start_date,end_date from job_history join employees using(employee_id); // s dng using khi c 2 trng ging nhau-> khng s dng ng thi natual v using Select first_name,start_date,end_date from job_history join employees on (job_histroty.employee_id=employee.employee_id) S dng on thay using/where Select city,country_name from contries left/right.full outer join locations on (countries.country_id=location.country_id) // hien ca gia tri khong co trong on Select e1.first_name NV, e2.first_name from employees e1 join employees e2 on (e1.manager_id=e2.employee_id) //->selfjoin join 2 thng tin trong cng 1 bng Create table table_name( colum_name datatype) Create table students (first_name varchar2(20), last_name varchar2(20), birthday date,grade number(2)) Insert into Students values(toan,cao,23-7-1989,3); Select systimestamp from dual; Varchar2,nvarchar2,char,number,float,interger,date,timestamp // kiu d liu Delete from students where first_name=tuan; Update students set grade=4 where first_name=toan; Rollback; Create table emp as select first_name,last_name from students;// tao bng con t subquery Drop table emp; Create table emp as select* from students where 1=2;// to bng con k c d liu Create table emp as select * from students where first_name likes t% Truncate table students;// delete table d liu mt nhng bng vn cn, k rollback c Drop table // xa bng -> khng cn tn ti na Create table groups (group_id number(2) primary key) Create table students(student_id number(5) constraint student_pk primary key, name varchar(30), group_id number(2) constraint student_pk reference group(group_id)); Create table students (name varchar2(30) not null, age number(3), email varchar2(40) unique,address varchar2(50) default viet nam, constraint students_check_age check(age>12)); Alter table students add (grade number(2));// them column Alter table students rename column grade to score;// i tn column Alter table students modify (score default 5); Alter table students drop column score // delete ct Alter table students read only; Alter table students read write; Create table emp as select * employees; Create view name as select first_name , last_name from emp;// to simple view Select * from name; Create view cities as select city, contry_name from locations nartural join contries// to complex view Create or replace view name as select first_name from emp; to hoc thay th khi view tn ti Create or replace force view name as select first_name,ducky from emp; //s dng khi 1 trng cha tn ti Alter view name compile; Drop view name; ..xa view Insert into name values (viet, tran);// insert vo view nhng thc cht l cp nht vo bng gc Update name set first_name=ducky where last_name=abc; Create or replace view r as select * from regions where region_name likeA% with check_option; Grant select on regions to oe;-> select * from hr.regions // truy cap bang thuoc csdl khac Creat public synonym TEN for hr.regions //error vi public cap cho tat ca user , ko co public mac dinh la private Revoke select on regions from oe; Alter user oe account lock; // lock 1 user Create table students (id number(3) , name varchar2(30),address varchar2(30)); Create sequence ids; // gia tri bat dau la 1, ko co gia tri MAX, khong co quay vong Insert into students (ids.nextval,viet,nghe an);// rollback khong co tac dung voi sequence Select ids.nextval from dual; Drop sequence ids; Increment by A// gia tri tang cho sequence Start with B// gia tri bat dau ( start with >=min value) Minvalue C Maxvalue D Cycle |nocycle// khi dat gia tri maxvalue no quay lai gia tri start Cache E|nocache// (mac dinh la 20, lien quan den performance nen dat la cache =50000;)