Oracle truncating column - oracle

I have the following query.
insert into ORDER_INFO(ORDINF_PK,ORDINF_LGNDET_PK_FK,MEDIA_TYPE,ORDINF_MUSIC_FK,DAT)
values (1,1,'Music',21,TO_DATE('14-OCT-2015','DD-MON-YYYY'));
insert into ORDER_INFO(ORDINF_PK,ORDINF_LGNDET_PK_FK,MEDIA_TYPE,ORDINF_MUSIC_FK,ORDINF_SERIES_FK,DAT)
values (2,2,'Series',71,23,TO_DATE('07-NOV-2015','DD-MON-YYYY'));
however when I do:
select * from ORDER_INFO;
I get:
truncating (as requested) before column ORDINF_SERIES_FK
truncating (as requested) before column ORDINF_MOVIES_FK
ORDINF_PK ORDINF_LGNDET_PK_FK MEDIA_TYPE ORDINF_MUSIC_FK DAT
---------- ------------------- -------------------- --------------- ---------
1 1 Music 21 14-NOV-14
2 2 Series 71 07-NOV-15
I understand that it is truncating ORDINF_MOVIES_FK because there is no entry in that column, but why is it truncating the column ORDINF_SERIES_FK?

I managed to solve the issue, I did this.
set wrap on;
set pagesize 50000;
set linesize 120;
link here: http://www.anattatechnologies.com/q/2012/01/sqlplus-pagesize-and-linesize/

Pay attention - both rows inserted and ARE in the database, so INSERT succeeded.
The warning you get is a warning from SQLPlus program that means that column is display not with full width (maybe the definition of column is long and SQLPlus decides to show column shorter because data you have in there is short).
You do not need to worry about this in any case.
See this link for more explanation about SQL*Plus wrap.

Related

Rows not copied to destination table from source table using oracle sqlplus copy command

I am using this copy command.
COPY FROM username/[pwd]#identifier INSERT SCHEMA_NAME.TABLE_NAME
USING SELECT * FROM SCHEMA_NAME.TABLE_NAME;
Note : Both the source and target tables are in different databases. The source table has around 19 million records. Both tables have 198 columns.
and I am getting the below message when the copy command is executed (I am not seeing any error message but no rows are copied).
Array fetch/bind size is 5000. (arraysize is 5000)
Will commit after every 100 array binds. (copycommit is 100)
Maximum long size is 80. (long is 80)
0 rows selected from username/[pwd]#identifier.
0 rows inserted into SCHEMA_NAME.TABLE_NAME.
0 rows committed into SCHEMA_NAME.TABLE_NAME at DEFAULT HOST connection.
Please help me on this or any possible guidance to tackle above issue is deeply appreciated.
I tried it on my local 11g XE database; it works OK.
SQL> create table test as select * From dept where 1 = 2;
Table created.
SQL> copy from scott/tiger#xe insert test using select * from dept;
Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
4 rows selected from scott#xe.
4 rows inserted into TEST.
4 rows committed into TEST at DEFAULT HOST connection.
SQL> select * From test;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
Your query selected nothing and inserted nothing, which looks as if query doesn't do what you thought it would. Did you make sure that it is correctly written and that it fetches some rows?
As of disadvantages: Oracle 19c documentation says that
The COPY command will be deprecated in future releases of SQL*Plus. After Oracle 9i, no new datatypes are supported by COPY.
so you'd probably rather use other options to move data around. That would be e.g.
INSERT INTO
MERGE
data pump export & import

How to spool a number in oracle in correct format

