temp-tables

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

霸气de小男生 提交于 2019-12-31 01:52:16
问题 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

Session-global temporary tables in SQL Server

大兔子大兔子 提交于 2019-12-30 11:32:13
问题 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

Global Temp Tables - SQL Server vs Oracle

前提是你 提交于 2019-12-30 09:42:42
问题 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

Using temp table with exec @sql in stored procedure

。_饼干妹妹 提交于 2019-12-29 06:46:16
问题 I have a stored procedure and part of them as below: @DRange is a incoming varchar value declare @sql varchar(max) set @sql = 'select * into #tmpA from TableA where create_date >= getDate - ' + @DRange + '' and is_enabled = 1' exec (@sql) select * from #tmpA The problem is when I execute the stored procedure, an error message occurs: Cannot find the object "#tmpA" because it does not exist or you do not have permissions. Is it not possible to use temp table and execute it or did I do

Can you define “literal” tables in SQL?

久未见 提交于 2019-12-29 04:28:05
问题 Is there any SQL subquery syntax that lets you define, literally, a temporary table? For example, something like SELECT MAX(count) AS max, COUNT(*) AS count FROM ( (1 AS id, 7 AS count), (2, 6), (3, 13), (4, 12), (5, 9) ) AS mytable INNER JOIN someothertable ON someothertable.id=mytable.id This would save having to do two or three queries: creating temporary table, putting data in it, then using it in a join. I am using MySQL but would be interested in other databases that could do something

SQL Server Temp table vs Table Variable

删除回忆录丶 提交于 2019-12-29 01:40:07
问题 Our client's database admins have requested that we don't use temp tables within our reporting stored procedures ( #Table ), but instead, make use of table variables. Are table variables less efficient than temp tables? Also, if I create a table as #table , as opposed to ##table , the one with one # is a session table, as opposed to the ## which is global, right? When the stored procedure is completed, and you don't do a DROP TABLE #table ... does #table still exist? If it's session based,

TSQL select into Temp table from dynamic sql

元气小坏坏 提交于 2019-12-28 06:18:55
问题 This seems relatively simple, but apparently it's not. I need to create a temp table based on an existing table via the select into syntax: SELECT * INTO #TEMPTABLE FROM EXISTING_TABLE The problem is, the existing table name is accepted via a parameter... I can get the table's data via: execute ('SELECT * FROM ' + @tableName) but how do I marry the two so that I can put the results from the execute directly into the temp table. The columns for each table that this is going to be used for are

Create a temp table with a distinct name and sum of values

流过昼夜 提交于 2019-12-25 09:29:04
问题 I have a table of costs per employee. The table can have multiple rows for a given employee and in each row a distinct cost. I want to end up with a temp table that has the total costs for each employee. So: Name | Cost Dave | 563.22 John | 264.00 I tried the following but the below is invalid for updating the cost. What do I have wrong? And is there a better way to do this. declare @temp2 table ( name text, cost integer ) insert @temp2(name) SELECT DISTINCT ename6 from dbo.condensed7day

SELECT INTO ##temptable from dynamic @sql

半城伤御伤魂 提交于 2019-12-24 20:45:40
问题 SQL Server 2012. There is a table with sql statements, maintained by developers. CREATE TABLE t ( id INT PRIMARY KEY CLUSTERED NOT NULL IDENTITY(1, 1) , sql_statement NVARCHAR(MAX) NOT NULL , recipient NVARCHAR(MAX) NOT NULL ); INSERT INTO t SELECT 'select 1 as one, 2 as two, 3 as three' , 'some-email-address@host.com' Every now and then, an automated process kicks-in and executes one of the statements, checks if it returned any rows and if it did, emails them. Important bit is, the process

Build temporary table with dynamic sql in SQL Server 2008

时光毁灭记忆、已成空白 提交于 2019-12-24 19:05:54
问题 To make a long story short... I'm building a web app in which the user can select any combination of about 40 parameters. However, for one of the results they want(investment experience), I have to extract information from a different table and compare the values in six different columns(stock exp, mutual funds exp, etc) and return only the highest value of the six for that specific record. This is not the issue. The issue is that at runtime, my query to find the investment exp doesn't