Oracle: If Table Exists

The best and most efficient way is to catch the “table not found” exception: this avoids the overhead of checking if the table exists twice; and doesn’t suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller: BEGIN EXECUTE IMMEDIATE … Read more

SQL query to select dates between two dates

you should put those two dates between single quotes like.. select Date, TotalAllowance from Calculation where EmployeeId = 1 and Date between ‘2011/02/25’ and ‘2011/02/27’ or can use select Date, TotalAllowance from Calculation where EmployeeId = 1 and Date >= ‘2011/02/25’ and Date <= ‘2011/02/27’ keep in mind that the first date is inclusive, but … Read more

How to set variable from a SQL query?

Using SELECT SELECT @ModelID = m.modelid FROM MODELS m WHERE m.areaid = ‘South Coast’ Using SET SET @ModelID = (SELECT m.modelid FROM MODELS m WHERE m.areaid = ‘South Coast’) See this question for the difference between using SELECT and SET in TSQL. Warning If this SELECT statement returns multiple values (bad to begin with): When … Read more

Best database field type for a URL

Lowest common denominator max URL length among popular web browsers: 2,083 (Internet Explorer) http://dev.mysql.com/doc/refman/5.0/en/char.html Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 … Read more

How to create a MySQL hierarchical recursive query?

For MySQL 8+: use the recursive with syntax. For MySQL 5.x: use inline variables, path IDs, or self-joins. MySQL 8+ with recursive cte (id, name, parent_id) as ( select id, name, parent_id from products where parent_id = 19 union all select p.id, p.name, p.parent_id from products p inner join cte on p.parent_id = cte.id ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)