INTO
Example
Section titled “Example”CREATE TABLE test_table (number INT, name VARCHAR(20));INSERT INTO test_table VALUES (1, 'Tom'), (2, 'Jerry');SELECT * FROM test_table;Output
Section titled “Output”+--------+-------+| number | name |+--------+-------+| 1 | Tom || 2 | Jerry |+--------+-------+Explanation
Section titled “Explanation”The above example demonstrates the use of the INTO keyword in SQL, specifically MySQL. A new table, test_table, is first created with two columns, number and name. Then, two rows of data are inserted using the INSERT INTO statement. The SELECT * FROM statement is used to display all rows from test_table.
Example
Section titled “Example”SELECT *INTO NewTableFROM OldTableWHERE Condition;Output
Section titled “Output”Command(s) completed successfully.Explanation
Section titled “Explanation”The example query duplicates an existing table named ‘OldTable’ and creates a new table named ‘NewTable’ with the same data structure and values - only for records that satisfy the given ‘Condition’. The result of the command isn’t a data set but a completion notification.
Example
Section titled “Example”DECLARE text_var VARCHAR2(100);BEGIN SELECT 'Hello, Oracle!' INTO text_var FROM dual;
DBMS_OUTPUT.PUT_LINE(text_var);END;Output
Section titled “Output”Hello, Oracle!Explanation
Section titled “Explanation”In the example, a variable text_var is declared to store text data. The SELECT INTO statement retrieves the string ‘Hello, Oracle!’ and assigns it to text_var. The DBMS_OUTPUT.PUT_LINE procedure prints the value of text_var, resulting in the output ‘Hello, Oracle!’. The FROM dual clause is a Oracle-specific syntax to select from a dummy table.
Example
Section titled “Example”CREATE TABLE Employee (Name STRING, Age INT);INSERT INTO Employee (Name, Age)VALUES ('John Doe', 30);Output
Section titled “Output”sqlite> SELECT * FROM Employee;John Doe|30Explanation
Section titled “Explanation”The INSERT INTO statement is used to insert new records into a table in SQLite. In the example, a new record is created for ‘John Doe’ with age ‘30’ in the ‘Employee’ table.