Table columns have weird characters
I have this script to generate a table.
p.s. This is an ETL table for incoming data - I know about the bad structure, but cannot change it.
In Toad, the table structure looks like this (with the weird characters shown):
And when I click on the data tab, I get the following error:
Why are all these weird characters showing up?
You can get odd characters in table/column names by quoting them [eg create table "test one" ("id#" number); ]
I'd be more concerned about the odd characters in the Histogram column which is system generated. I'd try SQL*Plus and select DUMP(column_name), dump(historgram) from user_tab_columns
That way you may be able to see if the problem is with how TOAD is working, or with the stuff in the database.
looks like some cut and paste characters.
try cutting the script into notepad, then save it, then cut it back out of notepad and running it in sql plus or the toad edit window.
that should remove funny chars.
(you will probably want to drop that existing table before running the script again )
Related
I'm trying to export the results of a query in Oracle SQL Developer. One of my columns is a user-defined type which looks like this when it gets exported:
SDE.ST_GEOMETRY(1,1,2702721.09480406,249404.580511138,2702721.09480406,249404.580511138,NULL,NULL,NULL,NULL,0,0,2272,'oracle.sql.BLOB#615bd3ac')
The problem is that SQL Developer doesn't quote values of this column, even though I've specified left and right enclosures of ", and the commas inside the parentheses break my CSV file.
Is there any way to force SQL Developer to enclose all values on export?
As seen from your problem add extra pipes in beginning and end of the column as like:
select ||'|'||column1||'|'|| from table1;
I am trying to export data from Oracle PLSQL to Excel.
The data type of one of the column is VARCHAR2.
The Column conatins value like 00798019859217.
But after exporting, the value in excel is something like this 7.9802E+11.
PLease let me know how to resolve this and the reason for this format issue.
Thanks in advance.
Do the following:
Select the column with single quotes, say
SELECT ("'" || COLUMN_NAME) AS COLUMN_NAME, OTHER_COLUMNS FROM MY_TABLE
Output will be like:
'ABC0157976
'00798019859217
Export the output to an excel.In excel "A" column values will be
'ABC0157976
00798019859217 (Single quote will not be visible for number only values)
Select the entire "A" row and clear all single quotes with replace all option. You will get final excel as.
ABC0157976
00798019859217
Since it is a text field and non-numeric characters are also expected to be present, the step#3 is required. If it is going to be only numeric characters, then step #3 can be ignored.
This is happening due to excel where the number auto casted. As #HamidP said try exporting as csv and check with opening in notepad or text, and check whether the number displaying fully or not. If so then you can open the same in Excel with small options change such
Right click the cell and click format option and make it cell format as text and then save the excel.
I apologize for posting a question that seems to have been asked numerous times on the internet, but I can't quite fix it for some reason.
I was trying to populate some tables using Oracle's magical sqldr utility, but it throws an ORA-01775 error for some reason.
Everywhere I go on Google, people say something along the lines of: "Amateur, get your synonyms sorted out" (that was paraphrased) and that's nice and all, but I did not make any synonyms.
Here, the following does not work on my system:
SQLPLUS user/password
SQL>CREATE TABLE test (name varchar(10), id number);
SQL>exit
Then, I have a .ctl file with the following contents:
load data
characterset utf16
infile *
append
into table test
(name,
id
)
begindata
"GURRR" 4567
Then I run this command:
sqlldr user#localhost/password control=/tmp/controlfiles/test.ctl
The result:
SQL*Loader-702: Internal error - ulndotvcol: OCIStmtExecute()
ORA-01775: looping chain of synonyms
Part of test.log:
Table TEST, loaded from every logical record.
Insert option in effect for this table: APPEND
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
NAME FIRST 2 CHARACTER
ID NEXT 2 CHARACTER
SQL*Loader-702: Internal error - ulndotvcol: OCIStmtExecute()
ORA-01775: looping chain of synonyms
And, if I try to do a manual insert:
SQL> insert into test values ('aa', 56);
1 row created.
There is no problem.
So, yeah, I am stuck!
If it helps, I am using Oracle 11g XE on CentOS.
Thanks for the help guys, I appreciate it.
EDIT:
I kind of, sort of figured out part of the problem. The problem was that somewhere along the line, maybe during a failed load or something, Oracle had given itself corrupt views and synonyms.
The affected views were: GV_$LOADISTAT, GV_$LOADPSTAT, V_$LOADISTAT and V_$LOADPSTAT. I am not quite sure why the views got corrupt, but recompiling them resulted in compiled with errorserrors. The synonyms used in the queries themselves were corrupt, namely the gv$loadistat, gv$loadpstat, v$loadistat and v$loadpstat synonyms.
I wasn't sure about why this was happening and I didn't quite understand anything. So, I decided to drop the synonyms and recreate them. Unfortunately, I couldn't recreate them, as the view they pointed to (there is a bit of weird recursion going on here...) was corrupt. These views were the aforementioned GV_$LOADISTAT and other views. In other words, the synonyms pointed to the views that used those synonyms. Talk about a looping chain.
So...I recreated the public synonyms but instead of specifying the view as GV_$LOADISTAT, I specified them as sys.GV_$LOADISTAT. e.g.
DROP PUBLIC synonym GV$LOADISTAT;
CREATE PUBLIC synonym GV$LOADISTAT for sys.GV_$LOADISTAT;
Then, I recreated the user views to point to those public synonyms.
CREATE OR REPLACE FORCE VIEW "USER"."GV_$LOADISTAT" ("INST_ID", "OWNER", "TABNAME", "INDEXNAME", "SUBNAME", "MESSAGE_NUM", "MESSAGE")
AS
SELECT "INST_ID",
"OWNER",
"TABNAME",
"INDEXNAME",
"SUBNAME",
"MESSAGE_NUM",
"MESSAGE"
FROM gv$loadistat;
That seemed to fix the views/synonyms. Yeah, it is a bit of a hack, but it somehow worked. Unfortunately, this was not enough to run SQL Loader. I got a table or view does not exist error.
I tried granting more permissions to my regular user, but it didn't work. So, I gave up and ran SQL Loader as sysdba. It worked! It is not a good thing to do, but it is a development only system made for testing purposes, so, I didn't care.
I could not repeat your looping synonym chain error, but it appears the control file needed a bit of work, at least for my environment.
I was able to get your example to work by modifying it thusly:
load data
infile *
append
into table test
fields terminated by "," optionally enclosed by '"'
(name,
id
)
begindata
"GURRR",4567
This question may be Toad specific. I have no idea how Oracle stores views, so I'll explain what happens when I use Toad. If I get an answer that is Oracle specific, so much the better.
I have created a rather complex view. To make it clearer, I have formatted the code nicely, and entered some comments where needed. When I need to make changes to the view, I use Toad's "describe objects" window, where I can find a script to recreate the view. The only problem is that all my formatting is gone. Comments before the select keyword (but after "create view xxx as") will also disappear.
If I enter this script to create a view:
create or replace view TestViewFormatting as
-- Here I have a long comment explaining the role of the
-- view and certain things to be aware of if changing it.
-- Unfortunately this comment will disappear...
select
name, --This comment will be kept
accountnumber --This also
from
debtable
where
name like 'S%';
Toad will display this when I describe it later:
DROP VIEW XXX.TESTVIEWFORMATTING;
/* Formatted on 04.07.2012 09:35:45 (QP5 v5.185.11230.41888) */
CREATE OR REPLACE FORCE VIEW XXX.TESTVIEWFORMATTING
(
NAME,
ACCOUNTNUMBER
)
AS
select name, --This comment will be kept
accountnumber --This also
from debtable
where name like 'S%';
Note that the first comment has disappeared, and that the format is totally different.
I suspect that Oracle doesn't store the code of the view, just some parsed version, and when Toad brings up the script, it reverses this parsed version and generates a script on the fly.
What will I have to do to make Toad/Oracle keep the original formatting?
(PS: I know I can change the settings for Toad's code formatter, but this is not what I want to do. Due to some questionable choices in my past, this particular view has several levels of inline views, and I need a very specific formatting to make it clear what happens)
select text from user_views
where view_name = 'YOUR_VIEW_NAME';
I've tested with:
create view z_v_test as
select
-- te
--st
* from
dual;
and it keeps even the blank line.
Another way is to use DBMS_METADATA:
select dbms_metadata.get_ddl('VIEW', 'YOUR_VIEW_NAME', user) from dual
This works not only for views, but also for (nearly) all kind of database objects (tables, triggers, functions, ...).
I'm using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on the query results window doesn't give me any export options.
Version I am using
Update 5th May 2012
Jeff Smith has blogged showing, what I believe is the superior method to get CSV output from SQL Developer. Jeff's method is shown as Method 1 below:
Method 1
Add the comment /*csv*/ to your SQL query and run the query as a script (using F5 or the 2nd execution button on the worksheet toolbar)
select /*csv*/ *
from emp;
That's it.
You can also use spool to automatically save it as a CSV file:
spool "/path/to/file.csv";
select /*csv*/ *
from emp;
spool off;
Just be sure to "Run as Script" or press F5.
Method 2
Run a query
Right click and select unload.
Update. In Sql Developer Version 3.0.04 unload has been changed to export
Thanks to Janis Peisenieks for pointing this out
Revised screen shot for SQL Developer Version 3.0.04
From the format drop down select CSV
And follow the rest of the on screen instructions.
Not exactly "exporting," but you can select the rows (or Ctrl-A to select all of them) in the grid you'd like to export, and then copy with Ctrl-C.
The default is tab-delimited. You can paste that into Excel or some other editor and manipulate the delimiters all you like.
Also, if you use Ctrl-Shift-C instead of Ctrl-C, you'll also copy the column headers.
FYI, you can substitute the /*csv*/
for other formats as well including /*xml*/ and /*html*/.
select /*xml*/ * from emp would return an xml document with the query results for example.
I came across this article while looking for an easy way to return xml from a query.
FYI to anyone who runs into problems, there is a bug in CSV timestamp export that I just spent a few hours working around. Some fields I needed to export were of type timestamp. It appears the CSV export option even in the current version (3.0.04 as of this posting) fails to put the grouping symbols around timestamps. Very frustrating since spaces in the timestamps broke my import. The best workaround I found was to write my query with a TO_CHAR() on all my timestamps, which yields the correct output, albeit with a little more work. I hope this saves someone some time or gets Oracle on the ball with their next release.
To take an export to your local system from sql developer.
Path : C:\Source_Table_Extract\des_loan_due_dtls_src_boaf.csv
SPOOL "Path where you want to save the file"
SELECT /*csv*/ * FROM TABLE_NAME;
CSV Export does not escape your data. Watch out for strings which end in \ because the resulting \" will look like an escaped " and not a \. Then you have the wrong number of " and your entire row is broken.