-->create table 테이블이름 ( 컬럼이름 컬럼데이터타입 null허용여부 );
drop table topic; create table topic ( id NUMBER not null, title VARCHAR2(40) not null,--가변형 데이터에는 VARCHAR2 description VARCHAR2(4000), --VARCHAR2최대 4000byte created date not null );
--> insert into 테이블이름 (칼럼1, 칼럼2, ...) VALUES (칼럼순서에 맞는 데이터 값);
insert into topic (id,title,description,created) VALUES (1,'oracle','oracle is ...',sysdate); insert into topic (id,title,description,created) VALUES (2,'mysql','mysql is ...',sysdate); insert into topic (id,title,description,created) VALUES (3,'sql server','sql server is ...',sysdate); insert into topic (id,title,description,created) VALUES (4,'mongoDB','mongoDB is ...',sysdate);
-->select *(모든 컬럼) from 테이블 이름
SELECT * from topic; -->select 컬럼이름 from 테이블 이름 select id from topic; -->id가 1인 행만 출력 select * from topic where id =1; -->id가 1보다 큰 행만 출력 select * from topic where id >1; -->id가 1인 행에서 id, title, created만 출력 select id, title, created from where id=1;
-->select * from 테이블이름 order by 칼럼 정렬순;
-->id를 기준으로 큰 수 먼저 정렬 select * from topic order by id desc; -->id를 기준으로 작은 수 먼저 정렬 select * from topic order by id asc;
-->offset n rows : n+1번째 행부터 출력 또는 n번째 인덱스 번호로 생각 (어디서부터 가져올것인가.)
select * from topic offset 1 rows; select * from topic offset 2 rows; select * from topic offset 0 rows --> 모든행을 다 가져오겠다. fetch next 1 rows only;--> fetch next 1 rows only : n개만 가져오겠다. select * from topic offset 1 rows fetch next 1 rows only; COMMIT;
--> update 테이블이름 set 수정칼럼 = 수정할칼럼내용 where 수정할행의칼럼;
update topic set title = 'mssql', description = 'mssql is ...' where id=3; COMMIT;
--> delete from 테이블이름 where 삭제를 원하는 행의 위치
delete from topic where id=3; COMMIT;