How to Insert into a temporary table
Hi Experts,
I have created a temp table in sql from vfp using the #prefix. But when I issue an insert command sqlexec returns negative.
The code which I have used :
=sqlexec(oConn, "Create table #smenu (code_ varchar(1), name_ varchar(50))")
Table created successfully under tempdb database of sql
m_result=sqlexec(oConn, "insert into #smenu values ('100','Police')")
m_result returns negative.
Kindly help.
Try to create a permanent table:
=sqlexec(oConn, "Create table temp_smenu (code_ varchar(1), name_ varchar(50))")
m_result=sqlexec(oConn, "insert into temp_smenu values ('100','Police')")
Temporary table has limited visibility.
You need to drop table temp_smenu when finished.
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Similar Messages
-
How to insert into two differents tables at the same time
Hi
I'm newer using JDev, (version 3.1.1.2 cause the OAS seems to support just the JSP 1.0)
and I want to insert into two differents tables at the same time using one view.
How can I do that ?
TIA
EdgarOracle 8i supports 'INSTEAD OF' triggers on object views so you could use a process similar to the following:
1. Create an object view that joins your two tables. 'CREATE OR REPLACE VIEW test AS SELECT d.deptno, d.deptname, e.empname FROM DEPT d, EMP E'.
2. Create an INSTEAD OF trigger on the view.
3. Put code in the trigger that looks at the :NEW values being processed and determines which columns should be used to INSERT or UPDATE for each table. Crude pseudo-code might be:
IF :NEW.deptno NOT IN (SELECT deptno FROM DEPT) THEN
INSERT INTO dept VALUES(:NEW.deptno, :NEW.deptname);
INSERT INTO emp VALUES (:NEW.deptno, :NEW.empname);
ELSE
IF :NEW.deptname IS NOT NULL THEN
UPDATE dept SET deptname = :NEW.deptname
WHERE deptno = :NEW.deptno;
END IF;
IF :NEW.empname IS NOT NULL THEN
UPDATE emp SET empname = :NEW.empname
WHERE deptno = :NEW.deptno;
Try something along those lines.
null -
Inserts into Global Temporary Table
I'm working on using a global temporary table in one of my apps. I have a small test run here to isolate the problem. It simply creates the global temporary table, inserts a row, commits and then does a select to see if the insert worked. No data shows in the table when running this. I don't know much about global temp tables, so any help would be appreciated.
CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
SBI_EMPLOYEE_ID NUMBER,
CURRENT_FLAG char(1),
EFFECTIVE_START date,
EFFECTIVE_END date
) ON COMMIT DELETE ROWS;
INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(0, '', SYSDATE, SYSDATE);
commit;
SELECT * FROM AGENT_SILO.AS_TEMP_VALIDATE;So I wonder what else I'm doing wrong that's really obvious. Here's what i'm trying to accomplish and maybe there's a better way of going about it.
I have a trigger that is supposed to do some validation before the insert is allowed to go through. So here's my approach. I have a trigger fired when there's an insert into the AS_Employee_history table. This passes some of the fields from this insert into a proc (the id, a flag and a couple of dates). Within the proc, i create a global temp table, insert these passed values into the temp table. Then I have a cursor to basically copy the rows from the as_employee_history table that have the same id. Then I can do some selects on the temp table to see if it passes the validation.
I have outputs throughout for debugging and it gets to right after the inserts into the temp table, then the rest of the code doesn't appear to be executed. So it looks like it's failing at the execution of select statements on the temp table. Anything else obvious that I"m missing here?
Here's my proc.
PROCEDURE "PAS_VALIDATE" (STATUS OUT VARCHAR2, v_status OUT BOOLEAN, NEW_SBI_EMPLOYEE_ID IN NUMBER,
NEW_CURRENT_FLAG IN CHAR, NEW_EFFECTIVE_START IN DATE,
NEW_EFFECTIVE_END IN DATE)
IS
v_prev_effective_end date;
v_flag_count number;
v_flag_count_date number;
--variables to store dynamic sql returns
v_sql_flag_count_date varchar2(255);
v_sql_flag_count varchar2(255);
v_sql_prev_eff_end varchar2(255);
cursor c_row is
select * from AGENT_SILO.AS_EMPLOYEE_HISTORY EMP
where (EMP.SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID);
r_row c_row%ROWTYPE;
BEGIN
Status := 'Started';
v_status := true;
DBMS_OUTPUT.PUT_LINE('Creating temporary table...');
execute immediate 'CREATE GLOBAL TEMPORARY TABLE AGENT_SILO.AS_TEMP_VALIDATE (
SBI_EMPLOYEE_ID NUMBER,
CURRENT_FLAG char(1),
EFFECTIVE_START date,
EFFECTIVE_END date
) ON COMMIT PRESERVE ROWS';
DBMS_OUTPUT.PUT_LINE('Validating the data...');
--DBMS_OUTPUT.PUT_LINE('Inserting submitted row into temp table');
--Insert the new row being submitted from user into the temp table
execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(' || NEW_SBI_EMPLOYEE_ID || ',
''' || NEW_CURRENT_FLAG || ''',
to_date(''' || to_char(NEW_EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
to_date(''' || to_char(NEW_EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
--Insert the other rows to we end up with a subset of the employee history table
--with only rows that match the sbi_employee_id of the submitted row
--DBMS_OUTPUT.PUT_LINE('Inserting into temp table...');
open c_row;
loop
fetch c_row into r_row;
exit when c_row%NOTFOUND;
execute immediate 'INSERT INTO AGENT_SILO.AS_TEMP_VALIDATE(SBI_EMPLOYEE_ID, CURRENT_FLAG, EFFECTIVE_START, EFFECTIVE_END)
VALUES(' || r_row.SBI_EMPLOYEE_ID || ',
''' || r_row.CURRENT_FLAG || ''',
to_date(''' || to_char(r_row.EFFECTIVE_START, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''),
to_date(''' || to_char(r_row.EFFECTIVE_END, 'mm/dd/yyyy hh:mi:ss') || ''', ''mm/dd/yyyy hh:mi:ss''))';
end loop;
close c_row;
DBMS_OUTPUT.PUT_LINE('After inserts');
-----Store queries to determine values for validation--------------------------
v_sql_prev_eff_end := 'SELECT to_char(max(effective_end), ''dd-mon-yy'')
FROM AGENT_SILO.AS_TEMP_VALIDATE
where to_char(EFFECTIVE_END, ''dd-mon-yy'') != ''31-dec-99'' AND
SBI_EMPLOYEE_ID = NEW_SBI_EMPLOYEE_ID';
--Find the largest effective_end, besides the 9999 value
execute immediate v_sql_prev_eff_end into v_prev_effective_end;
DBMS_OUTPUT.PUT_LINE('The highest previous end date: ' || v_prev_effective_end);
--...........Validation testing...........
execute immediate 'DROP TABLE AGENT_SILO.AS_TEMP_VALIDATE'; --Drop temp table
DBMS_OUTPUT.PUT_LINE('Validation Procedure Complete');
COMMIT;
status:='Success';
EXCEPTION
When Others Then
ROLLBACK;
Status := SQLERRM;
END;
Thanks a bunch for helping a noob out. -
How to insert into SQL server table form oracle forms
I created a form with oracle as my database. But there one trigger where I need to insert the data into a sql server table.
Is this possible. If so can any help me out.
Thanks in advance.
AshaHi,
You can insert into sql server database using the following steps
Note: Check wether you are using Forms 32 bit drivers. If not the Odbc data source will not work.
step 1: Create ODBC data source for SQL server(one time creation);
step 2: Logout from Oracle and login to SQL server giving the user name,password and host string as odbc:<odbc datasource name>;
step 3: use EXEC SQL statement to insert the values into the SQL server and then logout and login again to your oracle database.
Second Method.
Check the sql server documentation to insert the values using command line parameters. Then you can call the host command to execute this.
Third Method.
Write a VB exe to enter the values in the sql server making two connections one to oracle another to SQL server and then getting values from Oracle and putting in the SQL server database. You can call this exe using the Host command.
Hope this will help You.
Regards
Gaurav Thakur -
How to insert into more than one table at a time also..
hi,
i am a newbee.
how to insert into more than one table at a time
also
how to get a autoincremented value of an id say transactionid for a particular accountid.
pls assume table as
transactionid accountid
101 50
102 30
103 50
104 35
i want 102 for accountid 30 and 103 for accountid 50.
thank u@blushadow,
You can only insert into one table at a time. Take a look here :
Re: insert into 2 tables
@Raja,
I want how to extract the last incremented value not to insert.Also, I don't understand your thread title... which was "how to insert into more than one table at a time also.. "
Insert, extract... ? Can you clarify your job ?
Nicolas. -
How to insert into a table with a nested table which refer to another table
Hello everybody,
As the title of this thread might not be very understandable, I'm going to explain it :
In a context of a library, I have an object table about Book, and an object table about Subscriber.
In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
And finally, this nested table refers to the Book table.
Here the code concerning the creation of theses tables :
Book :
create or replace type TBook as object
number int,
title varchar2(50)
Loan :
create or replace type TLoan as object
book ref TBook,
loaning_date date
create or replace type NTLoan as table of TLoan;
Subscriber :
create or replace type TSubscriber as object
sub_id int,
name varchar2(25)
loans NTLoan
Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
insert into OSubscriber values
*(1, 'LEVEQUE', NTLoan(*
select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
Of course, there is an occurrence of book in the table OBook with the number attribute 1.
Oracle returned me this error :
SQL error : ORA-00936: missing expression
00936. 00000 - "missing expression"
Thank you for your help1) NUMBER is a reserved word - you can't use it as identifier:
SQL> create or replace type TBook as object
2 (
3 number int,
4 title varchar2(50)
5 );
6 /
Warning: Type created with compilation errors.
SQL> show err
Errors for TYPE TBOOK:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
SQL> create table OSubscriber of TSubscriber
2 nested table loans store as loans
3 /
Table created.
SQL> create table OBook of TBook
2 /
Table created.
SQL> insert
2 into OBook
3 values(
4 1,
5 'No Title'
6 )
7 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> insert into OSubscriber
2 values(
3 1,
4 'LEVEQUE',
5 NTLoan(
6 (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
7 )
8 )
9 /
1 row created.
SQL> select *
2 from OSubscriber
3 /
SUB_ID NAME
LOANS(BOOK, LOANING_DATE)
1 LEVEQUE
NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
SQL> SY. -
How to insert into 2 tables from the same page (with one button link)
Hi,
I have the following 2 tables....
Employees
emp_id number not null
name varchar2(30) not null
email varchar2(50)
hire_date date
dept_id number
PK = emp_id
FK = dept_id
Notes
note_id number not null
added_on date not null
added_by varchar2(30) not null
note varchar2(4000)
emp_id number not null
PK = note_id
FK = emp_id
I want to do an insert into both tables via the application and also via the same page (with one button link). I have made a form to add an employee with an add button - adding an employee is no problem.
Now, on the same page, I have added a html text area in another region, where the user can write a note. But how do I get the note to insert into the Notes table when the user clicks the add button?
In other words, when the user clicks 'add', the employee information should be inserted into the Employees table and the note should be inserted into the Notes table.
How do I go about doing this?
Thanks.Hi,
These are my After Submit Processes...
After Submit
30 Process Row of NOTES Automatic Row Processing (DML) Unconditional
30 Process Row of EMPLOYEES Automatic Row Processing (DML) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
50 Insert into Tables PL/SQL anonymous block Conditional
My pl/sql code is the same as posted earlier.
Upon inserting data into the forms and clicking the add button, I get this error...
ORA-06550: line 1, column 102: PL/SQL: ORA-00904: "NOTES": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
Error Unable to process row of table EMPLOYEES.
Is there something wrong with the pl/sql code or is it something else? -
How to insert into a table in database1 from a table in database2?
hi!
how to insert into a table in database1 from a table in
database2?
can anyone help?
Tariq.using the EXEC_SQL package.
see form help for detail.
Regards. -
How to insert into a table from 3 tables?
Hello,
How to insert into a table getting values from 3 different tables?
For example table_A has col_1 to col_10.
I want to insert into table_A,
values: col_1 to col_4 are from table_B,
col_5 is from table_C,
col_6 to col_10 are from table_D.
Thanks!Normally, you'd do this by joining B, C, and D together. In the simplest case, something like
INSERT INTO A( col1, ... col10 )
SELECT B.col1, ..., B.col4,
C.col5,
D.col6, ..., D.col10
FROM B,
C,
D,
WHERE B.someKeyColumn = C.someKeyColumn
AND C.anotherKeyColumn = D.anotherKeyColumnYou'd have to know how the data in B, C, and D relate to fill in the WHERE clause. This basically tells Oracle how to match the data in a particular row in B with the data in a particular row in C with the data in a particular row in D.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to insert into table from a xml with XDE for java?
want to insert into the oracle tables from the xml with XDE for java, some sample better. thank you.
XML Document may be stored in a SQL database with XML SQL Utility.
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10794/adx08xsu.htm#i1008168
XML Document may be stored in a SQL database with Oracle XML DB.
http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10790/xdb03usg.htm#CEGFECFH -
How to select data from 3rd row of Excel to insert into Sql server table using ssis
Hi,
Iam having Excel files with headers in first two rows , i want two skip that two rows and select data from 3rd row to insert into Sql Server table using ssis.3rd row is having column names.CUSTOMER DETAILS
REGION
COL1 COL2 COL3 COL4 COL5 COL6 COL7
COL8 COL9 COL10 COL11
1 XXX yyyy zzzz
2 XXX yyyy zzzzz
3 XXX yyyy zzzzz
4 XXX yyyy zzzzz
First two rows having cells merged and with headings in excel , i want two skip the first two rows and select the data from 3rd row and insert into sql server using ssis
Set range within Excel command as per below
See
http://www.joellipman.com/articles/microsoft/sql-server/ssis/646-ssis-skip-rows-in-excel-source-file.html
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to execute a Java method when row inserted into a database table?
I have the need to fire off a java method when a row is inserted into a database table. I am unfortunately working with MySQL which just recently supported triggers but these new triggers can not execute a Java application on any event.
What I am looking for is an event driven approach such that when a row is inserted into a specific table I can fire off a java method (sitting in a tomcat container) that will take the contents and send it to a web service.
It has been mentioned that JMS may have the ability to poll and monitor a database table. Just wondering if anyone could point me in the right direction.
thanks
JavaTekA service handler might be the right way to run some code at the end of a service call (another way would be to make use of filters).
First, make sure your static table is merged with ServiceHandlers.
Secondary, change your custom method name into one that is not already in the service definition of COLLECTION_COPY_LOT (preferably a unique method name like collectionCopyLotLastAction that describes its purpose) and remove the following line from your code:
m_service.doCodeEx("",this);Now create a service definition for COLLECTION_COPY_LOT in your custom component based on the original COLLECTION_COPY_LOT (copy paste from the original service definition) and add you own method collectionCopyLotLastAction as the last step in the service. Play with the load order to make sure CS is using your service definition of COLLECTION_COPY_LOT instead of the original.
regards,
Fabian -
Sql/Plsql code to export data into a temporary table from a text file
Dear all,
I need to create a temporary table getting data from a text file. I am very new to data loading could you please help me how to read the text file in to a temporary table.
i have text file like as below:
order items : books Purchasing
start date:
8-11-09
Notes: Books are selling from aug10 to aug 25
Action performed
Time
Verified By
sold out from shop, sold out date:_________
1.
physics _______ book sold to ravi
2.
social _______ book this is a good book
sold to kiran
aug10th
ronald
3.
maths book to sal
4.
english book__________ this was a newbook
to raj
jak
return to shop, return date:____________
1.
maths book return by:_____________ Verify book
aug11th
john
2.
story book by:_________ checked
aug14th
Now i need to create a temporary table and insert the data into the table from this text file.
Now i need to create a temporary table named as books_order with 5columns(order,Status,Action_Performed,Time,Verified_By) like as below:
Order status Action_Performed Time Verified_By
books Purchasing sold physics _______ book sold to ravi _______ _________
books Purchasing sold social _______ book this is a good book sold to kiran aug10th ronald
books Purchasing sold maths book to sal _____ __________
books Purchasing sold english book__________ this was a newbook to raj __________ jak
books Purchasing return maths book return by:_____________ Verify book aug11th john
books Purchasing return story book by:_________ checked aug14th _________
Thanks in advance.Isn't school work marvelous?
Create an external table.
http://www.morganslibrary.org/reference/externaltab.html
Getting the data into a temporary table may make sense in SQL Server ... but not in Oracle. -
How to insert images in a table
Hi all,
Iam working On Oracle10g
can any one explain how to insert images in a table.
Any help will be much appreciated!!
Thanks.Hi,
Try like this
step1: Create a folder & place the image in it.
for eg: place the image 'Sunset.jpg' in 'IMAGEFILE' folder of D drive
Step2: Create a Directory in sql*plus as
CREATE DIRECTORY IMAGEDIR AS 'D:\IMAGEFILE';
Step3: Grant previlage to user
GRANT READ ON DIRECTORY IMAGEDIR TO PUBLIC;
Step4: Create the table in which you want to insert the image
create table loadalbum
(name varchar2(100),
image blob)
Step5: Create the procedure as
declare
l_blob blob;
l_bfile bfile;
begin
insert into loadalbum values ( 'Sunset', EMPTY_BLOB() )
returning image into l_blob;
l_bfile := bfilename( 'IMAGEDIR', 'Sunset.jpg');
dbms_lob.fileopen( l_bfile );
dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
dbms_lob.fileclose( l_bfile );
end;
Now you can know whether the image is inserted or not by
SELECT COUNT(*) FROM LOADALBUM;
COUNT(*)
1
which means image is inserted.
Hope this may help you. -
Merge statement and insert into a third table
I'm wondering if the merge statement will work in my case. I'm loading a file into a temporary table. I want to compare this temporary table with an existing source table (there are multiple source tables, I've thought of breaking them up into separate statements) and write out any differences to a third table. The third table would be used for future processing on the rows that are found to be different. Do you think this is possible using the merge command?
Why use the merge command for that purpose?
If you want to find out the differences of two tables and put the result into a third one then you should do
insert into table_c
query_a
minus
query_b
or
insert into table_c
(query_a
minus
query_b)
union all
(query_b
minus
query_a)
hth
Maybe you are looking for
-
Media keys not working with iTunes 12.0.1
MacBook Pro, 15" Mid-2010 Software: OS X Yosemite 10.10.1 iTunes: 12.0.1.26 Hello, ever since I upgraded to OS X Yosemite/iTunes 12 back in October I have been unable to use the back, forward, and play/pause buttons with music playback on iTunes. I'v
-
Allow users to run installed applications
doing tons of homework on this to no avail--safarie and other applications are available to admin--i want to select applications as admin and pick which ones users can use--how the heck do you do this?--new to mac but tons of computer exp including s
-
Internal Error when selecting an Application
I'm running app server 7 2004Q2. When I access the web-based administrative interface for my server and click on an application I get the message "Internal Error. Plesae check error log for more details." This happens for both Enterprise Apps and Web
-
CAN SOMEONE PLEASE HELP ME REOVE ITUNES!
How Can I Remove and Unistall Itunes From My Computer I Went To "Add or Remove Programs" and Clicked Itunes "Change/Remove" and nothing happen! its still there same thing for quicktime and im trying to unistalled them because i dont have any were in
-
ORA:- 01033: Oracle Initialization oe shutdown in progress.
Database:- Ver 10.02 OS:- Windows Xp Scenario:- Tried to login with regular user scott,hr even sys with correct password Error:- ORA:- 01033: Oracle Initialization oe shutdown in progress. All your experts input are highly Appreciated. Thanks