sqlanywhere http://www.e-learn.cn/tag/sqlanywhere zh-hans Sybase: Stored Procedure called from within another Stored Procedure is too slow http://www.e-learn.cn/topic/3306970 <span>Sybase: Stored Procedure called from within another Stored Procedure is too slow</span> <span><span lang="" about="/user/169" typeof="schema:Person" property="schema:name" datatype="">亡梦爱人</span></span> <span>2020-01-25 08:10:10</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm writing a stored procedure for a Sybase database. I'm using Sybase Central 16.0 as my development environment. The machine I'm using runs Microsoft Windows Server 2012 R2 Standard and has 16GB RAM running on a 2.8GHz CPU.</p> <p>My stored procedure uses a cursor to iterate over the records in a table with about 400,000 reecords.  Each record is written incrementally into a <code>LONG VARCHAR</code> variable and every Nth record the proc will run an MD5 hash value on the variable and store the value in a separate table.</p> <pre><code>TABLE_NAME, DATE_TIME_RAN, FROM_RECORD, TO_RECORD, HASH_VALUE </code></pre> <p>If I run only the stored procedure to hash this table as a SQL block in SQL Anywhere (e.g.: <code>BEGIN ... &lt;hash the table here&gt; ... END;</code>) it goes through all records and completes successfully in about two minutes.  However if I run this stored procedure as an embedded command in another stored procedure (e.g.: <code>CALL &lt;MY_SCHEMA&gt;.&lt;MY_STORED_PROCEDURE&gt;</code>) then it never completes.</p> <p>Why would running the stored procedure (on the same dataset) from within another stored procedure perform differently?</p> <br /><h3>回答1:</h3><br /><p>Managed to find a much better solution to the issue without trawling through the table. I thought I'd post the solution here for anyone who might face a similar issue.</p> <p>The requirement for the stored procedure was to loop through a large table one row at a time, concatenating the contents of every column in the row into a string and assigning this to a variable. Every N rows this variable's value would be written to a separate table. Previously I had been using a cursor to do this but a developer on our team discovered a much faster way using the WITH clause.</p> <pre><code>INSERT INTO &lt;MY_SCHEMA&gt;.&lt;MY_TABLE_THAT_WILL_CONTAIN_THE_CONCATENATED_VALUES_OF_EVERY_N_ROWS&gt; WITH CONCATENATE_ROWS AS ( SELECT RANK() OVER (ORDER BY &lt;PRIMARY_KEY_COLUMN&gt;) AS ROWID, &lt;PRIMARY_KEY_COLUMN&gt;, &lt;COLUMN_1&gt; || '' || &lt;COLUMN_2&gt; || '' || ... &lt;COLUMN_N&gt; AS ROW_DETAIL FROM &lt;MY_TABLE_THAT_I_AM_QUERYING&gt; ORDER BY &lt;PRIMARY_KEY_COLUMN&gt; ), GROUPED_ROWS AS ( SELECT (((CONCATENATE_ROWS.ROWID-1)/ &lt;number of rows I want to concatenate, e.g.: 10&gt;)+1) AS GROUPID, CAST(LIST(CONCATENATE_ROWS.ROW_DETAIL, '' ORDER BY &lt;PRIMARY_KEY_COLUMN&gt;) AS VARCHAR(4000)) AS CONCAT_DETAILS FROM CONCATENATE_ROWS GROUP BY (((CONCAT_ORDERS.ROWID-1)/ &lt;number of rows I want to concatenate, e.g.: 10&gt;)+1) ) SELECT &lt;Whatever columns I want to insert into &lt;MY_TABLE_THAT_WILL_CONTAIN_THE_CONCATENATED_VALUES_OF_EVERY_N_ROWS&gt;&gt; FROM GROUPED_ROWS; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/54215723/sybase-stored-procedure-called-from-within-another-stored-procedure-is-too-slow</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/stored-procedures" hreflang="zh-hans">stored-procedures</a></div> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> <div class="field--item"><a href="/tag/sqlperformance" hreflang="zh-hans">sqlperformance</a></div> </div> </div> Sat, 25 Jan 2020 00:10:10 +0000 亡梦爱人 3306970 at http://www.e-learn.cn Cannot open Interactive sql from command prompt http://www.e-learn.cn/topic/3228090 <span>Cannot open Interactive sql from command prompt</span> <span><span lang="" about="/user/200" typeof="schema:Person" property="schema:name" datatype="">余生长醉</span></span> <span>2020-01-15 11:23:48</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have added my own procedure to run as soon as user logs, using </p> <p>SET OPTION PUBLIC.post_login_procedure = 'xxx.Myprocedure';</p> <p>I need to set custom message on pop up this provides when user logs in. The pop up is working, when I manually login in from Sybase central. however, when I run dbisql -c "DSN=myDSN" from command prompt Interactive sql opens and I get the popup that stays on forever! </p> <p>I cannot post images yet but I can send u one, it says "Connecting to database.."</p> <p>I get this pop up only when I have set the popup to appear through post_login_procedure , If i remove that then I can connect to interactive sql without any problem.</p> <p>Please help, Thanks</p> <p>来源:<code>https://stackoverflow.com/questions/25897338/cannot-open-interactive-sql-from-command-prompt</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Wed, 15 Jan 2020 03:23:48 +0000 余生长醉 3228090 at http://www.e-learn.cn Cannot open Interactive sql from command prompt http://www.e-learn.cn/topic/3228084 <span>Cannot open Interactive sql from command prompt</span> <span><span lang="" about="/user/120" typeof="schema:Person" property="schema:name" datatype="">て烟熏妆下的殇ゞ</span></span> <span>2020-01-15 11:23:29</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have added my own procedure to run as soon as user logs, using </p> <p>SET OPTION PUBLIC.post_login_procedure = 'xxx.Myprocedure';</p> <p>I need to set custom message on pop up this provides when user logs in. The pop up is working, when I manually login in from Sybase central. however, when I run dbisql -c "DSN=myDSN" from command prompt Interactive sql opens and I get the popup that stays on forever! </p> <p>I cannot post images yet but I can send u one, it says "Connecting to database.."</p> <p>I get this pop up only when I have set the popup to appear through post_login_procedure , If i remove that then I can connect to interactive sql without any problem.</p> <p>Please help, Thanks</p> <p>来源:<code>https://stackoverflow.com/questions/25897338/cannot-open-interactive-sql-from-command-prompt</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Wed, 15 Jan 2020 03:23:29 +0000 て烟熏妆下的殇ゞ 3228084 at http://www.e-learn.cn Cannot open Interactive sql from command prompt http://www.e-learn.cn/topic/3228078 <span>Cannot open Interactive sql from command prompt</span> <span><span lang="" about="/user/180" typeof="schema:Person" property="schema:name" datatype="">孤者浪人</span></span> <span>2020-01-15 11:23:11</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have added my own procedure to run as soon as user logs, using </p> <p>SET OPTION PUBLIC.post_login_procedure = 'xxx.Myprocedure';</p> <p>I need to set custom message on pop up this provides when user logs in. The pop up is working, when I manually login in from Sybase central. however, when I run dbisql -c "DSN=myDSN" from command prompt Interactive sql opens and I get the popup that stays on forever! </p> <p>I cannot post images yet but I can send u one, it says "Connecting to database.."</p> <p>I get this pop up only when I have set the popup to appear through post_login_procedure , If i remove that then I can connect to interactive sql without any problem.</p> <p>Please help, Thanks</p> <p>来源:<code>https://stackoverflow.com/questions/25897338/cannot-open-interactive-sql-from-command-prompt</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Wed, 15 Jan 2020 03:23:11 +0000 孤者浪人 3228078 at http://www.e-learn.cn SQL Anywhere v10 Syntax error near OUTPUT http://www.e-learn.cn/topic/3226474 <span>SQL Anywhere v10 Syntax error near OUTPUT</span> <span><span lang="" about="/user/105" typeof="schema:Person" property="schema:name" datatype="">岁酱吖の</span></span> <span>2020-01-15 09:48:13</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm attempting to output a table to an outside file. I've found a few questions regarding this and followed the answers from there without any luck.</p> <p><code>SELECT * FROM transactions; OUTPUT TO 'C:\Users\administrator\Desktop\Test.txt'</code></p> <p>Is the statement I've been using, I've attempted different variations with formatting and file types such as .csv with no change.</p> <p>Which produces: </p> <p>ErrorCode : 102 SQLState : 42W04 Message : SQL Anywhere Error -131: Syntax error near 'OUTPUT' on line 1</p> <p>SQL = </p> <p>OUTPUT TO 'C:\Users\administrator\Desktop\Test.txt'</p> <p>Appreciate all your help</p> <br /><h3>回答1:</h3><br /><p>Are you running this through dbisql, or in a different application? <code>OUTPUT TO</code> is a dbisql command, not a SQL statement recognized by the database server. You can use the UNLOAD statement in any application to allow the server to create the file. </p> <p><em>Disclaimer: I work for SAP in SQL Anywhere engineering.</em></p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/33677756/sql-anywhere-v10-syntax-error-near-output</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Wed, 15 Jan 2020 01:48:13 +0000 岁酱吖の 3226474 at http://www.e-learn.cn How to delete duplicate rows in sybase, when you have no unique key? http://www.e-learn.cn/topic/3220782 <span>How to delete duplicate rows in sybase, when you have no unique key?</span> <span><span lang="" about="/user/125" typeof="schema:Person" property="schema:name" datatype="">僤鯓⒐⒋嵵緔</span></span> <span>2020-01-15 03:35:06</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Yes, you can find similar questions numerous times, but: the most elegant solutions posted here, work for SQL Server, but not for Sybase (in my case Sybase Anywhere 11). I have even found some Sybase-related questions marked as duplicates for SQL Server questions, which doesn't help.</p> <p>One example for solutions I liked, but didn't work, is the <code>WITH ... DELETE ...</code> construct.</p> <p>I have found working solutions using cursors or while-loops, but I hope it is possible without loops.</p> <p>I hope for a nice, simple and fast query, just deleting all but one exact duplicate.</p> <p>Here a little framework for testing:</p> <pre><code>IF OBJECT_ID( 'tempdb..#TestTable' ) IS NOT NULL DROP TABLE #TestTable; CREATE TABLE #TestTable (Column1 varchar(1), Column2 int); INSERT INTO #TestTable VALUES ('A', 1); INSERT INTO #TestTable VALUES ('A', 1); -- duplicate INSERT INTO #TestTable VALUES ('A', 1); -- duplicate INSERT INTO #TestTable VALUES ('A', 2); INSERT INTO #TestTable VALUES ('B', 1); INSERT INTO #TestTable VALUES ('B', 2); INSERT INTO #TestTable VALUES ('B', 2); -- duplicate INSERT INTO #TestTable VALUES ('C', 1); INSERT INTO #TestTable VALUES ('C', 2); SELECT * FROM #TestTable ORDER BY Column1,Column2; DELETE &lt;your solution here&gt; SELECT * FROM #TestTable ORDER BY Column1,Column2; </code></pre> <br /><h3>回答1:</h3><br /><p>If all fields are identical, you can just do this:</p> <pre><code>select distinct * into #temp_table from table_with_duplicates delete table_with_duplicates insert into table_with_duplicates select * from #temp_table </code></pre> <p>If all fields are not identical, for example, if you have an id that is different, then you'll need to list all the fields in the select statement, and hard code a value in the id to make it identical, if that is a field you don't care about. For example:</p> <pre><code>insert #temp_table field1, field2, id select (field1, field2, 999) from table_with_duplicates </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>This works well and fast:</p> <pre><code>DELETE FROM #TestTable WHERE ROWID(#TestTable) IN ( SELECT rowid FROM ( SELECT ROWID(#TestTable) rowid, ROW_NUMBER() OVER(PARTITION BY Column1,Column2 ORDER BY Column1,Column2) rownum FROM #TestTable ) sub WHERE rownum &gt; 1 ); </code></pre> <p>If you don't know <code>OVER(PARTITION BY ...)</code>, just execute the inner <code>SELECT</code> statement to see what it does.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Here is another interesting one I found and adopted:</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes, #TestTable fullTable WHERE dupes.Column1 = fullTable.Column1 AND dupes.Column2 = fullTable.Column2 AND ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>or, if you like explicit joins more (I do):</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes INNER JOIN #TestTable fullTable ON dupes.Column1 = fullTable.Column1 AND dupes.Column2 = fullTable.Column2 AND ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>or the short form (a "natural" join incorporates identical column names automatically):</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes NATURAL JOIN #TestTable fullTable ON ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>...if someone finds a solution not requiring <code>ROWID()</code>, I would be interested to see them.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>Please try this:</p> <pre><code>create clustered index i1 on table table_name(column_name) with ignore_dup_row </code></pre> <p></p><p></p> <pre><code>create table #test(id int,name char(9)) insert into #test values(1,"A") insert into #test values(1,"A") create clustered index i1 on #test(id) with ignore_dup_row select * from #test </code></pre> <br /><br /><br /><h3>回答5:</h3><br /><p>Ok, now that I know the <code>ROWID()</code> function, solutions for tables with primary key (PK) can be easily adopted. This one first selects all rows to keep and then deletes the remaining ones:</p> <pre><code>DELETE FROM #TestTable FROM #TestTable LEFT OUTER JOIN ( SELECT MIN(ROWID(#TestTable)) rowid FROM #TestTable GROUP BY Column1, Column2 ) AS KeepRows ON ROWID(#TestTable) = KeepRows.rowid WHERE KeepRows.rowid IS NULL; </code></pre> <p>...or how about this shorter variant? I like!</p> <pre><code>DELETE FROM #TestTable WHERE ROWID(#TestTable) NOT IN ( SELECT MIN(ROWID(#TestTable)) FROM #TestTable GROUP BY Column1, Column2 ); </code></pre> <p>In this post, which inspired me most, is a comment that <code>NOT IN</code> might be slower. But that's for SQL server, and sometimes elegance is more important :) - I also think it all depends on good indexes.</p> <p>Anyway, usually it is bad design, to have tables without a PK. You should at least add an "autoinc" ID, and if you do, you can use that ID instead of the <code>ROWID()</code> function, which is a non-standard extension by Sybase (some others have it, too).</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/19544489/how-to-delete-duplicate-rows-in-sybase-when-you-have-no-unique-key</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/duplicate-removal" hreflang="zh-hans">duplicate-removal</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Tue, 14 Jan 2020 19:35:06 +0000 僤鯓⒐⒋嵵緔 3220782 at http://www.e-learn.cn How to delete duplicate rows in sybase, when you have no unique key? http://www.e-learn.cn/topic/3220781 <span>How to delete duplicate rows in sybase, when you have no unique key?</span> <span><span lang="" about="/user/154" typeof="schema:Person" property="schema:name" datatype="">主宰稳场</span></span> <span>2020-01-15 03:35:06</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Yes, you can find similar questions numerous times, but: the most elegant solutions posted here, work for SQL Server, but not for Sybase (in my case Sybase Anywhere 11). I have even found some Sybase-related questions marked as duplicates for SQL Server questions, which doesn't help.</p> <p>One example for solutions I liked, but didn't work, is the <code>WITH ... DELETE ...</code> construct.</p> <p>I have found working solutions using cursors or while-loops, but I hope it is possible without loops.</p> <p>I hope for a nice, simple and fast query, just deleting all but one exact duplicate.</p> <p>Here a little framework for testing:</p> <pre><code>IF OBJECT_ID( 'tempdb..#TestTable' ) IS NOT NULL DROP TABLE #TestTable; CREATE TABLE #TestTable (Column1 varchar(1), Column2 int); INSERT INTO #TestTable VALUES ('A', 1); INSERT INTO #TestTable VALUES ('A', 1); -- duplicate INSERT INTO #TestTable VALUES ('A', 1); -- duplicate INSERT INTO #TestTable VALUES ('A', 2); INSERT INTO #TestTable VALUES ('B', 1); INSERT INTO #TestTable VALUES ('B', 2); INSERT INTO #TestTable VALUES ('B', 2); -- duplicate INSERT INTO #TestTable VALUES ('C', 1); INSERT INTO #TestTable VALUES ('C', 2); SELECT * FROM #TestTable ORDER BY Column1,Column2; DELETE &lt;your solution here&gt; SELECT * FROM #TestTable ORDER BY Column1,Column2; </code></pre> <br /><h3>回答1:</h3><br /><p>If all fields are identical, you can just do this:</p> <pre><code>select distinct * into #temp_table from table_with_duplicates delete table_with_duplicates insert into table_with_duplicates select * from #temp_table </code></pre> <p>If all fields are not identical, for example, if you have an id that is different, then you'll need to list all the fields in the select statement, and hard code a value in the id to make it identical, if that is a field you don't care about. For example:</p> <pre><code>insert #temp_table field1, field2, id select (field1, field2, 999) from table_with_duplicates </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>This works well and fast:</p> <pre><code>DELETE FROM #TestTable WHERE ROWID(#TestTable) IN ( SELECT rowid FROM ( SELECT ROWID(#TestTable) rowid, ROW_NUMBER() OVER(PARTITION BY Column1,Column2 ORDER BY Column1,Column2) rownum FROM #TestTable ) sub WHERE rownum &gt; 1 ); </code></pre> <p>If you don't know <code>OVER(PARTITION BY ...)</code>, just execute the inner <code>SELECT</code> statement to see what it does.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Here is another interesting one I found and adopted:</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes, #TestTable fullTable WHERE dupes.Column1 = fullTable.Column1 AND dupes.Column2 = fullTable.Column2 AND ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>or, if you like explicit joins more (I do):</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes INNER JOIN #TestTable fullTable ON dupes.Column1 = fullTable.Column1 AND dupes.Column2 = fullTable.Column2 AND ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>or the short form (a "natural" join incorporates identical column names automatically):</p> <pre><code>DELETE FROM #TestTable dupes FROM #TestTable dupes NATURAL JOIN #TestTable fullTable ON ROWID(dupes) &gt; ROWID(fullTable); </code></pre> <p>...if someone finds a solution not requiring <code>ROWID()</code>, I would be interested to see them.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>Please try this:</p> <pre><code>create clustered index i1 on table table_name(column_name) with ignore_dup_row </code></pre> <p></p><p></p> <pre><code>create table #test(id int,name char(9)) insert into #test values(1,"A") insert into #test values(1,"A") create clustered index i1 on #test(id) with ignore_dup_row select * from #test </code></pre> <br /><br /><br /><h3>回答5:</h3><br /><p>Ok, now that I know the <code>ROWID()</code> function, solutions for tables with primary key (PK) can be easily adopted. This one first selects all rows to keep and then deletes the remaining ones:</p> <pre><code>DELETE FROM #TestTable FROM #TestTable LEFT OUTER JOIN ( SELECT MIN(ROWID(#TestTable)) rowid FROM #TestTable GROUP BY Column1, Column2 ) AS KeepRows ON ROWID(#TestTable) = KeepRows.rowid WHERE KeepRows.rowid IS NULL; </code></pre> <p>...or how about this shorter variant? I like!</p> <pre><code>DELETE FROM #TestTable WHERE ROWID(#TestTable) NOT IN ( SELECT MIN(ROWID(#TestTable)) FROM #TestTable GROUP BY Column1, Column2 ); </code></pre> <p>In this post, which inspired me most, is a comment that <code>NOT IN</code> might be slower. But that's for SQL server, and sometimes elegance is more important :) - I also think it all depends on good indexes.</p> <p>Anyway, usually it is bad design, to have tables without a PK. You should at least add an "autoinc" ID, and if you do, you can use that ID instead of the <code>ROWID()</code> function, which is a non-standard extension by Sybase (some others have it, too).</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/19544489/how-to-delete-duplicate-rows-in-sybase-when-you-have-no-unique-key</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/duplicate-removal" hreflang="zh-hans">duplicate-removal</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Tue, 14 Jan 2020 19:35:06 +0000 主宰稳场 3220781 at http://www.e-learn.cn correlation name not found on SQL Anywhere http://www.e-learn.cn/topic/3181450 <span>correlation name not found on SQL Anywhere</span> <span><span lang="" about="/user/39" typeof="schema:Person" property="schema:name" datatype=""> ̄綄美尐妖づ</span></span> <span>2020-01-11 13:14:08</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have two tables called <em>Employees</em> and <em>Salarygroup</em>. PersonalID is the primary key of <em>Employees</em> and <em>SalaryID</em> is the primary key of Salarygroup. Inside the Employees table there is one more row called <em>StartDat</em>, which has date data type and tracks down the date when the employee started working at the company. Moreover, <em>AmountInEuros</em> is the salary that an employee gets every month and it has a numeric data type</p> <p>I need to make a function, which count the total amount of money, that the employee has recieved so far from the company, but when I input the PersonalID I get an error saying *Correlation name 'Salarygroup' not found.</p> <p>Could someone helo me understand why this is happening?</p> <pre><code> ALTER FUNCTION "dba"."countTotalAmountOfMoney"(@PersonalID int) RETURNS int AS BEGIN DECLARE @totalAmountOfMoney int; SELECT @totalAmountOfMoney = g.AmountInEuros * DATEDIFF(month, g.StartDat, '2019-01-16') FROM dba.Employees Inner Join dba.Salarygroup s ON dba.Employees.SalaryId = dba.Salarygroup.SalaryId RETURN @totalAmountOfMoney; END </code></pre> <br /><h3>回答1:</h3><br /><p>You have given the table an alias, so you need to use it. I would recommend using aliases for all the tables:</p> <pre><code>DECLARE @totalAmountOfMoney int; SELECT @totalAmountOfMoney = s.AmountInEuros * DATEDIFF(month, e.StartDat, '2019-01-16') FROM dba.Employees e INNER JOIN dba.Salarygroup s ON e.SalaryId = s.SalaryId WHERE e.personalID = @PersonalID; </code></pre> <p>Note that the <code>g</code> alias is not defined in your query. <code>StartDat</code> comes from <code>Employees</code>, so I changed that to <code>e</code>. I am guessing that <code>AmountInEuros</code> comes from <code>s</code>.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Maybe you forgotten to refer the second table using the Alias 's' you created:</p> <pre><code>ALTER FUNCTION "dba"."countTotalAmountOfMoney"(@PersonalID int) RETURNS int AS BEGIN DECLARE @totalAmountOfMoney int; SELECT @totalAmountOfMoney = g.AmountInEuros * DATEDIFF(month, g.StartDat, '2019-01-16') FROM dba.Employees Inner Join dba.Salarygroup s ON dba.Employees.SalaryId = s.SalaryId RETURN @totalAmountOfMoney; END </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/54199732/correlation-name-not-found-on-sql-anywhere</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/tsql" hreflang="zh-hans">tsql</a></div> <div class="field--item"><a href="/tag/sql-function" hreflang="zh-hans">sql-function</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Sat, 11 Jan 2020 05:14:08 +0000  ̄綄美尐妖づ 3181450 at http://www.e-learn.cn Sybase database password “recovery” http://www.e-learn.cn/topic/3100609 <span>Sybase database password “recovery”</span> <span><span lang="" about="/user/29" typeof="schema:Person" property="schema:name" datatype="">穿精又带淫゛_</span></span> <span>2020-01-04 17:29:27</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have DBA authority to a sybase database on Windows.</p> <p>I have a another user that I don't know the password for.</p> <p>I regularly use an application that <em>does</em> know the password, and it uses the password to automatically login to the application. However, I can't find a way to find that password anywhere in the application or its dlls/files/registry/etc.</p> <p>I obviously don't want to just change the password of the user, as the password in the application can't be updated (that i know of).</p> <p>I want to be able to login to the database as this user.</p> <p>Are there any logging settings for the database server that will log the password in plaintext? Or any other methods I can use to obtain the password (maybe via login_procedure)? <strong>I'd also be okay with just obtaining the hash for the password(+salt).</strong></p> <br /><h3>回答1:</h3><br /><p>There is no SAP Sybase supported way to get the password in plaintext. You can view the hashed password by querying <code>master..syslogins.passwords</code> column.</p> <p>A possible workaround would be to create a new user, and alias them to user in question inside the database. </p> <p><code>sp_addalias</code> is the command you would use to do something like that. </p> <p>You can view the hashed password </p> <br /><br /><br /><h3>回答2:</h3><br /><p>You can't get the plaintext password as it's not logged anywhere and we don't store it. What's stored in the ISYSUSER system table is the SHA-256 <em>hash</em> of the password, and so it is not possible to get the password from it. (And it's not the hash of just the password - it includes a random salt.)</p> <p>However, if you have DBA authority, you can do anything in the database anyway. If you <em>need</em> to be connected as that particular user, you can connect as the user with DBA authority and then use the SETUSER statement.</p> <p><em>Disclaimer: I work for SAP in SQL Anywhere engineering.</em></p> <br /><br /><br /><h3>回答3:</h3><br /><p>Another option might be to decompile the application program and look for the password. I don't know who in their right mind would hard code a password into program code, but it kind of sounds like that is what happened here? Alternatively, if it is an internally-developed app, do you have access to the source code?</p> <p>If that <em>is</em> what happened, and you have the ability to recompile the app, use the keyring (Mac, Linux) or DPAPI (Windows) to securely (as much as possible) store an encrypted instance of the password outside the application code. You'll be able to change it, and some random person who manages to hack in and get access to the source code or binary won't be able to inspect the program like I'm suggesting you try.</p> <p>I also realize this is an old post and you've either solved the problem or moved on by now. ;-)</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/21101024/sybase-database-password-recovery</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/passwords" hreflang="zh-hans">passwords</a></div> <div class="field--item"><a href="/tag/sybase" hreflang="zh-hans">sybase</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> <div class="field--item"><a href="/tag/password-recovery" hreflang="zh-hans">password-recovery</a></div> </div> </div> Sat, 04 Jan 2020 09:29:27 +0000 穿精又带淫゛_ 3100609 at http://www.e-learn.cn Python list of ints in prepared sql statement http://www.e-learn.cn/topic/3013546 <span>Python list of ints in prepared sql statement</span> <span><span lang="" about="/user/45" typeof="schema:Person" property="schema:name" datatype="">妖精的绣舞</span></span> <span>2019-12-30 22:52:34</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>My question is somewhat the same as Python list of String to SQL IN parameter but I have a list of integers. The python code I use is:</p> <pre><code>ids = [1000032, 1000048] sql = 'SELECT CompNo, CompName, CompType FROM Component WHERE DeptID IN (?)' cursor.execute(sql, [','.join(ids)]) </code></pre> <p>And the Sybase database engine responds with:</p> <pre><code>pyodbc.Error: ('07006', "[07006] [Sybase][ODBC Driver][SQL Anywhere]Cannot convert '1000032','1000048' to a numeric (-157) (SQLExecDirectW)") </code></pre> <p>What is the correct way to do this?</p> <br /><h3>回答1:</h3><br /><p>IMO a more readable way to build a dynamic query string with placeholders using str.format</p> <pre><code>ids = [1000032, 1000048] sql = 'SELECT CompNo, CompName, CompType FROM Component WHERE DeptID IN ({0})' sql = sql.format(','.join('?' * len(ids))) cursor.execute(sql, (ids,)) ... </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>You cannot provide the IN-list as one argument. You need to provide the exact number of place holders in the SQL IN clause, and then provide the array to the <em>execute</em> method:</p> <pre><code>ids = [1000032, 1000048] sql = 'SELECT CompNo, CompName, CompType FROM Component WHERE DeptID IN (' \ + (',?' * len(ids))[1:] + ')' cursor.execute(sql, ids) </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>you should cast the array of int to array of strings:</p> <pre><code>",".join(map(str,ids)) </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/35061730/python-list-of-ints-in-prepared-sql-statement</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/pyodbc" hreflang="zh-hans">pyodbc</a></div> <div class="field--item"><a href="/tag/sqlanywhere" hreflang="zh-hans">sqlanywhere</a></div> </div> </div> Mon, 30 Dec 2019 14:52:34 +0000 妖精的绣舞 3013546 at http://www.e-learn.cn