I'm new to oracle (or SQL in general) and trying to get stuff done.
In MS SQL Server I can do select * from tablename; and it displays all the data in a tabulated format. If I do that in Oracle it displays the data in a weird format that's hard to read, unless I specifically select the columns I want.
Is there a way to display the data in Oracle formatted like regular MSSQL format?
I looked around and people say to use SHOW COLUMNS FROM TABLENAME; but that gives me an error saying "unknown option". I can do Desc tablename but that only gives me the metadata.
Welcome to Oracle!
As a new user, we have 2 command-line interfaces. It sounds like you're using SQL*Plus. We also have something called SQLcl.
The latter includes automatic output formatting so you don't have to do the things like 'linesize' or 'format' in your commands to get readable query results.
I think you are using SQLPlus window to see output. You have to format it to see good.
First
set linesize 5000;
This command will make your row long enough to hold columns. You need to increase or decrease number according your need.
Set pagesize 100;
Here, 100 is number of records in one page to show.
Moreover, some column length are very big in database. You need to format display for those specific column to show it as short.
COLUMN Column_NAME FORMAT A10;
Here, a10 is ten digit for that column.
Use below query, use solution 2 if you don't know exact table name:
--Solution1
select column_name,table_name from all_tab_cols where table_name='table_name'
--Solution2
select column_name,table_name from all_tab_cols where table_name like '%table_name%'
Download SQLDeveloper from Oracle. It's free to use.
Related
How do I find out what text was used to create a view in oracle sql, especially how do I find out what columns may be hidden?
select view_name, text from all_views where viewname = 'XYZ';
will give me the first few words only
sql developer has a tab for this, I'm just wondering if there is a way to do it from the command line in sqlplus.
By default SQL*Plus only shows the first 80 characters of long and clob columns. You can do set long 32767 (or some other large number; 30000 seems to be common, I think from older releases where the limit was 32K and that was easier to type, but it is 2M now) and reissue your query.
You can also use the dbms_metadata package to get the view DDL, if it is your view (in your schema) or you have the select catalog role.
select dbms_metadata.get_ddl('VIEW', 'XYZ')
You'll need to do set long for that to show you a useful amount of output too; and specify the schema with the third argument if it isn't in your schema.
Sorry if my questions sounds silly, but I never worked with Oracle databases.
If I'm executing select * from table in MS Management Studio I have 3 options to select that data. I'm using grid and sometimes text. Using grid you're able to easily copy this into Excel spreadsheet.
When I'm selecting data from Oracle database table I have to format each column, but when I'm executing select * from table, I'm getting something very unreadable.
I'm using SQL Developer. Is there any way to retrieve data in more friendly view?
Thanks
Use Run Statement command (green arrow or Ctrl+Enter).
If you want export data, you can right click on table and select Export..
First, SQL Developer allows you to export selected data into many format, including the "new" XLSX spreadsheet format. So you do not really need to worry about formatting.
But if you want to do it yourself, you can try to select the data in CSV format that is very easy to convert to Excel spreadsheet. Something like this:
SELECT '"' || column1 || '","' || column2 || '"'
FROM table
WHERE ...
You might want to convert dates to some universal format (like YYYY-MM-DD) and you need to enclose text with double quotes if they contain double quotes.
You might want to consider using Toad for Oracle, The free version gives you the option to view your data in Grid Format and you will also be able to export it out into Excel or csv.
is there a way to actually query the database in a such a way to search for a particular value in every table across the whole database ?
Something like a file search in Eclipse, it searches accross the whole worspace and project ?
Sorry about that .. its MS SQL 2005
SQL Workbench/J has a built in tool and command to do that.
It's JDBC based and should also work with SQL Server.
You will need to use the LIKE operator, and search through each field separately. i.e.
SELECT * FROM <table name>
WHERE (<field name1> LIKE '%<search value>%') OR
(<field name2> LIKE '%<search value>%') OR
... etc.
This isn't a quick way though.
I think the best way would be to
1) programatically generate the query and run it
2) use a GUI tool for the SQL server you are using which provides this functionality.
In mysql you can use union operator like
(SELECT * from table A where name = 'abc') UNION (SELECT * from
table B where middlename = 'pqr')
and so on
use full text search for efficency
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Well, your best bet is to write a procedure to do this. But to give you some pointers you can use the INFORMATION_SCHEMA.Tables to get a list of all the tables in a given database and INFORMATION_SCHEMA.Columns to get a list of all columns. These tables also give you the datatype of columns. So you will need a few loops on these tables to do the magic.
It should be mentioned most RDBMSs nowadays support these schemas.
In phpmyadmin, go to your database, reach the search tab.
Here you will be able to select all of your tables and search through your entire db in one time.
I don't know if anyone can help me. In my job, I inherited a completely undocumented database (Oracle 11). So far, I've managed to map most of the tables and determine what's going on where. However, there are a few columns that I haven't been able to decipher.
Is there some way of finding out how is the data in the column built? This is not a manual input. Everything seems to point to the data being the result of an entry in a different column in a completely different table.
It might be an impossible task, but any and all suggestions will be more than welcome.
Thanks!
C
Perhaps the data is being inserted in your mystery columns via a trigger? Try looking in the PL/SQL source table in the dictionary:
SELECT owner, name, type, line
FROM dba_source
WHERE UPPER(text) LIKE '%MYSTERY_COLUMN_NAME%'
AND type = 'TRIGGER'; -- use or omit this as desired.
This will get you pointed in some possible places to look.
Good luck!
You can retrieve the complete DDL for a table using the DBMS_METADATA package.
SELECT dbms_metadata.get_ddl('TABLE', 'YOUR_TABLE_NAME', 'YOUR_USER_NAME')
FROM dual;
If those columns are really computed columns then this should be visible in the DDL for the table.
Alternatively you can use SQL Developer to show the DDL for the table
I am presuming that you already have the sql that is in question.
select table_name from dba_tab_columns
where column_name = 'COLUMN_YOU_WANT_TO_KNOW'
will provide all tables that contain a column name that you are looking for. If you do not have dba privileges you can use all_tab_columns instead (which will show all tables your account would have access to).
Hi guys I'm using varchar2 for a product name field, but when I query the database from the run SQL command line it shows too many empty spaces, how can I fix this without changing the datatype
here is the link to the ss
http://img203.imageshack.us/img203/20/varchar.jpg
The data that got inserted into the database (probably through some ETL process) had spaces which were not trimmed.
You could update using (pseudo code)
Update Table Set Column = Trim(Column)
If TRIM does not change the results, that tells you that there are not trailing spaces in the actual database rows; they're just being added as part of the formatted screen output.
By default, sqlplus (the command-line Oracle tool you appear to be using) uses the maximum length of the varchar2 column as the (fixed) width when displaying the results of a select statement.
If you want to change this, use the column format sqlplus command before running the select. For example:
column DEPT_NAME format a20
Hi
Try to use trim on both sides,
Update TableName set FieldName = RTrim(LTrim(FieldName))
Regards