Posts

Showing posts with the label table

Common Mistakes 01 - rownum and order by

SQL> create table hr . numbers (id number ) tablespace EXAMPLE ; Table created . SQL> insert into hr . numbers (id) values( 19 ); SQL>   insert into hr . numbers (id) values( 3 ); SQL>   insert into hr . numbers (id) values( 15 ); SQL> insert into hr . numbers (id) values( 9 ); SQL>   insert into hr . numbers (id) values( 21 ); SQL>   insert into hr . numbers (id) values( 7 ); SQL>   insert into hr . numbers (id) values( 17 ); SQL>   insert into hr . numbers (id) values( 1 ); SQL> insert into hr . numbers (id) values( 11 ); SQL>   insert into hr . numbers (id) values( 5 ); SQL> commit; Commit complete. SQL> select id from hr . numbers ;         ID ----------         19          3         15          9         21          7         17          1         11          5 10 rows selected . Common Mistake.   A common mistake is  we

Literal object name using quotation marks ""

We create a new table. SQL> create table "HR" . "Test"   ( cmp01 number ( 5 ), cmp02 varchar2 ( 10 ) ) ; Table created . But apparently it doesn't exist. SQL> select * from HR . Test ; select * from HR . Test                  * ERROR at line 1 : ORA - 00942 : table or view does not exist Why doesn't my table exist if  i created it ???   SQL> select table_name , owner from dba_tables where table_name = 'TEST' ; no rows selected When you use quotation marks on object name, they will be case sensitive.  SQL>  select  table_name ,  owner  from  dba_tables  where   table_name = 'Test'; TABLE_NAME                     OWNER ------------------------------ ------------------------------ Test                           HR For example, using  quotation marks   you can create different object with same name: SQL> create table "HR"."test&

DBMS_METADATA package to retrieve metadata

--- Format set heading off; set echo off; Set pages 999 ; set long 90000 ; BEGIN dbms_metadata.set_transform_param ( DBMS_METADATA.SESSION_TRANSFORM , 'PRETTY' , TRUE ); dbms_metadata.set_transform_param ( DBMS_METADATA.SESSION_TRANSFORM , 'SQLTERMINATOR' , TRUE ); END; / --- Example   select dbms_metadata.get_ddl ( 'TRIGGER' , '&TRIGGER_NAME , '&OWNER' ) from dual ; select dbms_metadata.get_ddl ( 'TYPE' , '&TYPE_NAME' , '&OWNER' ) from dual ; select dbms_metadata.get_ddl ( 'INDEX' , '&INDEX_NAME' , '&OWNER' ) from dual ; select dbms_metadata.get_ddl ( 'TABLE' , '&TABLE_NAME' , '&OWNER' ) from dual ; select dbms_metadata.get_ddl ( 'TABLESPACE' , '&TABLESPACE_NAME' ) from dual ; select dbms_metadata.get_ddl ( 'PROCEDURE' , '&PROCE

Indexes and Functions - 01

The user said me that the table has a index in the date column that he used in his query SQL but is too slow. That is true, this table ( TB_EVENTS ) has an index in date type column ( EVNT_PK ).  SQL> SELECT TABLE_NAME , COLUMN_NAME , DATA_TYPE FROM DBA_TAB_COLUMNS WHERE TABLE_NAME = 'TB_EVENTS' AND COLUMN_NAME = 'EVENT_DATE' ; TABLE_NAME                     COLUMN_NAME                      DATA_TYPE ------------------------------ -------------------------------- ------------ TB_EVENTS                      EVENT_DATE                       DATE SQL> SELECT COL . INDEX_NAME ,    COL . COLUMN_NAME   FROM SYS . DBA_IND_COLUMNS COL   WHERE OWNER = 'PSP' AND INDEX_NAME = 'EVNT_PK' ; INDEX_NAME                     COLUMN_NAME ------------------------------ -------------------------------- EVNT_PK                        EVENT_DATE Ok, He use EVENT_DATE column in the WHERE but also use TO_CHAR function in