Is there any shortcut for formatting the query in plsql developer?
I want to format below query:
SELECT * FROM T1, T2 WHERE T1.ID = T2.ID
like:
select
*
from
T1, T2
WHERE
T1.ID = T2.ID
I am using version 12.0.7.
For this version, function name is not Edit / PL/SQL Beautifier
It is Tools / Source / PL/SQL Beautifier
It took some time for me to find it. I hope this help others.
PL/SQL Developer does not have a default keyboard shortcut to launch the PL/SQL Beautifier but it is easy to configure one.
Open Tools --> Preferences, click on "Key Configuration", find the item "Edit / PL/SQL Beautifier", double-click on the empty space, click whatever keys you want to use for the shortcut, then click OK:
You can also enable the PL/SQL Beautifier to run automatically:
But be careful before you become too dependent on the code beautifier. They generally do not work well for Oracle SQL and PL/SQL. PL/SQL has a huge grammar and no code beautifier in existence can handle all types of code well. Also, dynamic code is much more important in PL/SQL than in other languages; beautifiers won't help with dynamic code so you'll likely need to manually format some code anyway.
You must select your query and then click PL/SQL Beautifier button.
For Ver. 12.07 you can click PL/SQL Beautifier button to format sql
Select your code and Use Ctrl-F7 on SQL Developer and PLSQL Developer as well.
If you want to customize PLSQL Beautifier, save your custom file on your PC and then import file and save it as picture below.
The PL/SQL Beautifier allows you to format your SQL and PL/SQL code through a user-defined set of rules. Your code can automatically be beautified when you compile, save, or open a file.
Related
I have to copy some objects from one schema to another on the same database, between others java sources too. The dbms_metadata.get_ddl(object_type, object_name, schema_name) returns schema name in the ddl. Because I want to execute this ddl on the new schema the old schema name in the ddl doesn't help me in my job. To avoid this problem I use a following function a step before:
execute dbms_metadata.set_transform_param(dbms_metadata.session_transform,'EMIT_SCHEMA', false);
In case of a table it works (it means, it omits the schema name in ddl):
select dbms_metadata.get_ddl('TABLE', object_name, schema_name) from dual;
but in case of java source:
select dbms_metadata.get_ddl('JAVA_SOURCE', object_name, schema_name) from dual;
it doesn't!
I've tested these functions on VM with database 12.2 from Oracle too. The same behavior.
Is it a bug? Any workaround?
Regards,
Jacek
The only thing I don't have an automated tool for when working with Oracle is a program that can create INSERT INTO scripts.
I don't desperately need it so I'm not going to spend money on it. I'm just wondering if there is anything out there that can be used to generate INSERT INTO scripts given an existing database without spending lots of money.
I've searched through Oracle with no luck in finding such a feature.
It exists in PL/SQL Developer, but errors for BLOB fields.
Oracle's free SQL Developer will do this:
http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
You just find your table, right-click on it and choose Export Data->Insert
This will give you a file with your insert statements. You can also export the data in SQL Loader format as well.
You can do that in PL/SQL Developer v10.
1. Click on Table that you want to generate script for.
2. Click Export data.
3. Check if table is selected that you want to export data for.
4. Click on SQL inserts tab.
5. Add where clause if you don't need the whole table.
6. Select file where you will find your SQL script.
7. Click export.
Use a SQL function (I'm the author):
https://github.com/teopost/oracle-scripts/blob/master/fn_gen_inserts.sql
Usage:
select fn_gen_inserts('select * from tablename', 'p_new_owner_name', 'p_new_table_name')
from dual;
where:
p_sql – dynamic query which will be used to export metadata rows
p_new_owner_name – owner name which will be used for generated INSERT
p_new_table_name – table name which will be used for generated INSERT
p_sql in this sample is 'select * from tablename'
You can find original source code here:
http://dbaora.com/oracle-generate-rows-as-insert-statements-from-table-view-using-plsql/
Ashish Kumar's script generates individually usable insert statements instead of a SQL block, but supports fewer datatypes.
I have been searching for a solution for this and found it today. Here is how you can do it.
Open Oracle SQL Developer Query Builder
Run the query
Right click on result set and export
http://i.stack.imgur.com/lJp9P.png
You might execute something like this in the database:
select "insert into targettable(field1, field2, ...) values(" || field1 || ", " || field2 || ... || ");"
from targettable;
Something more sophisticated is here.
If you have an empty table the Export method won't work. As a workaround. I used the Table View of Oracle SQL Developer. and clicked on Columns. Sorted by Nullable so NO was on top. And then selected these non nullable values using shift + select for the range.
This allowed me to do one base insert. So that Export could prepare a proper all columns insert.
If you have to load a lot of data into tables on a regular basis, check out SQL Loader or external tables. Should be much faster than individual Inserts.
You can also use MyGeneration (free tool) to write your own sql generated scripts. There is a "insert into" script for SQL Server included in MyGeneration, which can be easily changed to run under Oracle.
i need to interact with an oracle database,i usually use toad but i need to simplify some operations.
i'd like to have forms and buttons to launch custom query
EX
have a button "username" and a button "start" so when i press the button ,the program will do some checks whit ifs and cases and then some insert or update
web page or windows application i don't care as long its "easy" to do
i've tried visual basic but i cant understand how to do updates and inserts
Thank you
AFAIK you can try every language that .NET framework supports (even F#), but most popular way is to use C# with .NET.
There are a lot of books and manual online abut connecting .NET to DB. Also try reading about LINQ.
You may strat by looking on the net if there is an easy code that it could help you on your needs.
You can always try paste some code of your mine here so ppl will help you.
IF you managed to make calls to Oracle from VB or the other languages that you are using, but you are having trouble with specific commands, you could wrap them in PL/SQL procedures or packages.
Here's a simple example:
create or replace procedure updateuser(p_user in varchar2) as
--here you can declare local stored procedure variables and you can already give some starting value if you want
somevariable number := length(p_user) + 1;
someothervariable varchar2(10);
begin
--some useless code just to show you basic usage:
someothervariable := '(' || p_user || ')';
--Your update or insert statement:
UPDATE sometable
SET somecolumn = someothervariable
where username = p_user;
commit;
end;
To call it from your VB, you might need to do something like this: (forgive my poor knowledge of vb, the syntax may be all wrong):
myvbsub "begin updateuser('" + vbuservar + "'); end;"
Hope this helps!
I am a newb to Oracle. I used to use SQL Plus, and use set serveroutput on to see the results. However, when I started using Oracle Developer, my queries would run, however, I was not able to see the console or the results:
select *
from customer;
I assume that you mean "Oracle SQL Developer" application.
If yes, the in SQL Developer click on View option, then select Dbms output
DBMS Output window (panel) should appear somewhere on the screen.
Then, click on green plus sing in the DBMS-Output panel, and select a session you want to spy.
The same query ran in PL/SQL Developer shows time, however it does not show in Oracle SQL Developer. Is there a way to get the time in SQL Developer?
In SQL Developer:
In PL/SQL:
This is the details of the date field:
You can change this in the Tools / Preferences dialog of SQL developer:
Select Database / NLS Parameters in the tree view on the left.
Then put dd/mm/yyyy hh24:mi:ss into the Date Format field.
Press OK to close the dialog.
To make it simple:
use to_char() function, it will work with SQL developer as well as Pl/sql.
select to_char(sysdate,'MM-DD-YYYY HH:Mi:SS') from table_name;
Can't see your query, but in oracle, it would look like this:
select sysdate from dual