Chapter 22 : DML Inserting Data into Tables Page 140 Insert Statement • To populate a table use the insert command. • The INSERT statement starts with the keywords INSERT INTO and table name, followed by the column list, and values. INSERT INTO tableName (column1, column2, column3, …) VALUES (value1, value2, value3, …); Example: Add the following row to the customer table: Customer_id 12345 Lname Springsteen Fname Bruce Add11212 Awesome Way City Rumsford State NJ Zip 08005 Insert Statement INSERT INTO tableName (column1, column2, …) VALUES (value1, value2, …); INSERT INTO customer (Customer_ID, Customer_lname, Customer_fname, Customer_add1, Customer_city, state, zip) VALUES (12345, ‘Springsteen’, ’Bruce’, ‘1212 Awesome Way’, ‘Rumsford’, ‘PA’, ‘08005’); To quote or not to quote!!! • Remember only strings (text ) in quotes • Datatypes of char, varchar • Must be single quotes. • Numbers are not in strings. • Use a describe command if you don’t know the datatype To_date • Functions must: ▫ ▫ ▫ ▫ Have name of function Open parentheses take arguments (i.e. parmeters) Close parentheses • Read page 141!!! • Basic syntax: • The TO_DATE’s syntax is as follows: ▫ to_date( string1, format_mask ) string1 is the string that will be converted to a date. format_mask is optional. This is the format that will be used to convert string1 to a date. Date formats • • • • • • to_date('2003/07/09', 'yyyy/mm/dd') returns a date value of July 9, 2003. to_date('070903', 'MMDDYY') returns a date value of July 9, 2003. to_date('20020315', 'yyyymmdd') returns a date value of Mar 15, 2002. What if you need to add time? • Just add the format for the time to the argument!!! • E.g. to enter 6:15 PM on 9/23/10 -> TO_DATE('09/23/2010 18:15:00', 'MM/DD/YYYY HH24:MI:SS') Can change format include seconds, 12 hour Insert Statement With Date INSERT INTO customer (Customer_ID, Customer_lname, Customer_fname, Customer_add1, Customer_city, state, zip, date_born) VALUES (12345, ‘Springsteen’, ’Bruce’, ‘1212 Awesome Way’, ‘Rumsford’, ‘PA’, ‘19112’, TO_DATE(’09/17/2009’, MM/DD/YYYY) ); When you’re done.. View your data: SELECT * FROM tableName; Save your work: COMMIT tableName ;