I am trying to spool the records by executing script in SqlDeveloper, everything is working fine except printing the record of columns which are NUMBER(38,0) data type.
All numbers record are printing in below format:
1.5E+18
I tried many combinations by using set but nothing working.
You can use to_char; for example:
SQL> select to_char(n, '999999999999999999999') from numbers;
TO_CHAR(N,'99999999999
----------------------
1500000000000000000
This way you can decide the exact format you want to use; for example:
SQL> select to_char(n, 'FM999G999G999G999G999G999G999G999') from numbers;
TO_CHAR(N,'FM999G999G999G999G999
--------------------------------
1.500.000.000.000.000.000
If you don't need a full control on the format, and/or you don't want to chenge your code, you can follow the suggestion by Nicholas Krasnov :
SQL> set numwidth 50
SQL> select n from numbers;
N
--------------------------------------------------
1500000000000000000

Why does Oracle round up a number with less than 38 significant digits?

We have Oracle Server 10.2.
To test this, I have a very simple table.
CREATE TABLE MYSCHEMA.TESTNUMBER
(
TESTNUMBER NUMBER
)
When I try to insert 0.98692326671601283 the number gets rounded up.
INSERT INTO MYSCHEMA.TESTNUMBER (TESTNUMBER)
VALUES (0.98692326671601283);
The select returns:
select * from TESTNUMBER
0.986923266716013
It rounds up the last 3 numbers "283" to "3".
Even looking at it with TOAD UI and trying to enter it with TOAD, I get the same result.
Why? Is it possible to insert this number in an Oracle number without it getting rounded up?
I think you need to look into how your client program displays number values. An Oracle NUMBER should store that value with full precision; but the value may be rounded for display by the client.
For instance, using SQLPlus:
dev> create table dctest (x number);
Table created.
dev> insert into dctest VALUES (0.98692326671601283);
1 row created.
dev> select * from dctest;
X
----------
.986923267
dev> column x format 0.000000000000000000000000000
dev> /
X
------------------------------
0.986923266716012830000000000
As you can see, the default format shows only the first 9 significant digits. But when I explicitly change the column formatting (a client-side feature in SQLPlus), the full value inserted is displayed.

Where those sqlplus columns are used?

Just type col in sqlplus returns a list of columns, there are some columns ended with _recyc, where those columns are used ? I googled but could not find any documentation on them.
COLUMN droptime_plus_show_recyc ON
HEADING 'DROP TIME'
FORMAT a19
COLUMN objtype_plus_show_recyc ON
HEADING 'OBJECT TYPE'
FORMAT a12
COLUMN objectname_plus_show_recyc ON
HEADING 'RECYCLEBIN NAME'
FORMAT a30
COLUMN origname_plus_show_recyc ON
HEADING 'ORIGINAL NAME'
FORMAT a16
They're used by the show recyclebin command. If you run that you get headings like:
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
...
If you do clear columns and run it again you get:
ORIGNAME_PLUS_SHOW_RECYC OBJECTNAME_PLUS_SHOW_RECYC OBJTYPE_PLUS_SHOW_RECYC DROPTIME_PLUS_SHOW_
-------------------------------- ------------------------------ ------------------------- -------------------
...
Whatever underlying query show recyclebin is using (some variant of select .. from user_recyclebin presumably) is aliasing the columns in the resultset; SQL*Plus is configured to format those aliased names.
The other pre-set column definitions are similar; for example, show edition gives a column displayed with heading EDITION, but if you clear columns it reverts to the underlying NAME_COL_PLUS_SHOW_EDITION. Anything with _PLUS_SHOW_ is going to be for some output from a show command.

How to display to terminal in SQLPLUS the column of a row with the width of the max value of the data within that column

I was wondering if this could be done without the COLUMN FORMAT.
Current example:
TABLESPACE_NAME BIG DATAFILE_NAME
------------------------------ --- -------------------------------------------------------------------------------------------------------------------
STORETABS NO C:\ORACLE\APP\ASUH\ORADATA\TESTORCL\STORETABS_01.DBF
STORETABS NO C:\ORACLE\APP\ASUH\ORADATA\TESTORCL\STORETABS_02.DBF
Notice the header "-" lines are extended all the way out to match the varchar(n) value defined.
Is there a SQLPLUS SET command that will auto adjust the column width to either the size of the column header or the size of the max data within the column?
I want it to look like this:
TABLESPACE_NAME BIG DATAFILE_NAME
---------------- --- -----------------------------------------------------
STORETABS NO C:\ORACLE\APP\ASUH\ORADATA\TESTORCL\STORETABS_01.DBF
STORETABS NO C:\ORACLE\APP\ASUH\ORADATA\TESTORCL\STORETABS_02.DBF
If not by the size of the column header, adjusting to the max size of the data is more desired.
No, there is no such setting.
There can't be such a setting, because SQL*Plus fetches arraysize (default of which is 15, I believe) records at a time. So, if after 15 records another longer record is fetched, the -------.... is already printed/written, leaving no chance to SQL*Plus to adjust it.
arraysize is the number set with set arraysize n.

Resources