I am currently trying to create a report using SQLPLUS, but the output keeps splitting after showing record #11.
I would like to see all the records under one output. The second columns 'Schema' and 'TOTAL_SIZE_IN_GB' are unnecessary and I want to get rid of them. How can I fix this?
Code:
set verify off
set feedback off
column owner format a15 heading 'Schema'
column total_size format 990.99 heading 'TOTAL_SIZE_IN_GB'
SELECT owner, ROUND(SUM(bytes)/1024/1024/1024, 2) total_size
FROM dba_segments
where (segment_type='TABLE' and owner like '%OBS%')
or (segment_type='TABLE' and owner like '%USR%')
group by owner
order by total_size DESC;
How many rows are shown "per page" is controlled by a setting, pagesize. (This is all SQL*Plus stuff, it has nothing to do with the query itself.) Issue the following SQL*Plus command before you run your query:
set pagesize 3000
(or some other number larger than the number of rows in your output).
Obviously, if you have 10000 rows in the output they will still be broken into "pages" of 3000 rows each, but I hope you are not actually creating a report, for human reading, with 10000 rows. No one will read that.
You could also set the pagesize to zero, but then you won't print column headers anymore; likely not what you need.
I tried to query the Monetdb server. I am printing the columns in the table called Ada and the columns are truncated and only few columns are displayed. On the terminal, it says to avoid dropping or truncating the columns use \w-1 but not sure how to use it in commands.
I am new to use MonetDB so I need some help. Thanks
fram -> Database
The query i used to print columns:
>select * FROM fram.Ada LIMIT 3;
Just type \w-1 in the sql prompt at mclient:
sql>\w-1
Fair warning though the result probably will not look that good. You can see a brief description of all the meta-commands valid in mclient by typing \?. Specifically for \w the description is:
\w# - set maximal page width (-1=unlimited, 0=terminal width, >0=limit to num)
So in order to go back to the previous behavior use \w0, or to format the result to use 120 character columns use \w120.
I solved it by first running
>\w-1
>select * FROM fram.Ada LIMIT 3;
I have two broad questions:
Q1. Are executing the lines of code in Oracle SQL Developer and executing the same code in sqlplus command prompt same things?
(reason I ask this that I heard that not all the sqlplus commands are executable in SQL Developer. If answer to above question is yes then please then few useful links will help).
Q2. I am spooling the results of a sql query to a .csv file, but the thing is that columns names are truncated according the maximum length of the values in that column.
My code is:
set colsep ","
spool C:\Oracle\sample.csv
select * from acct_clas_rule;
spool off;
Output of above code is (middle column is having null values)
ABCD_,ABCD_,ABC
-----,-----,---
AB , ,WSD
ABCD , ,WSD
ABCD , ,WSD
SG , ,WSD
KD , ,WSD
WD , ,LKJ
KLHGF, ,LKO
WSDFG, ,LOK
WSDF , ,LKO
WS , ,GH
In above output, columns names have been truncated. I want full names of the columns to be displayed. Can anyone help?
I have seen the question in this link, but I didn't understand how to apply the answers provided there as there was no particular example cited. I am new to these things so I couldn't understand.
Original names of my columns (from left to right in above table) are :
ABCD_DFGT_SDF, ABCD_EDF_GH, ABCD_DFRE
PS -
1. I am using Oracle SQL developer to run sqlplus commands. I think because of which few of my commands are not working (like set underline, set linesize etc.).Please let me know if this is the case. I actually want remove those underlines beneath the columns names.
2. Also let me know that whether you answer is applicable to Oracle SQL Developer or sqlplus.
Thank You
There are a couple of things you can do, in addition to #JChomel's approach - that will work in either SQL Develoepr or SQL*Plus, while these suggestions are specific to SQL Developer.
Let's start with a dummy query based on a CTE to get something like your situation:
set colsep ","
with acct_clas_rule (abdc_1, abcd_2, abcd_3) as (
select cast('AB' as varchar2(5)), cast(null as varchar2(5)), cast('WSD' as varchar2(4)) from dual
union all select 'ABCD', null, 'WSD' from dual
-- ...
union all select 'WS', null, 'GH' from dual
)
select * from acct_clas_rule;
When run as a script in SQL Developer (from the document+arrow icon, or F5) the output is:
ABDC_,ABCD_,ABCD
-----,-----,----
AB , ,WSD
ABCD , ,WSD
WS , ,GH
If you change the query to include the SQL Developer-specific formatting hint /*csv*/ then you get the output you want:
select /*csv*/ * from acct_clas_rule;
"ABDC_1","ABCD_2","ABCD_3"
"AB","","WSD"
"ABCD","","WSD"
"WS","","GH"
except that the strings are all enclosed in double-quotes, which might not be what you really want. (It depends what you're doing with the spooled file and whether any of your string values contain commas, which would confuse Excel for instance).
With more recent versions of SQL Developer you can get exactly the same result without modifying the query using the sqlformat option:
set sqlformat csv
select * from acct_clas_rule;
but again you get the double-quotes. You could change the double-quotes to different enclosure characters, but that probably doesn't help.
A different approach is to use the built-in export tools instead of spool. If you run the query as a statement (green 'play button' icon, or control-enter) then rather than appearing in the Script Output panel, a new Query Result panel will open next to that, showing the results as a grid.
If you right-click on the results you'll get a contextual menu, and choosing Export... from that will give you a wizard to export the results in a format of your choice, including CSV:
You can leave the left and right enclosures as double-quotes to get the same results as the options above, except that null values use the word 'null' instead of an empty string:
"ABDC_1","ABCD_2","ABCD_3"
"AB",null,"WSD"
"ABCD",null,"WSD"
"WS",null,"GH
or you can change them, or remove them by choosing 'none', which gives you:
ABDC_1,ABCD_2,ABCD_3
AB,null,WSD
ABCD,null,WSD
WS,null,G
#thatjeffsmith has commented on how to change the null-replacement text for the /*csv*/ approach. For export it looks like having the word 'null' might have been a bug in 17.2.0; in 17.3.1 that does not appear, and instead you see:
ABDC_1,ABCD_2,ABCD_3
AB,,WSD
ABCD,,WSD
WS,,GH
or enclosed empty strings ("") if you leave the enclosures set.
Q1: TI'm not an expert of SQL Developer. There might be a mode like "command line" or something where you could get similar result, but unsure.
Q2: You have to set the right option to sqlplus: here is a trick I know of (it will also remove the --- --- --- that will cause other issue):
SET HEADING OFF`, to avoid column name to be printed
Union all the column names at the beginning of your script:
set colsep ","
spool C:\Oracle\sample.csv
select 'ABCD_DFGT_SDF', 'ABCD_EDF_GH', 'ABCD_DFRE' from dual
UNION ALL
select * from acct_clas_rule;
spool off;
use the sql plus set command -----> set underline off
I am trying to run a hive query which should join two table with matching records. However, it never matches but i have the record in the other table. When i do length of a given string it outputs 27, but it should be just 12.
When i download the output file from s3 then i see weird row like
U S 3 F F 1 2 1 4 9 3 3
but in hive console it see it as
US3FF1214933
Also i cannot query the row with
select * from table where item like "US3FF1214933";
It is totally a mess right now and trimming also does not work for me.
I am in need of help.
Thanks in advance,
Thanks to legato for giving me an idea to investigate this by doing
od -c and seeing actual characters between the string.
And after in hive query using regexp_replace(ExString,'\0',"") to replace the weird characters with empty string solved my issue.
I need to write a query on an Oracle database where one of the fields is called ACCOUNT. ACCOUNT is on the reserved list http://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm and my query is failing.
In this DB, ACCOUNT is a VARCHAR2 and I cannot change it's name nor the structure of anything, I can only run SELECT queries.
Although ACCOUNT is a VARCHAR2, it always contains an integer and I want to get at a range of values.
I thought that this would do the trick:
SELECT *
FROM TABLE
WHERE TO_NUMBER(ACCOUNT) > 1000
AND TO_NUMBER(ACCOUNT) < 2000
but I just get an ORA-01722 invalid number error.
I have checked that ACCOUNT only contains integers and running this query with a non-reserved keyword works fine...
You can escape the reserve word using " double quote like
SELECT *
FROM TABLE
WHERE TO_NUMBER("ACCOUNT") > 1000
AND TO_NUMBER("ACCOUNT") < 2000
(OR) Better use BETWEEN construct like
SELECT *
FROM TABLE
WHERE TO_NUMBER("ACCOUNT") BETWEEN 1001 AND 1999
In case your table name really is TABLE; you need to escape that too cause that as well a reserve word.
I looked into your issue and I was able to DUPLICATE
this error ORA-01722 invalid number error. occurs because your sql is trying to convert something like
To_NUMBER('SOMETEXT') > SOME NUMBER
so when your sql is converting the to_number('somenumber as a varchar2') it comes across ('sometext varchar2)
an example
SELECT *
FROM TABLE as tbl
WHERE TO_NUMBER('helloworld') > 1000
this will throw that error. check your column's data, somewhere in that data, there is some text in one or more row.
have you tried to add an alias to the table
SELECT *
FROM TABLE as tbl
WHERE TO_NUMBER(tbl.ACCOUNT) > 1000
AND TO_NUMBER(tbl.ACCOUNT) < 2000