How to set numwidth in the grid output of PL/SQL developer? - sql

I'm running some queries in PL/SQL Developer, and one of the columns in the result has 18-digit numbers. Instead of displaying the entire number in the resulting grid, PL/SQL Developer displays only 15 digits in scientific notation.
I tried to find a way to change this in the preferences of the program, so that I'll see the entire number, just like set numwidth does in SQL*Plus. But my search was futile.
How do I change this setting?

Turns out this is possible!!!
Tools -> Preferences -> SQL Window ->
Number fields to_char

Use to_char, then you get the all the numbers:
select to_char ( t.reference_nr), t.reference_nr from rss_ing_cc_imp t
1 95209140353000001009592 9,5209140353E22
2 25546980354901372045601 2,55469803549014E22
3 75203220356000583867347 7,52032203560006E22
4 25546980357904327000017 2,55469803579043E22
5 95209140358000000700337 9,5209140358E22
6 95209140359000000596387 9,5209140359E22
7 25546980361131086003511 2,55469803611311E22
8 25546980361901390031808 2,55469803619014E22
9 85207130362051881964326 8,52071303620519E22
10 95209140363000000634885 9,5209140363E22
11 25546980364131099000436 2,55469803641311E22
12 95209141001000001006196 9,5209141001E22
13 85207131001100892094030 8,52071310011009E22
14 75203221001000590476576 7,52032210010006E22

You can also set the column format(Using the same table name as above...)
column reference_nr format 99999999999999999999999999999999
Select reference_nr from rss_ing_cc_imp;
REFERENCE_NR
95209140353000001009592
25546980354901372045601
Or ( new session ) which probably is better:
show numwidth
numwidth 10
Select reference_nr from rss_ing_cc_imp;
REFERENCE_NR
9.5E+22
2.6E+22
Set numwidth 30
show numwidth
numwidth 30
Select reference_nr from rss_ing_cc_imp;
REFERENCE_NR
95209140353000001009592
25546980354901372045601

SET sqlformat ansiconsole;
This will set the output format for any queries that you run hereafter. There are other sql formats but this is probably the best for your situation.
To revert to what you had earlier, use.
SET sqlformat;
*This has been verified on SQLDeveloper Version 18.3.0.277, Build 277.2354

Same answer as Ilya Kogan, but in PL SQL Dev 13 the Preferences has moved and is now under an little tuner icon in the title bar. Then SQL Window -> Number fields to_char

Related

How to ignore rows whose numbers are more than 6 digits

I have a few codes as you see in the screenshot below.
I want my database only to take code that has exactly 6 digits. The code which has more than 6 digits is expected to be deleted/ignored.
How do I write my SQL query for the same?
I was thinking to use Patindex but couldn't succeed in it.
I suggest using SQL Server's enhanced LIKE operator here:
SELECT *
FROM yourTable
WHERE Code LIKE '[0-9][0-9][0-9][0-9][0-9][0-9]';

Add System Date to file name during Oracle SQL Run

