09/25/2020
DML (INSERT, UPDATE, DELETE)
DML - data manipulation language
transaction only involves one table at a time.
> INSERT INTO table (col, col, ...) VALUES (val, val, ...) ;
--> the number of cols and vals must match up.
UPDATE
> UPDATE table SET col=val, col=val, ... [WHERE condition];
DELETE
> DELETE FROM table [WHERE condition];
restore vs. recovery
Back to INSERT
> SELECT sysdate FROM dual; --> to check what the current date format is.
> ALTER~~~;
> INSERT INTO emp (eno, ename, ...) VALUES (val, val, ...) ;
변환 함수 (Conversion Functions)
숫자 출력 형식
MI: -50 이 아니라 50-
T_CHAR(123456789, '9.999EEEE') --> 1.235E+08
TO_NUMBER는 안씀. SQL이 저절로 해줌.
TO_CHAR는 보통 format 땜에 씀. 여기서 숫자 출력 형식 문자들을 씀.
WHENEVER you write a date in a query, ALWAYS use TO_DATE. 여기서 DON'T GET CONFUSED!!! You use TO_CHAR for the date as well if it's a formatting thing!! but if you're using a date for other purposes like hdate before or after a certain date, use TO_DATE().
> SELECT TO_CHAR(sysdate, '"오늘은 "YYYY"년 "MM"월 "DD"일 입니다."') 날짜 FROM DUAL;
--> ' ' because it's date and not number. The underlined part needs to have ' ' around it as long as it's either a date or a char.
--> * also, don't forget to add NICKNAME after to_char() or to_date() functions!!
> SELECT eno, ename, hdate FROM emp WHERE hdate < TO_DATE('19920101','YYYYMMDD');
--> You use TO_DATE when you are comparing something to a DATE data-type column, since you can only compare dates to a date.
--> OR when you are inserting an entry into a database that has a DATE data-type column.
PHP