While entering a SQL statement in Oracle SQL Developer, I noticed that I have two choices. I can either "Run Statement" or "Run Script". A similar choice seems to be available in SQL Maestro as well, although named "Execute query" and "Execute as script".
What exactly is the difference between the two?
Run Statement will give you a list of all the results in a sortable table. It will also only run the statement under the cursor (or highlighted). You will be prompted for bind variables when you run the statement (any place holder with : in front of it).
E.g.
select * from customers where customer_id = :id
will prompt for a value for id
Run Script will execute all statements in the worksheet, and give a text readout of the results. It will not prompt you for the values of bind variables.
I think
"Execute Statement" - mean if you want to get results (resultset)
"Run Script" - is something you need to execute but don't need a results, like installing database dump, or upgrade script to add columns to the table etc.
Related
I have simple SQL Query and need to get the input from parameter. I am getting the when i click parameter button. Please let me know how to get the parameter if i have declare statement in my scripts.
Note :OLEDB connection manager used for connection
You can't use parameters in an OLEDB Source if your command contains DECLARE, or anything other than a single SELECT statement.
The way to do what you want is to use build your entire SQL Command into a single SSIS variable, and use the "SQL Command from variable" option in the OLEDB source.
EDIT based on comments:
If you have to handle a SQL Command over 4000 characters, the only way to do it is in a Script Component. The SQL Command in a script component can be any length. Here is an example.
I am new to PDI/Kettle.I need to execute simple SQL select similar to "SELECT EMPID FROM Employee" and need to write the output to "Microsoft Excel Output" as part of reports generation.
When I write this query in "Execute SQL Statement" step under "SQL Scripts to execute" section in my transformation and execute it , it is returning nothing but transformation got completed without any errors.
No result written in my output file. The same behavior with the step "Execute Row SQL Script" by reading the input from sql file/data grid with query as input.
Transformation flow:
EXECUTE SQL STATEMENTS >> Microsoft Excel Output
EXECUTE SQL
STATEMENTS >> Textfile Output
If I use "Table Input" step and write the query under "SQL" section , it is getting executed and giving the result.
Table Input >> Microsoft Excel Output
Table Input >> Textfile Output
Can anyone help me in understanding this behavior and context/use cases of these steps.
Thank you techies for your knowledge share on this .
As per my understanding ,"Execute SQL statement" step is used to execute SQL statements like DDL, DML but it won't give any result to output stream except number of records impacted/affected(statistics) when we execute DML statements.
To track this statistics, there were optional fields give like insert stats, update stats, delete stats and read stats and based on your DML statement we can give the field name and number of records affected will be written as a value to that field. This can be noticed in "Preview data" under Transformation Execution results.
The Execute SQL Statement does not provide any result. Its purpose is DDL (Data Definition Language) to drop/create/truncate/alter tables, and DML (Data Manipulation Language) insert/update/delete rows.
Two checks (among other) should become a second nature after the coding of every step:
Check the output columns (right click on the step, choose Output fields).
Make a preview of the results (right click on the step, choose Preview).
Let me explain one basic concept of pentaho pdi (kettle): all the actions on kettle happens with a row. If there is no row, there will be no action. So if you add a generate row step at the begining of your transformation, with one dummy row with some value you will see how your sql statement will be triggered.
At a glance pentaho works with this 2 premises:
1 Everything is an asyncronous flow
2 Every action happens at row level. (no row, no action)
an input table step generates rows but an execute sql statement is not a input step type, is a transform step and expects rows generated already before this step.
I think this two basics concepts can help to understand how ketle works.
I am tying to execute multiple select statements at a time in Toad for Oracle to compare two tables and develop some logic but it is throwing some error.
I searched through net and I found suggestions to execute multiple insertstatements by putting them in between begin and end but same thing is not working for select queries.
Finally, what I want is to print two tables by executing two select queries at a time like selecting two select queries and clicking F5 in SQL Server.
You have to write your 2 select statements, with a semicolon in between. Then hit F5 (Execute as script). In the Script Output window, you will have 4 tabs : Output, Errors, Grid1, Grid2. Grid1 and Grid2 are the results of your 2 select statements. Hope this helps.
I got two tables it is very useful when we are writing joins by seeing both table
As far as I can tell, you can't see such an output in a "parallel manner" using one Editor window. Therefore, open two Editors (use the appropriate toolbar button)!
Arrange them (resize, place them side by side or, eventually, one above the other) and run SELECTs one by one. Each output will be in its own "Data Grid" and you'll be able to compare them.
I'm coming from a MS SQL background using SSMS. I just recently started using Oracle / Toad at a new company and I'm finding it to be a bit finicky.
One of the things that I use to do in SSMS was select 2 queries, and then execute the statement and see the results for both.
When I attempt to run the following queries
select count(*) from table1;
select count(*) from table2;
I get the following error message back: ORA-00933: SQL Command not properly ended
Is there something in particular that I'm not doing correct?
In your tool, hit F5, you'll get your results as a script for both queries.
In the free, official GUI for Oracle Database, you can do this:
As Barbaros Özhan notes, you'll need to fix your queries first. You need to do a count() on SOMETHING - * will work.
You need to include some literal like 'x', or a symbol like * or a number 1 inside count function like count(1) or count(*) or count('x').
In your case, one of these missing operators causes ORA-00933.
The answer apparently was the button that I was selecting in Toad for Oracle / slightly incorrect SQL statement.
I was hitting the "Execute / compile statement at caret" button instead of the "Execute Script As" button.
Selecting the wrong button in Toad
3GLs provide mechanisms to prepare statements before executing them. E.g.
SELECT name
FROM people
WHERE age=:AGE
The same query can then be executed for different ages. But can such a statement also be prepared in a "plain" Oracle SQL client? Can the same be done in e.g. SQL Plus or dbForge Studio for Oracle as in Java or C# or any other programming language that supports prepared statements?
In dbForge Studio for Oracle, named parameters can be used, preceded by a colon :
SELECT *
FROM people
WHERE name=:name
The parameters can then be filled in with the "Edit parameters dialog box", available from the SQL toolbar.
I know you didn't ask about PostgreSQL but about Oracle. However, of note, PostgreSQL has this feature right in its SQL language.
The SQL standard includes a PREPARE statement, but it is only for use in embedded SQL. The PostgreSQL version of the PREPARE statement works like this:
PREPARE nameByAge(number) AS
SELECT name
FROM People
WHERE age=$1;
and you use it like this:
EXECUTE nameByAge(18);
EXECUTE nameByAge(50);
So unfortunately for Oracle SQLPlus the answer seems to be no, not bind variables. But SQLPlus has substitution variables, similar to shell scripts. You use them as &1, &2, &3, ... and they get their parameters from the way you call the SQLPlus script.
sqlplus user/password #script.sql 18
sqlplus user/password #script.sql 50
with the script.sql being
SELECT name
FROM People
WHERE age=&1;
this would work, even though it is not bind. But then, do you really care about the slight savings in repeat parse time? In fact Oracle hashes SQL statements and already replaces constants with bind variables to be able to better reuse query plans. So the savings you would get with PREPARE and BIND are really minuscule.