DB2 supports the standard SQL syntax to insert rows:
insert into mytable (name, phone)
values ('nick', '123-456-7890');
DB2 supports the standard SQL syntax to insert rows:
insert into mytable (name, phone)
values ('nick', '123-456-7890');
DB2 provides the FETCH FIRST command to limit query results.
select * from mytable fetch first 10 rows only;
To get the first 10 by column
A select statement fetches data from database tables and stores the results in a table called resultset. Your SQL tool displays the contents of the resultset.
Comments are text written by developers to leave an explanation in the code. Comments are ignored by the database. DB2 supports two types of comments:
/* */ --
Example
If you want to list tables in MySQL, you simply type the following command:
show tables
Oracle does not provide such a short cut. You have to type the following command:
extract function is used to extract year, month, or date from a date or timezone hour or timezone minute from an interval. Examples:
extract(DAY FROM DATE '2011-01-02') -- 02
To change the first letter of the word to cap, use the inicap function. Use upper to covert to uppercase and lower to convert to lower case. Examples:
initcap('change case') -- Change Case
NVL2 function extends the funcitonality of NVL function. NVL function prints the value of the variable unless a null value is encountered; in which case a value is substituted for the null.
Suppose you have two dates and you want to compares the years rather the exact date. Make sure you know the format of the dates. The use the following code:
The substr function extracts a substring from a string. Syntax:
substr( string, start position, length)
This error occurs if a wrong value is passed when converting a number or string to date. To fix this problem, find out what date format the date is stored in e.g. yyyymmdd, dd-mm-yy, dd-mon-yy, etc.
Peculiarly, Oracle uses the double pipe ( || ) as a concatenation operator. Most programming languages use || for the or operator. Example:
All columns of your SELECT must be listed in the GROUP BY expression. Alternately you can use functions MIN() or MAX() which compress results.
NVL function can be used to substitute a value when null in encountered. It has the following syntax:
NVL(string,replacement_string)