background preloader

SQL

Facebook Twitter

Oracle Dates and Times. Resources Database Systems: The Complete Book by Hector Garcia, Jeff Ullman, and Jennifer Widom.

Oracle Dates and Times

A First Course in Database Systems by Jeff Ullman and Jennifer Widom. Gradiance SQL Tutorial. Overview Oracle supports both date and time, albeit differently from the SQL2 standard. The DATE type is used in the same way as other built-in types such as INT. Create table x(a int, b date); DATE Format When a DATE value is displayed, Oracle must first convert that value from the special internal format to a printable string.

Select b from x; you will see something like: Whenever a DATE value is displayed, Oracle will call TO_CHAR automatically with the default DATE format. SELECT TO_CHAR(b, 'YYYY/MM/DD') AS b FROM x; returns the result: The general usage of TO_CHAR is: TO_CHAR(<date>, '<format>') where the <format> string can be formed from over 40 options. You have just learned how to output a DATE value using TO_CHAR. Insert into x values(99, '31-may-98'); CREATE a table from another table. Mysql - Odd CONCAT Error with Select/Insert. MySQL concat() function < MySql Tutorial. MySQL concat() function has average rating 8 out of 10.

MySQL concat() function < MySql Tutorial

Total 61 users rated. <<PreviousNext>> Description MySQL CONCAT() function is used to add two or more strings. There may be one or more arguments. Syntax CONCAT (string1, string2,…) Arguments MySQL Version : 5.6 Examples of MySQL CONCAT() function One argument : mysql> SELECT CONCAT('w3resource'); +----------------------+ | CONCAT('w3resource') | +----------------------+ | w3resource | +----------------------+ 1 row in set (0.00 sec) Two or more arguments : mysql> SELECT CONCAT('w3resource','.' One of the arguments is NULL : mysql> SELECT CONCAT('w3resource','.' Numeric argument : mysql> SELECT CONCAT(102.33); +----------------+ | CONCAT(102.33) | +----------------+ | 102.33 | +----------------+ 1 row in set (0.00 sec) For quoted strings, concatenation can be performed by placing the strings next to each other : mysql>SELECT 'w3resource' '.' Pictorial representation of MySQL CONCAT() function Example of MySQL CONCAT() function on columns Output <!

SQL Concatenate Function - 1Keydata SQL Tutorial. SQL > SQL String Functions > Concatenate Sometimes it is necessary to combine together (concatenate) the results from several different fields.

SQL Concatenate Function - 1Keydata SQL Tutorial

V15 - Oracle SQL Tutorial - Insert data into a table. Joins. Learn how to use SQL joins with syntax, visual illustrations, and examples.

Joins

Description SQL JOINS are used to retrieve data from multiple tables. SQL Tutorials: SQL IF...ELSE Statement. SQL IF...ELSE Statement used to test a condition.

SQL Tutorials: SQL IF...ELSE Statement

IF...ELSE Statement using in execution of a Transact-SQL statement (Store Procedure or T-SQL) and Trigger.IF tests can be nested after another IF or following an ELSE. There is no limit to the number of nested levels. IF condition is satisfied and the Boolean expression returns TRUE, it will executed IF Block Sql statement. IF condtion is not satisfied and the Boolean expression returns FALSE, it will executed ELSE Block Sql Statement query. Syntax for IF...ELSEIF ( Boolean_expression ) BEGINSql Statement BlockENDELSE BEGINSql Statement BlockENDBelow is simple example of IF...ELSE Statement With 1 IF...ELSE BlockFor Boolean_expression part, you can replace with your condition to match with your Sql query. Oracle Tip: Create functions to join and split strings in SQL. Learn how to take a comma delimited list of values in a single string and use it as a table of values.

Oracle Tip: Create functions to join and split strings in SQL

A common task when selecting data from a database is to take a set of values a query returns and format it as a comma delimited list. Another task that's almost as common is the need to do the reverse: Take a comma delimited list of values in a single string and use it as a table of values. Many scripting languages, such as Perl and Python, provide functions that do this with their own language-specific list of values; so it's surprising that, as of yet, this functionality isn't a standard part of SQL functions. I've seen some pretty ugly looking code that involved complex declarations with MAX and DECODE, but that solution usually only returns a limited set of values.

With some of the new Oracle9i and above features, it's possible to do this yourself. Create table [Oracle SQL] Prerequisites Additionally, the user needs to have enough quota on the tablespace where he wants to create the table.

create table [Oracle SQL]

Heap tables Usually, if we refer to tables, we mean heap tables, although there are other types as well. A heap table is created like this: create table t ( a number, b varchar2(10) ) It is possible to create the constraints together with the create statement. Create table orders ( order_id number primary key order_dt date, cust_id references customers ) A primary key needs to have an associated (unique) index.