Multiple insert into in SQL Developer worksheet - sql

I just installed SQL Developer 4 and I'm using Oracle Database 11g. I want to execute multiple insert into statements in the worksheet at once. That works fine if I copy paste via command line of SQL but in Develop 4, only one row is being inserted at a time. Is there any way to fix this? I don't want to type line by line and also don't want directly enter via data tab though the textboxes. I want be able to execute the following in one single worksheet. Please help
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00001','ivan bayross','bombay',400054,'maharashtra',15000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00002','vandana saitwal','madras',780001,'tamil nadu',0);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00003','pramada jaguste','bombay',400057,'maharashtra',5000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00004','basu navindgi','bombay',400056,'maharashtra',0);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00005','ravi sreedharan','delhi',100001,'delhi',2000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00006','rukmini','bombay',400057,'maharashtra',0);

From the documentation (3.2 since 4 is still beta):
SQL Worksheet toolbar (under the Worksheet tab): Contains icons for the following operations:
Execute Statement executes the statement at the mouse pointer in the
Enter SQL Statement box. The SQL statements can include bind variables
and substitution variables of type VARCHAR2 (although in most cases,
VARCHAR2 is automatically converted internally to NUMBER if
necessary); a pop-up box is displayed for entering variable values.
Run Script executes all statements in the Enter SQL Statement box
using the Script Runner. The SQL statements can include substitution
variables (but not bind variables) of type VARCHAR2 (although in most
cases, VARCHAR2 is automatically converted internally to NUMBER if
necessary); a pop-up box is displayed for entering substitution
variable values.
To run multiple statements together you need to Run Script, either from the toolbar icon or by pressing F5.

After all of the insert statements are in the "Query" Builder window, you can "hilight" (Control A) and then hit "Control" and "Enter" at the same time.

Related

How do I get this SQL statement to write to an empty excel sheet for the rows beyond the first one?

I am attempting to send some data, stored as local variables in an automation tool, to an Excel sheet using OleDB 12. So far, my code (below) is what I've come up with that works to write data successfully to the first line of a templated Excel sheet (headers are already filled out). My problem is every subsequent iteration is not writing data to any line after the first successful (Index 2).
I've tried changing the where clause to work with line index rather than finding empty rows, but that was unsuccessful and returned errors. I've also tried to leverage the 'INSERT INTO' statement, which is also was returning perplexing run-time errors every which way I try to write the statement. Can you not use 'INSERT' with Oledb?
Update statement (semi-successful):
UPDATE [Sheet1$]
SET [SAP_ID] = %SapEmployeeNumber%
WHERE [SAP_ID] IS NULL;
Insert statement (have not gotten to work):
INSERT INTO Sheet1$ (SAP_ID)
VALUES %SapEmployeeNumber%
WHERE [SAP_ID] IS NULL
The expectation is to write data to the first empty row (In other words, the employee number is blank).
First of all: an INSERT statement NEVER has a WHERE clause - check the official MS docs on INSERT.
Secondly: you need to put the values in the VALUES section into parentheses, like this:
INSERT INTO Sheet1$ (SAP_ID)
VALUES (%SapEmployeeNumber%)

inserting a row in Oracle sql using command prompt and by using Apex,but only one row is getting inserted

When I insert a row in command prompt and access it, it is successfully done. But when I see it in Apex it doesn't show any data in table. What is the mistake. And one more thing. When I insert a row by using apex it shows in command prompt also but it doesn't give the result in my JDBC program, it gives only one row.

SQL INSERT sp_cursor Error

