Tema Sectiunea 13

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

13-1: Creating Tables

Vocabulary
Data Dictionary->Created and maintained by the Oracle Server and contains
information
about the database

Schema->A collection of objects that are the logical structures that directly
refer to the data in the database

DEAFULT->Specifies a preset value if a value is omitted in the INSERT


statement

Table->Stores data; basic unit of storage composed of rows


and columns

CREATE TABLE->Command use to make a new table


Try It / Solve It
1.-
2. CREATE TABLE grad_candidates
(student_id number(6),
last_name varchar2(15),
first_name varchar(15),
credits number(3),
graduation_date date);
3.
DESCRIBE grad_candidates;
4.
CREATE TABLE herman_table
AS (SELECT*
FROM grad_candidates);
5.
INSERT INTO grad_students
(student_id, last_name, first_name, credits,graduation_date)
VALUES
(103,'Herman','Felician-Nicu',30,to_date('31 May,2016', 'dd Month,yyyy');
6.
users_tables->descrie toate tabelele din baza relationala de date
user_objects->descrie toate obiectele detinute de utilizator
user_catalog->arata indexe, tabele, vederi, sinonime si secvente detinute de
utilizator

13-2: Using Data Types

Vocabulary
INTERVAL YEAR TO MONTH->Allows time to be stored as an interval of years and months

TIMESTAMP LOCAL TIME ZONE->When a column is selected in a SQL statement the time is
automatically
converted to the user�s timezone

BLOB->Binary large object data up to 4 gigabytes

TIMESTAMP WITH TIME ZONE->Stores a time zone value as a displacement from Universal
Coordinated
Time or UCT

INTERVAL DAY TO SECOND->Allows time to be stored as an interval of days to hours,


minutes,
and seconds

CLOB->Character data up to 4 gigabytes

TIMESTAP->Allows the time to be stored as a date with fractional seconds


Try It / Solve It
1.
a.CREATE TABLE time_ex3 (first_column TIMESTAMP WITH TIME ZONE,
second_column TIMESTAMP WITH LOCAL TIME ZONE);

b.
CREATE TABLE time_ex4
(loan_duration1 INTERVAL YEAR(3) TO MONTH,
loan_duration2 INTERVAL YEAR(2) TO MONTH);
INSERT INTO time_ex4 (loan_duration1, loan_duration2 )
VALUES( INTERVAL '120' MONTH(3), INTERVAL '3-6' YEAR TO MONTH);
c.
CREATE TABLE time_ex5
(day_duration1 INTERVAL DAY(3) TO SECOND,
day_duration2 INTERVAL DAY(3) TO SECOND);
INSERT INTO time_ex5 (day_duration1, day_duration2 )
VALUES( INTERVAL '25' DAY(2), INTERVAL '4 10:30:10' DAY TO SECOND);
2.
SELECT * FROM time_ex3;

SELECT TO_CHAR( SYSDATE + loan_duration1 , 'DD-Month-YYYY') AS "120 months from


Now",
TO_CHAR( SYSDATE + loan_duration2 , 'DD-Month-YYYY') AS "3 years 6 months from
Now"
FROM time_ex4;
SELECT
TO_CHAR( SYSDATE + day_duration1 , 'DD-Month-YYYY hh:mi:ss') AS "25 days from
Now",
TO_CHAR( SYSDATE + day_duration2 , 'DD-Month-YYYY hh:mi:ss') AS
"4day10hr30min10sec from now "
FROM time_ex5;
3.
firme multinationale-ora de livrare a unui pachet
ora la care se difuzeaza o emisiune la tv

13-3: Modifying a Table

Try It / Solve It
1.
Greseli pot fi facute, iat schimbarea e permanenta.
2.
a.CREATE TABLE artists
(artist_id NUMBER(5,0),
first_name VARCHAR2(25),
last_name VARCHAR2(25),
band_name VARCHAR2(25),
email VARCHAR2(25),
hr_rate NUMBER(8,2),
song_id NUMBER(5,0)
);
b.
INSERT INTO artists (artist_id, first_name, last_name, band_name, email, hr_rate,
song_id)

c.
INSERT INTO artists (artist_id, first_name, last_name, band_name, email, hr_rate,
song_id)
VALUES(12,'Christina','Aguilera','Lilo Band','lilo.band@gmail.com','456.23',NULL);
d.
1)ALTER TABLE artists
ADD (genra VARCHAR2(100));
2)ALTER TABLE artists
DROP COLUMN genra;
3)RENAME artists TO theNewArtists;
4)TRUNCATE TABLE artists;
5)COMMENT ON TABLE artists
IS "These are the best artists";
3.
ALTER TABLE o_employees
ADD ("Termination" VARCHAR2(100) DEFAULT TO_CHAR(SYSDATE,'Month ddth, YYYY') );
4.
ALTER TABLE o_employees
ADD (start_date TIMESTAMP WITH LOCAL TIME ZONE);
5.TRUNCATE TABLE o_jobs;
coloanele sunt inca acolo, dar a disparut data;
6.
DROP->sterge definitia tabelului din baza de data impreuna cu datele
se poate folosi flashback
TRUNCATE->sterge inregistrarile si elibereaza spatiul de memorie
nu se pot recupera datele
DELETE->sterge randurile dar nu curata spatiul de stocare

7.
crestere precizie pt coloana cu numere/decrestere daca sunt numai null uri
crestere lungime coloana cu stringuri/decrestere pana la cea mai mare lungime
existenta
schimbare tip de data daca sunt null in tabel
specificare/modificare valoare default
o coloana poate fi stearsa(trebuie sa ramana cel putin o coloana in tabel)
setare ca si unused
8.
COMMENT ON TABLE o_jobs IS 'New job description added';

SELECT table_name, comments


FROM user_tab_comments WHERE LOWER(table_name) = 'o_jobs';
9.
ALTER TABLE o_jobs
RENAME TO o_job_description;
10.
a.CREATE TABLE copy_f_staffs
AS ( SELECT * FROM f_staffs);
b.
DESC copy_f_staffs;
c.
DROP TABLE copy_f_staffs;
d.
SELECT * FROM copy_f_staffs;

ORA-00942: table or view does not exist


e.
SELECT object_name
FROM user_recyclebin
WHERE LOWER(original_name) = 'copy_f_staffs';
f.
SELECT*
FROM "BIN$edvS62RVd+HgU81jFJCn2A==$0";
g.
FLASHBACK TABLE copy_f_staffs TO BEFORE DROP;
h.
DESCRIBE copy_f_staffs;
11.
a.
SELECT * FROM copy_f_staffs;
b.
UPDATE copy_f_staffs
SET salary = 12
WHERE first_name = 'Sue' AND last_name = 'Doe';
c.
SELECT * FROM copy_f_staffs;
d.
UPDATE copy_f_staffs
SET salary = 2
WHERE first_name = 'Sue' AND last_name = 'Doe';
e.
SELECT * FROM copy_f_staffs;
f.
SELECT versions_operation, versions_starttime, versions_endtime, id, first_name,
last_name, birthdate, salary,overtime_rate,training,staff_type,manager_id,
manager_budget,manager_target
FROM copy_f_staffs
VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
WHERE id = 12;

You might also like