temp-tables

Why are temporary tables not removed from tempdb in SQL Server?

佐手、 提交于 2019-12-01 22:14:03
问题 I have created one stored procedure with 7 temporary tables and each temp table is dropped at the end of their own work. I am calling the SP from one web service and same web service we are used for different instance. I have dropped every temp table forcefully but when SP executes it will not delete any of the temporary table which are located in "tempdb/Temporary Table". And, when I open new instance of my application and try to execute same SP it will modify same temp tables. This creates

ORA-14551: cannot perform a DML operation inside a query

喜欢而已 提交于 2019-12-01 21:16:30
I have the following inside a package and it is giving me an error: ORA-14551: cannot perform a DML operation inside a query Code is: DECLARE CURSOR F IS SELECT ROLE_ID FROM ROLE WHERE GROUP = 3 ORDER BY GROUP ASC; BEGIN FOR R IN F LOOP DELETE FROM my_gtt_1; COMMIT; INSERT INTO my_gtt_1 ( USER, role, code, status ) (SELECT trim(r.user), r.role, r.code, MAX(status_id) FROM table1 r, tabl2 c WHERE r.role = R.role AND r.code IS NOT NULL AND c.group = 3 GROUP BY r.user, r.role, r.code); SELECT c.role, c.subgroup, c.subgroup_desc, v_meb_cnt INTO record_type FROM ROLE c WHERE c.group = '3' and R

Alternative for a MySQL temporary table in Oracle

房东的猫 提交于 2019-12-01 20:51:24
I noticed that the concept of temporary tables in these two systems is different, and I have a musing.. I have the following scenario in MySQL: Drop temporary table 'a' if exists Create temporary table 'a' Populate it with data through a stored procedure Use the data in another stored procedure How can I implement the same scenario in Oracle? Can I (in one procedure preferable) create a temporary table, populate it, and insert data in another (non-temporary) table? I think that I can use a (global) temporary table which truncates on commit, and avoid steps 1&2, but I need someone else's

Why are temporary tables not removed from tempdb in SQL Server?

两盒软妹~` 提交于 2019-12-01 20:46:37
I have created one stored procedure with 7 temporary tables and each temp table is dropped at the end of their own work. I am calling the SP from one web service and same web service we are used for different instance. I have dropped every temp table forcefully but when SP executes it will not delete any of the temporary table which are located in "tempdb/Temporary Table". And, when I open new instance of my application and try to execute same SP it will modify same temp tables. This creates problem for me. it will lock the tables when SP execute simultaneously it will lock the table and my sp

Session-global temporary tables in SQL Server

北慕城南 提交于 2019-12-01 12:47:19
In SQL Server, temporary tables with a name like #temp has a local scope. If you create them in your session, everything in your session can see them, but not outside your session. If you create such a table within a stored procedure, the scope is local to that procedure. So when the proc exits, the table vanishes. The only alternative I am aware of, is to use tables with a name like ##temp. These are temporary, but are visible server-wide. So if I create the table in my session, Bob in the office next door will also see them. What I am looking for is somewhere in the middle, so I can create

Creating a cursor on a temp table - is it safe?

北城以北 提交于 2019-12-01 12:29:36
I know that creating and using cursors in SQL is neither safe nor efficient but sometimes it's the only alternative. And right now it is the only alternative I have. My question not how to avoid using cursors but how safe safe and what performance issues I will incur if the cursor is only operating on a temp table created on the fly within a stored procedure. I know cursors run slower than set operations and put a lock on tables that they're iterating. My temp table is a relatively small table containing just one field of type int and max 50 records. DECLARE @pD int DECLARE CurDB CURSOR FOR

Creating a cursor on a temp table - is it safe?

喜夏-厌秋 提交于 2019-12-01 11:15:25
问题 I know that creating and using cursors in SQL is neither safe nor efficient but sometimes it's the only alternative. And right now it is the only alternative I have. My question not how to avoid using cursors but how safe safe and what performance issues I will incur if the cursor is only operating on a temp table created on the fly within a stored procedure. I know cursors run slower than set operations and put a lock on tables that they're iterating. My temp table is a relatively small

Global Temp Tables - SQL Server vs Oracle

喜你入骨 提交于 2019-12-01 06:07:15
I am using Oracle 11g Global Temporary Tables as I need a solution where I can add rows to a temporary table for a join, and I want only the rows added to the temp table for the Oracle Connection/session to be included. I am using Global Temp Table in Oracle becuase I want the table to exist between sessions so it doesn't have to be recreated every time I create a query. This is working out fine. My Oracle table definition is as follows: CREATE GLOBAL TEMPORARY TABLE book_id_temp ( book_id RAW(32) )ON COMMIT DELETE ROWS; I have the same database structure also on the SQL Server 2008-R2 side,

Accessing a temporary table multiple times in MySql

巧了我就是萌 提交于 2019-12-01 05:53:42
I have tried to use a temporary table as an intermediate result holder for a SELECT statement. The problem is though that I can't access the temp table multiple times in other queries statement which I hoped would be possible i.e. makes the temp table useless. Is there an alternative to temporary tables in MySql that allows me to extract my SQL statement. I can't use store procedures (can't access them from the web-framework version used in the company) and I don't want to use a cursor. Edit: Well my code looks somewhat like this: Temp table creation: CREATE TEMPORARY TABLE dates_with_entries

How to convert list of numbers into (temp) table using SQL (SQL Server)

断了今生、忘了曾经 提交于 2019-12-01 05:21:37
Here is an example; I have list of numbers (1,5,8,36) and I want these values as a (temp) table rows. One of the way to do is as follow select 1 as n into ##temp union select 5 as n union select 8 as n union select 36 as n The problem is number list is dynamic . it can have any no of values. So I need a proper systematic way to convert these values into temp table rows. A solution I use alot... Supply your list of numbers as a VARCHAR(MAX) comma delimeted string, then use one of the many dbo.fn_split() functions that people have written on line. One of many examples online... SQL-User-Defined