I have a pair of linked SQL servers: ServerA and ServerB. I want to write a simple INSERT INTO SELECT statement which will copy a row from ServerA's database to ServerB's database. ServerB's database was copied directly from ServerA's, and so they should have the exact same basic structure (same column names, etc.)
The problem is that when I try to execute the following statement:
INSERT INTO [ServerB].[data_collection].[dbo].[table1]
SELECT * FROM [ServerA].[data_collection].[dbo].[table1]
I get the following error:
Msg 16902, Level 16, State 48, Line 1
sp_cursor: The value of the parameter 'value' is invalid.
On the other hand, if I try to execute the following statement:
INSERT INTO [ServerB].[data_collection].[dbo].[table1] (Time)
SELECT Time FROM [ServerA].[data_collection].[dbo].[table1]
The statement works just fine, and the code is executed as expected. The above statement executes just fine, regardless of which or how many tables I specify to insert.
So my question here is why would my INSERT INTO SELECT statement function properly when I explicitly specify which columns to copy, but not when I tell it to copy everything using "*"? My second question would then be: how do I fix the problem?
Googling around to follow up on my initial hunch, I found a source I consider reliable enough to cite in an answer.
The 'value' parameter specified isn't one of your columns, it is the optional argument to sp_cursor that is called implicitly via your INSERT INTO...SELECT.
From SQL Server Central...
I have an ssis package that needs to populate a sql table with data
from a pipe-delimited text file containing 992 (!) columns per record.
...Initially I'd set up the package to contain a data flow task to use
an ole db destination control where the access mode was set to Table
or view mode. For some reason though, when running the package it
would crash, with an error stating the parameter 'value' was not valid
in the sp_cursor procedure. On setting up a trace in profiler to see
what this control actually does it appears it tries to insert the
records using the sp_cursor procedure. Running the same query in SQL
Server Management Studio gives the same result. After much testing and
pulling of hair out, I've found that by replacing the sp_cursor
statement with an insert statement the record populated fine which
suggests that sp_cursor cannot cope when more than a certain number
of parameters are attempted. Not sure of the figure.
Note the common theme here between your situation and the one cited - a bazillion columns.
That same source offers a workaround as well.
I've managed to get round this problem however by setting the access
mode to be "Table or view - fast load". Viewing the trace again
confirms that SSIS attempts this via a "insert bulk" statement which
loads fine.

Change select statement in SQL from Excel - end user

I have a decent size SQL statement that I have connected to an Excel worksheet and it runs fine. The question I have is would it be possible to have the end user enter a list of values in an excel sheet or somewhere else and have those values added to a WHERE clause in my SQL to limit the results per the users needs without the user having to go into connection and alter the SQL etc.? Thank you.
Yes. I do it as part of a VB script. I'm not a VB expert and I didn't set it up- I just know enough to tweak some changes that the users require.
Conceptually- provide an area in th Excel template for users to enter the parameters, use VB to get the values of those parameters, then pass them to the SQL statement.
You can create a Data Connection in Excel that utilizes a parameter. Whether you are calling a Stored Procedure on the DB or sending raw SQL, you can replace part of the statement with a ?. Tie that parameter to a specific cell. Now all your user needs to do is enter/change the value in that cell and it will re-query the database using that value as the parameter.
(I don't have Excel in front of me, otherwise I'd walk you through the exact steps)

Is there a web site where I can paste a SQL Insert statement and have it break it out by column?

I've been working on an application that has no discernable data access layer, so all the SQL statements are just built up as strings and executed. I'm constantly confronted by very long INSERT statements where I'm trying to figure out what value in the VALUES list matches up with what column in the column name list.
I was about to create a little helper application where I could paste in an INSERT statement and have it show me a list of values matched up with the column names, just for debugging, and I thought, "someone else has probably done this already."
Does anyone know of a web site where I can just paste in an INSERT statement and have it show me a two column table with column names in the first column and values in the second column?
not a website but have you tried either visual studio or Sql Server Management studio. Both of these are able to do this.
You can use SQL Server Management studio or Visual Studio (with Server Explorer) to do that. For SSMS, follow these steps:
On a random table, click "Edit Top 200 Rows"
Open the SQL pane and paste your Insert script.
Open the Criteria Pane, which displays the insert column value pairs.
http://www.dpriver.com/pp/sqlformat.htm
I use Red Gate SQL Prompt for all my re-formatting.
Even though it is unnecessary (and unused), I often use aliases to make it easier to line things up, so instead of:
INSERT INTO tbl
SELECT 2 * y
FROM other_tbl
I usually do:
INSERT INTO tbl (x)
SELECT 2 * y AS x
FROM other_tbl