I am running the following code in SQL developer (oracle) to run the query and export a csv file into a folder. I would like to add the system date to the filename as well. I am using the following code. Although it does the job, it asks the user to input the date in the pop up window. I am looking to get rid of the pop up window and rather have the code use the system date instead. Is there any way i can eliminate the user input window?
Second issue is that this also brings in the SQL code to the output file along with the query results, is there any way to avoid bringing in the SQL as well?
set VERIFY off
set FEEDBACK off
set echo off
set heading off
col date_stp new_value date_stp
Select to_char(sysdate,'yyyymmdd') date_stp from dual;
Spool 'I:\Folder\ExportData&date_stp..csv';
SET sqlformat csv;
Select Customer, ID, etc -- the content of the query
Spool off;
Here's how: in order to avoid displaying the select statement within the spooled file, you need to
set term off
set feed off
but not directly in SQL*Plus (or SQL Developer); you'll have to save the following contents into a .SQL file and run it using #.
So: p.sql
set term off
set feed off
col sd new_value x
select to_char(sysdate,'YYYYMMDD') sd from dual;
spool dept&x..txt
select * From dept;
spool off
Testing:
SQL> #p --> call the .sql file
SQL> $dir *.txt
Volume in drive C is OSDisk
Volume Serial Number is 7635-F892
Directory of C:\Users\lf
12.06.2020. 21:13 494 dept20200612.txt --> file name is OK
1 File(s) 494 bytes
0 Dir(s) 260.040.732.672 bytes free
SQL> $type dept20200612.txt
--> no SELECT statement here
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
In order to stop SQL*Plus or SQL Developer asking for value of a substitution variable (that's what &something represents), run set define off.

Oracle returns value in 2 tables

currently I'm facing a problem where I select the data from db where it returns the data into 2 tables.
I have attached a screenshot of the output. Hope you guys can help. Thanks
This is Screenshot.
You need to format the output in the SQL*Plus to make the output looks proper.
You can use
COLUMN <column_name> FORMAT <format>;
for string:
COLUMN SCENE_NAME FORMAT a15
Example for numbers:
COLUMN SCENE_ID FORMAT 99
For more details on column formatting, please refer Oracle documentation here
Also, you will need to set the LINESIZE using
set linesize 250
here, 250 means the total character that can fit into one line and the size of the character is calculated based on the column format.
Before that you mention which database table you will display. After do select query

Problems while spooling data from Oracle. It spools elapsed time instead of spooling result of sql query into output file

I am trying to make a cron job that runs once a day. On invoking the shell script, it calls a Sql file. Which in turn Spools data into a file. This file is Picked by Shell Script and then mailed accordingly. Problem is when I try to spool data , it is writing elapsed time instead of writing actual result of query to the output file.
Here is the sql file I am using.
set define off
set numformat 99999999999999999999999999
set markup html on
set serveroutput on
set head on
set pages 3000
set echo off
DECLARE
total integer :=0;
total = select count(*) from t_c_table1 vt, t_c_table2 ti WHERE vt.f_item_id = ti.f_item_id (+) AND (f_update_date < sysdate - 30)order by F_INSERT_DATE desc;
IF total > 0 then
spool /home/output.csv
select f_name, count (*) from t_c_table1 where F_INSERT_DATE < sysdate-100 group by f_item_provider_id;
spool off
END IF
I get output like Elapsed: 00:00:00.506 in the spooled csv file.
Where am i going wrong?
Please Help.
Thanks in Advance..
Code you posted is wrong, it won't even compile in Oracle so I'm surprised that you got anything at all.
As there's no SET TIMING ON, I'm not sure what produced the elapsed time line in the spooled file. Maybe it is some old, previously created CSV file you're looking at?
Apart from the fact that SPOOL is a SQL*Plus command (so you can't invoke it in a PL/SQL procedure), the way you calculated the TOTAL variable's value is wrong - it should be part of the SELECT ... INTO statement.
SQL> declare
2 total integer := 0;
3 begin
4 select count(*)
5 into total
6 from dept;
7
8 if total > 0 then
9 spool test.csv
10 select * from dept;
11 spool off;
12 end if;
13 end;
14 /
spool test.csv
*
ERROR at line 9:
ORA-06550: line 9, column 12:
PLS-00103: Encountered the symbol "TEST" when expecting one of the following:
:= . ( # % ;
SQL>
If you want to spool data conditionally, you'll have to use the UTL_FILE package.
Or, you could do it "interactively" so that SQL*Plus asks you whether you want to spool data or not, as Alex Poole described in his answer here.

How do I convince Oracle SQL Developer to show number in scientific notation?

I'm using Oracle SQL Developer version 4.0.3, and I have a number in the order of 1e-13, so it's kind of inconvenient to have it shown as 0.0000000000001...
I couldn't find any option to change this behaviour, what I'd like is something like the opposite of this question, but for Oracle SQL developer:
How to set numwidth in the grid output of PL/SQL developer?
I just cannot find anything similar, does anyone know if this is possible?
From the documentation:
to_char(<your number column>, '9.9EEEE')
In SQL Developer 4:
I can't see any way to apply a model globally, as suggested by the accepted answer from the question you linked to - the current version of SQL Developer doesn't seem to have 'SQL Window' section under preferences like PL/SQL Developer does. But you probably don't want to apply the model to every number in every result set anyway.
Use TO_CHAR(1e-13, '0.9999999999999');. You need to check for the proper format model to convert the scientific notation into string. I used '.', you could also use 'D' as decimal separator, but it depends on your NLS_NUMERIC_CHARACTER.
See the different number formats here, http://www.java2s.com/Tutorial/Oracle/0300__Conversion-Functions/FormatParameters.htm
Update I initially answered the opposite of the requirement, i.e. convert from scientific notation to regular number format. The update is about converting number into scientific notation.
In SQL Developer, you would see something like this :
In SQL*Plus, the same SQL would convert the number into its scientific notation`.
SQL> WITH DATA AS(
2 SELECT to_number('0.0000000000001','0.99999999999999') num FROM dual
3 )
4 SELECT to_char(num, '9.9EEEE') num
5 FROM DATA;
NUM
---------
1.0E-13
SQL>
Without a format,
SQL> WITH DATA AS(
2 SELECT to_number('0.0000000000001','0.99999999999999') num FROM dual
3 )
4 select num from data;
NUM
----------
1.0000E-13
SQL>