sqldeveloper exports integer inserts as strings - oracle-sqldeveloper

It seems like a bug in Version 19.4 which is fixed in 20+
I exported the content of my tables in sqldeveloper and the insert sql statements all have number as strings.
Example:
Insert into testtable(id,stuff) values ('1','Hello')
ID 1 becomes '1' in the export and I have trouble reading it in.
This is the case for every table. Is there a way to avoid the two ' ?
The DDL is:
create table TESTTABLE(
ID INTEGER not null
);
after executing its this in sqldeveloepr:
create table testtable{
"ID" Number(*,0) NOT NULL ENABLE
}
I noticed that I'm able to add such a line, if the constraints are not active. It seems like sqldeveloper convertes the string to a number internally.

create table testtable(
"ID" Number(*,0) NOT NULL ENABLE
);
insert into testtable values (1);
commit;
select /*insert*/ * from testtable;
Running this, i get
Table TESTTABLE created.
1 row inserted.
Commit complete.
REM INSERTING into TESTTABLE
SET DEFINE OFF;
Insert into TESTTABLE (ID) values (1);
No quotes on the number value/field. I did this with version 20.2 of SQL Developer.

Related

DB2 Temp Table - Retrieving inserted Data in DB2 Z OS

I have created a temp table and Inserted in DB2 ZOS as mentioned below
CREATE GLOBAL TEMPORARY TABLE tmp2 (col1 INT)
INSERT INTO tmp2 (col1) VALUES (10687);
INSERT INTO tmp2 (col1) VALUES (10689);
INSERT INTO tmp2 (col1) VALUES (10691);
Inserted data with out any issues, where I'm trying to retrieve the data using select query Im unable see any values which I had inserted with the above values and getting.
select * from tmp2
I have an earlier experience in SQL Server and ran the below queries which work without any issues.
Drop table #tmp2
CREATE TABLE #tmp2 (col1 INT)
INSERT INTO #tmp2 (col1) VALUES (10687);
INSERT INTO #tmp2 (col1) VALUES (10689);
INSERT INTO #tmp2 (col1) VALUES (10691);
select * from #tmp2
How to get to see the inserted data?
Check the documentation for details, sometimes this is faster than waiting for an answer.
The CGTT (create global temporary table) object differs from a regular table when a COMMIT happens - it will empty the table if there are no with hold cursors open on the table. If you have autocommit enabled for your database connection then the result will be that your CGTT table may appear to be empty.
If you want more control over the commit behaviour (and rollback behaviour, and logging options etc. ) you can consider using DGTT (declare global temporary table) instead because that syntax lets you use additional non-default options like on commit preserve rows and on rollback preserve rows. But a DGTT object has more restrictions , including that its qualifier must always be SESSION and its definition is not catalogued so the table is invisible to any other session.
Thanks for all replies.
Below is the set of queries, actually I was looking for
DECLARE GLOBAL TEMPORARY TABLE SESSION.tmp2 (col1 INTEGER)
CCSID EBCDIC ON COMMIT PRESERVE ROWS;
INSERT INTO SESSION.tmp2 (col1) VALUES (10687);
INSERT INTO SESSION.tmp2 (col1) VALUES (10689);
INSERT INTO SESSION.tmp2 (col1) VALUES (10691);
select * from SESSION.tmp2;

Insert Into: Returns inserted records

I'm trying to insert some new records into a table and return the inserted records.
DECLARE #newRecords TABLE
(
Id INT NULL,
Col1 VARCHAR(MAX) NOT NULL,
Col2 VARCHAR(MAX) NOT NULL,
ForeignKey VARCHAR(MAX) NOT NULL
)
INSERT INTO #newRecords
SELECT ColA AS Col1, ColB AS Col2, Key AS ForeignKey
FROM SomeTable;
INSERT INTO PrimaryTable(Col1, Col2)
OUTPUT inserted* INTO #newRecords
SELECT Col1, Col2
FROM #newRecords;
The problem is that outputting the inserted records via the OUTPUT statement causes an error because the column ForeignKey does not exist in PrimaryTable. I am worried about outputting the records to a second temp table because I have no good means of joining the data from PrimaryTable to the #newRecords table.
Ideally what I would like to see happen is:
The new records are populated into the #newRecords temp table from SomeOtherTable
The appropriate columns from the #newRecords temp table are then inserted into the PrimaryTable
Finally the primary keys that were assigned to the newly inserted records in the PrimaryTable are updated into the #newRecords.Id column so that I can go on and do some additional record creations
I've tried messing around with the MERGE statement as well as seeing if I could add some additional statements to the OUTPUT statement but either it's not possible or (more likely) I am not using the syntax correctly.
Any ideas would be greatly appreciated.

dashDB: insert into generated default column using select

I have a simple test table
CREATE TABLE TEST (
KEY INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
INTENTS VARCHAR(255),
NO_FOUND SMALLINT );
I am then trying to insert data into this table using the following command from within dashDB's sql dashboard.
Insert into table from (select item1,item2,item3 from TEST2 where some_condition );
However I cannot seem to get the command to not return an error.
Have tried the db2 'DEFAULT', and '0' (default for integer), and even NULL as values for item1.
Have also tried the insert using values, but then the column headings cause the system to report multiple values returned.
Have also tried 'OVERRIDING USER VALUE'
but this then complains about not finding a JOIN element.
Any ideas welcome.
I would try something like this:
Insert into test(intents,no_found)
(select item2,item3 from TEST2 where some_condition );
You specify that only two of the three columns receive values, the KEY column is generated. Hence you only select the two related columns.

Is there a way to quickly duplicate record in T-SQL?

I need to duplicate selected rows with all the fields exactly same except ID ident int which is added automatically by SQL.
What is the best way to duplicate/clone record or records (up to 50)?
Is there any T-SQL functionality in MS SQL 2008 or do I need to select insert in stored procedures ?
The only way to accomplish what you want is by using Insert statements which enumerate every column except the identity column.
You can of course select multiple rows to be duplicated by using a Select statement in your Insert statements. However, I would assume that this will violate your business key (your other unique constraint on the table other than the surrogate key which you have right?) and require some other column to be altered as well.
Insert MyTable( ...
Select ...
From MyTable
Where ....
If it is a pure copy (minus the ID field) then the following will work (replace 'NameOfExistingTable' with the table you want to duplicate the rows from and optionally use the Where clause to limit the data that you wish to duplicate):
SELECT *
INTO #TempImportRowsTable
FROM (
SELECT *
FROM [NameOfExistingTable]
-- WHERE ID = 1
) AS createTable
-- If needed make other alterations to the temp table here
ALTER TABLE #TempImportRowsTable DROP COLUMN Id
INSERT INTO [NameOfExistingTable]
SELECT * FROM #TempImportRowsTable
DROP TABLE #TempImportRowsTable
If you're able to check the duplication condition as rows are inserted, you could put an INSERT trigger on the table. This would allow you to check the columns as they are inserted instead of having to select over the entire table.

Is it possible to write an "insert into" statement for a single column table?

Here's the caveat...
If you have a table that has a single column and that column happens to be an identity column with identity_insert turned OFF, is it still possible to write a T-SQL insert statement for this table?
sure
use insert TableName default values
example
create table Test (id int identity not null)
insert Test default values
select * from Test