Sybase has the ability to make an insertion multi rows? If yes, what version is available? If not, has plans to develop? asked 07 Oct '12, 20:53 LGregianin |
CREATE TABLE IF NOT EXISTS TEST( EMP char(3) NOT NULL, COD integer NOT NULL, DESCR char(60) NULL, PRIMARY KEY (EMP, COD) ); INSERT INTO TEST VALUES ('001',1,'TEST 1'), ('001',2,'TEST 2'), ('001',3,'TEST 3'); ('001',4,'TEST 4'), ('001',5,'TEST 5'), ('001',6,'TEST 6'); ('001',7,'TEST 7'), ('001',8,'TEST 8'), ('001',9,'TEST 9'); Thanks a lot. answered 08 Oct '12, 14:41 LGregianin |
Do you mean a VALUES clause on an INSERT statement that permits multiple rows? Something like this: INSERT INTO T VALUES( (col1_value, col2_value), (col1_value, col2_value), ... ) This is supported in version 12 - I cannot recall whether or not this shipped in 12.0.0 or 12.0.0. See the documentation at dcx.sybase.com. If you are thinking of another construction (ie. multi-row inserts thru JDBC or ODBC), these are also supported and have been for some time. answered 07 Oct '12, 21:42 Glenn Paulley 2
FWIW, this enhancement has been introduced with v12.0.0, cf. this page:
(08 Oct '12, 03:23)
Volker Barth
|
The multiple values option in 12.0.0 is great; but if you have an old version or want to do some SQL substitutions related to a fixed set of data in your Stored Procedure, try using OpenXML. I do the following when building up a set of error messages that I want to hardcode (for maintenance reasons) into the code and that have to be translated using tables in system: create table #E (idSituationCUR unsigned integer, txMessage char(150), idSeqRead integer default 0); -- using openxml to simplify the load and set a default value should the Join with CodelistTranslation -- fail to find a corresponding entry insert into #E (idSituationCUR, txMessage) select LOAD.idSituationCUR, isnull(CLT.txOther,LOAD.txOther) from OPENXML( string ('<a>', '<b c1="6201" c2="REF" c3="',@kSituation_APPENDED,'"/>', '<b c1="6202" c2="CODE USED BY 2+ ITEMS, FIX ONLINE ONLY" c3="',@kSituation_MULTICDs,'"/>', '<b c1="6203" c2="UNKNOWN/CAN ADD" c3="',@kSituation_NOTFOUND,'"/>', '</a>'), 'a/b' ) with ( idKey integer '@c1', txOther text '@c2', idSituationCUR unsigned integer '@c3') AS LOAD left outer join BOS.CodelistLanguage CLT on CLT.idCodelist = 238 and CLT.idLanguage = @idLanguage and CLT.idKey = LOAD.idKey;
permanent link
This answer is marked "community wiki".
answered 09 Oct '12, 02:56 Eric Hofer |
For older versions ( e.g. 10 ), this seems to work: INSERT INTO T ( "col1", "col2" ) ( ( SELECT '12', '34' FROM T2 ) UNION ( SELECT '56', '78' FROM T2 ) ) greg answered 16 May '16, 19:59 Gregory Durniak Yes, this is a simple INSERT...SELECT and will work even with very very old SQL Anywhere versions... - note, you can omit the brackets around the SELECT statement and omit the (dummy) table name, such as CREATE TABLE T (col1 VARCHAR(10), col2 VARCHAR(10)); INSERT INTO T (col1, col2) SELECT '12', '34' UNION SELECT '56', '78'; (I'm note sure whether the OP was asking for that...)
(17 May '16, 02:56)
Volker Barth
Replies hidden
With this method, Is there a limit on the number of rows inserted ? greg
(17 May '16, 20:41)
Gregory Durniak
I don't think there is an explicit limit on the number of rows aka the number of times you can use the UNION operator to combine query blocks... (or it would be same as the (huge) maximum number of rows per table, so it would not matter how you try to insert them). - I would guess that the overall length of the resulting statement might have its limits, possibly dependent of the API used, but then again that would hold for the INSERT ... VALUES (...), (...) statement, too. - Usually the particular hardware (memory, CPU, disk drives) will have a more limitating effect. IMHO, when trying to insert big amounts of data that is not already contained in another table (possibly of another database) and thus prevents the use of a simple INSERT SELECT statement, I would not use INSERT with multple values but would prefer LOAD TABLE or SELECT ... FROM OPENSTRING()/OPENXML() or the like.
(18 May '16, 00:59)
Volker Barth
|
For older versions without the repeating values enhancement or where you might be doing a translation substitution, the following works.. create table #E (idSituationCUR unsigned integer, txMessage char(150), idSeqRead integer default 0);
permanent link
This answer is marked "community wiki".
answered 09 Oct '12, 02:50 Eric Hofer Reimer Pods |
Such a pity that "open database documentation" like this page doesn't list the great features of SQL Anywhere... sometimes the "invisible database" is way too invisible to get its deserved audience:(