The question is very common, but I am facing one single issue in there for which I am not able to find the answer. What I have to do is, create a table if the table does not exist. But while creating the table, I need to create it from the select query(which is result of JOIN of two tables). This is for "ORACLE SQL DEVELOPER" / "PL/SQL".
The query I am using is:
DECLARE
count_matching_tbl BINARY_INTEGER := 0;
BEGIN
SELECT COUNT(*)
INTO count_matching_tbl
FROM dba_tables
WHERE LOWER(table_name) = 'testtable';
IF(count_matching_tbl = 0)
THEN
EXECUTE IMMEDIATE ( ' CREATE TABLE testtable AS (SELECT A.*, B.* from tab1 A JOIN tab2 B ON A.id = B.RID WHERE 1=2)');
END IF;
END;