T - SQL->; conversion of PL/SQL: Insert... select problem
Hello!If I have an insert in... Select T - SQL statement without a clause "from":
Bq. insert into sometable (foo, bar)-select 5, case when @bar = 5, then 4 3 other purpose
its translation is:
Bq. INSERT INTO sometable------(foo, bar)-VALUES (CASE 5,------WHERE 5 = 5 THEN 4-3 OTHER------neck END);
and I got: ORA-00917: "missing comma" for this. I don't know if this is a bug in the code of migration, or is there something so that I can use 'CASE' in an insert into... statement values somehow?
Zoli
You must remove the column name. I've just simplified your test case to check and it works:
CREATE TABLE test(
id NUMBER
);
INSERT
INTO test(id)
VALUES(CASE WHEN 5=5 THEN 4 ELSE 3 END)
;
SELECT *
FROM test
;
C.
Tags: Database
Similar Questions
-
2 PL/SQL insert new string in the string specified to a specific Position
Hello
PL/SQL insert new string in the string specified to a specific Position
Continuing the previous thread has answered, I would like to know how to cut the data after the underscore ("_").
Example:
Old chain: D100_RT
New string:APPROX100 d.
Here after, what is there after that execution should be deleted.
Thank you
Suppose that the string = D100_RT
select substr('D100_RT', 1, instr('D100_RT','_')-1 ) from dual
-
How to solve the error ORA-00001 in SQL Insert?
Hi all, I need your help appreciated.
I do a plsql procedure that inserts a line according to the value of the slider, I have error oracle ORA-00001: unique constraint (constraint_name) violated.
This message may appear if a duplicate entry exists at a different level: in the RDBMS MySQL, I have the syntax IGNORES to solve this error of duplication... and in Oracle?
Thanks for your time and your advice.
Miguelitouser6317803 wrote:
How to solve the error ORA-00001 in SQL Insert?ORA-00001 means table a unique/primary key / index and you attempt to insert a row with the key value already exists in the table. I'll assume table has a primary key on COUNTRY_ID. Then modify SQL for:
SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID ="BZ").
There is a good chance COUNTRY table also has unique key/index on COUNTRY_NAME. If so use:
SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID = 'BZ' OR 'BLZ' = COUNTRY_NAME).
SY.
-
Problem with PL/SQL insert query
Hello to all the genius... Vikram im, Im new in the world of the apex and pl/sql... I need everything that you guys help... This is my first application user (for example)
name of the table - form
name of the column - f_no number, name varchar2, number of salary.
Apex page n - p1_f_no, p1_name, p1_sal
Now my problem is the query that is below works in the workshop of sql (insertion of data in the table in shape) and can be seen using the select query... but when I implement this in the apex... It shows - in all areas:
declare
v_no number (3);
v_Name varchar2 (20);
v_sal number (10);
Start
Insert in the form values (: v_no,: v_name,: v_sal);
end;
IM using this query in the Process button,
Thank you
-Best regards,.
VikramMahir M. Quluzade have already responded.
Published by: Gokhan Atil on 03.May.2011 12:45
-
PL/SQL Insert Row Assign PK Value
I try to insert a row of data into a table and assign a primary key value. I want to give the first available primary key, not only the nextval in the maxval. Is there a way to do it cleanly, or will I need to create a cursor to do? If I need to create a slider or the sequence, how do I declare it in my procedure? Do I need a sequence so that I couldn't just use a loop for? Please help - it seems such a simple thing, but it has left me speechless.CheRenee
Look at this,
SQL> Create table M_MOVIES(MOVIE_ID NUMBER not null); Table created SQL> Alter table M_MOVIES add constraint PROD_ID_PK primary key (MOVIE_ID); Table altered SQL> Insert Into M_movies 2 (Select level id_movies From dual connect by level <= 10); 10 rows inserted SQL> Commit; Commit complete SQL> CREATE SEQUENCE seq_avail_id 2 START WITH 1 3 INCREMENT BY 1 4 MAXVALUE 99999999 5 / Sequence created SQL> INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL); INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL) ORA-00001: unique constraint (SYSTEM.PROD_ID_PK) violated SQL> Drop SEQUENCE seq_avail_id; Sequence dropped SQL> Select max(movie_id) from m_movies; MAX(MOVIE_ID) ------------- 10 SQL> CREATE SEQUENCE seq_avail_id 2 START WITH 11 3 INCREMENT BY 1 4 MAXVALUE 99999999 5 / Sequence created SQL> INSERT INTO m_movies(movie_id) VALUES(seq_avail_id.NEXTVAL); 1 row inserted
Kind regards
Christian Balz -
11.2.0.1.0 date SQL + timestamp select interesting result
Please take a look at the statement select and its result.
SQL > SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
---------------------------------------------------------------------------
CURRENT_DATE
--------------------
CURRENT_TIMESTAMP
---------------------------------------------------------------------------
12.44.09.664153 JUNE 17 10: 00:00
2010.06.17 12:44:09
12.44.09.000000 JUNE 17 10: 00:00
Interesting result, but why? The third column is always truncated to the second.
This is the expected behavior?bernyo wrote:
Please take a look at the statement select and its result.SQL > SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
---------------------------------------------------------------------------
CURRENT_DATE
--------------------
CURRENT_TIMESTAMP
---------------------------------------------------------------------------
12.44.09.664153 JUNE 17 10: 00:00
2010.06.17 12:44:09
12.44.09.000000 JUNE 17 10: 00:00Interesting result, but why? The third column is always truncated to the second.
This is the expected behavior?
No, maybe it's a bug, if it is reproducible.
Works well on 10g...SQL> SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL; CURRENT_TIMESTAMP CURRENT_DATE CURRENT_TIMESTAMP --------------------------------------------------------------------------- ------------------- --------------------------------- 17-JUN-10 13.51.40.148000 +01:00 17/06/2010 13:51:40 17-JUN-10 13.51.40.148000 +01:00 SQL>
-
How to close a sql insert?
I have an ASP poll that takes questions from a sql database. The results table to store the answer is simple. It has a field ID result, QID, and response.
Given that the survey is built dynamically, the number of questions in each survey is limitless. So my problem. How to build a sql Insert loop thru and add value to the db for QID?There is a tutorial on the www.charon.co.uk that may be of some use to you as
It is written for ASP.--
Paul Whitham
Certified Professional Dreamweaver MX2004
Adobe Community Expert - DreamweaverValleybiz Web design
www.valleybiz.NET"Lucky Kitty"
wrote in message
News:f2f1tk$KVG$1@forums. Macromedia.com...
> I have an ASP poll that takes questions from a sql database. Results
> table to store the answer is simple. It has an ID of result, QID, and response
> field.
>
> Since the investigation is built dynamically, the number of questions in each
> investigation
> is limitless. So my problem. How to build a sql insert
> statement to
> loop thru and add value to the db for QID?
> -
Using a variable in an Insert / Select
Oracle 11 g 2
It is a block of the size of the code. I want to use a variable in the clause values an Insert / Select using the execute immediate statement.
g_sysdate date := sysdate
I can't ' use sysdate directly because it is a long-term process. We attribute sysdate to g_sysdate at the beginning of the procedure and we stored in several tables. Therefore, it has the same value everywhere.
I'm getting ORA-00904: "G_SYSDATE": invalid identifier
create table usa.work_time ( id number , work_status_id number , work_task_id number , txt_msg varchar2(255) ) / create table usa.work_time_arc ( id number , work_status_id number , work_task_id number , txt_msg varchar2(255), archived_dt date ) / insert into usa.work_time values(1,2,3,'hello'); commit ; DECLARE v_query varchar2(2000); g_sysdate date := sysdate ; v_tbl_arc varchar2(61) := 'usa.work_time_arc'; v_tbl_src varchar2(61) := 'usa.work_time'; v_tab_cols varchar2(2000) := 'id,work_status_id,work_task_id,txt_msg'; v_id number := 9521; BEGIN v_query := 'insert /*+ append */ into '||v_tbl_arc || ' (' || v_tab_cols || ',archived_dt)' || 'select ' || v_tab_cols || ',g_sysdate from ' || v_tbl_src || ' where id = :id'; dbms_output.put_line(v_query); execute immediate v_query using v_id ; END ; / ERROR at line 1: ORA-00904: "G_SYSDATE": invalid identifier ORA-06512: at line 14
That should do it.
DECLARE v_query varchar2(2000); g_sysdate date := sysdate ; v_tbl_arc varchar2(61) := 'usa.work_time_arc'; v_tbl_src varchar2(61) := 'usa.work_time'; v_tab_cols varchar2(2000) := 'id,work_status_id,work_task_id,txt_msg'; v_id number := 9521; BEGIN v_query := 'insert /*+ append */ into '||v_tbl_arc || ' (' || v_tab_cols || ',archived_dt)' || 'select ' || v_tab_cols || ',:g_sysdate from ' || v_tbl_src || ' where id = :id'; dbms_output.put_line(v_query); execute immediate v_query using g_sysdate, v_id ; END ; /
-
I have an insert query that I have not changed, but for some reason it won't insert anything in the database.
The data is entered by a form of Ajax submission and goes to insert.php
{if (isset($_POST['message_wall']))}
/ * The database connection * /.
include ('config.php');
/ * Remove the HTML tag to prevent the injection of the query * /.
$message = mysql_real_escape_string($_POST['message_wall']);
$to = mysql_real_escape_string($_POST['profile_to']);
$sql = "INSERT INTO wall (VALUES) (message)
« '. $message. " »)';
mysql_query ($SQL);I want to be able to add a user_id in the database too
The ajax code:
$(document) .ready (function () {}
{$("form#submit_wall").submit (function ()}
var message_wall is $('#message_wall').attr ('value');.
$.ajax({)
type: 'POST',
URL: "insert.php"
data: "message_wall ="+ message_wall, ".
success: function() {}
$("ul#wall").prepend ("< style li =' display: none" > "+ message_wall +"< /li > < br > < HR >");
$("ul #wall li:first").fadeIn();)
}
});
Returns false;
});
});Hello
As it is a form ajax post then the form data should be inserted into your database using the insert.php script. All in the form of ajax jQuery is passed to the script of treatment if you process in the insert script it should work o/k.
You must then include a text response to aid a statement simple echo in your insert script, this should include everything that you want to appear on your page.
Php in your insert script would be similar to.
At the beginning of the script.
$date = $_POST ['msg_date'];
At the bottom of the script.
If {($success)
echo "Inserted on $date ';
} else {}
echo "there was a problem processing your information.';
}The jQuery to achieve code would be-
Perform tasks of post-tabling
function showResponse (responseText, statusText) {}
$('.response').text (responseText);
}More-
success: showResponse,
Treatment options in your ajax form
And just include a
where you want to display in your html code.
PZ
-
Someone broke into my computer informing me that he has been infected with malware, viruses, etc. and advising me to contact a phone number, also send me a live conversation on how to solve the problem. He claims to be an Apple / Safari servic
This kind of message is a scam. Do not meet it.
Force Quit Safari, then restart Safari while holding the SHIFT key.
-
issue: sql insert into select
which is wrong with this query?
insert into m_payment_option (p_type, m_fulfillment)
values ('DIRECT_DEBIT', (select id from M_FULFILLMENT whose id not in (select m_fulfillment from M_PAYMENT_OPTION)));
SQL-Fehler: ORA-01427: Unterabfrage fur eine liefert mehr als eine line line
01427 00000 - "einreihig subquery returns several lines.
the subquery returns:
SELECT id from M_FULFILLMENT whose id not in (select m_fulfillment from M_PAYMENT_OPTION)
47113
47182
47183
..
Hallo,
Try this
insert into m_payment_option (p_type,m_fulfillment) select 'DIRECT_DEBIT', id from M_FULFILLMENT where id not in (select m_fulfillment from M_PAYMENT_OPTION));
The subquery in your statement offers several lines and failed to insert 2 or more values in your m_fulfillment column at a time.
But I think you want to insert several lines. Otherwise, you need to change your subquery to offer that one value, maybe a max or min function will help.
Grüße aus Bonn
Kay
-
Word key missing in to_number conversion in the SQL statement select error
ORA-00905: lack keyword for the below SQL statement error. It should be of to_number (m.EQUIP_SUB_CLASS_ID, '9999')
between 3800 and the 3699 where Clause. Is that what I miss in the SQL below?
SELECT M.EQUIP_NO,M.EQUIP_CLASS_ID, M.EQUIP_DESCR,M.ORG_ID from MAMIS.EQUIP M where M.EQUIP_NO in ( SELECT M.EQUIP_NO from MAMIS.EQUIP M, MAMIS.ORG O where upper(M.ORG_ID) like upper(O.ORG_ID) and length(replace(translate(M.EQUIP_SUB_CLASS_ID, '0123456789', '000000000'), '0')) is null and upper(M.fleet_status) like 'ACTIVE' and upper(M.ORG_ID) not like 'NA' and to_number(m.EQUIP_SUB_CLASS_ID , '9999') between 3699 and 3800 )
Hello
I don't see obvious errors.
Whenever you have a problem, please post a full test script that people can run to recreate the problem and test their ideas. Include CREATE TABLE and INSERT statements for all of the tables involved and the results desired from these data. Format your code so people can read and understand.
See the FAQ forum {message identifier: = 9360002}I saw a couple of things you need to know about Oracle, but none of them would cause an error "Missing key word".
There is no point in using the LIKE operator if you do use wildcards. For example
upper (M.fleet_status) like 'ACTIVE'
is slower than, but otherwise equivalent to
upper (M.fleet_status) = 'ACTIVE'
What are you trying to do here?
length ( replace ( translate ( M.EQUIP_SUB_CLASS_ID , '0123456789' , '000000000' ) , '0' ) ) is null
Want to see if m.equip_sub_class_id consists only of numbers, from ' 0 'to 9'?
If so, you can simply sayTRANSLATE ( m.equip_sub_class_id , 'X0123456789' , 'X' ) IS NULL
Depending on your front end, you may need a sem, i-colon (;) the end of your query.
-
PL/SQL insert based on conditions
I'd appreciate any help I can get. I learn PL/SQL and have stumbled upon a problem, so please help me to find an appropriate way to deal with this situation I am running Oracle 11 GR 2
My diagram:
CREATE TABLE "ENTRY"
(
'TYPE' VARCHAR2 (5 CHAR) ,
'TRANSACTION' VARCHAR2()5 TANK),
'OWNER' VARCHAR2 (5 CHAR)
);CREATE TABLE "VIEW"
(
'TYPE' VARCHAR2 (5 CHAR) ,
'TRANSACTION' VARCHAR2 (5 CHAR),
'OWNER' VARCHAR2 (5 CHAR)
);CREATE TABLE "REJECTED"
(
'TYPE' VARCHAR2 (5 CHAR) ,
'TRANSACTION' VARCHAR2 (5 CHAR),
'OWNER' VARCHAR2 (5 CHAR)
);My sample data:
insert into entry (type, transaction, owner) values (11111, 11111, 11111);
insert into entry (type, transaction, owner) values (22222, 22222, 22222);
Now for the confusing part, I wrote this procedure which has to copy the values from the table ENTRY in the table VIEW if a record is no specific combination (transaction AND owner). If such an association exists in the table for VIEW this record should then go to the REJECTED table. This procedure done that but on the executions of the procedure, I get more entries in the REJECTED table so my question is how do to limit inserts them into the table of REJECTED - if a record already exists in the REJECTED table then do nothing.
create or replace PROCEDURE COPY AS
v_owner_entry ENTRY.owner%TYPE;
v_transaction_entry ENTRY.transaction%TYPE;
v_owner VIEW.owner%TYPE;
v_transaction VIEW.transaction%TYPE;begin
begin
select e.owner, e.transaction, v.owner, v.transaction
into v_owner_entry, v_transaction_entry, v_owner, v_transaction
from entry e, view v
where e.owner = v.owner and e.transaction = v.transaction;
EXCEPTION when too_many_rows
then insert into REJECTED ( TYPE, TRANSACTION, OWNER ) SELECT s1.TYPE, s1.TRANSACTION, s1.OWNER FROM ENTRY s1;when no_data_found THEN insert into VIEW ( TYPE, TRANSACTION, OWNER ) SELECT s.TYPE, s.TRANSACTION, s.OWNER FROM ENTRY s;
end;
end;Any suggestions guys?
See you soon!
UPDATE
Sorry if the original message was not enough - clear the procedure must replicate data (on a daily basis) of DB1 to DB2 and insert in the VIEW or REJECTED depending on the conditions. Here is a picture, it would be perhaps more clearly:
Hello
your procedure could look something like this:
declare -- Local variables here i integer; begin -- Test statements here INSERT INTO REJECTED (TYPE, TRANSACTION, OWNER) SELECT ENTRY.TYPE, ENTRY.TRANSACTION, ENTRY.OWNER FROM ENTRY, VIEW WHERE ENTRY.OWNER = VIEW.OWNER AND ENTRY.TRANSACTION = VIEW.TRANSACTION AND NOT EXISTS (SELECT NULL FROM REJECTED VW2 WHERE VW2.OWNER = ENTRY.OWNER AND VW2.TRANSACTION = ENTRY.TRANSACTION); INSERT INTO VIEW (TYPE, TRANSACTION, OWNER) SELECT TYPE, TRANSACTION, OWNER FROM ENTRY WHERE NOT EXISTS (SELECT NULL FROM VIEW WHERE ENTRY.OWNER = VIEW.OWNER AND ENTRY.TRANSACTION = VIEW.TRANSACTION); COMMIT; end;
Edited: Use SQL syntax
-
service that uses multiple sql insert commands
Hello! Is it possible to use a service that updates tables of two DB? In addition, these two tables, a field is the same as the ProcessID? For example, here is the service:
< b >
< td > < table > EUM_WORKFLOW_UPDATE_ACTIONS
< td > Service
3
null
null
value Null < br >
value Null < table >
2:IEumWorkflowActions:null < td >
-> 2:IEumWorkflowDocumentProcess:Null < table >
< /tr >
Here are two separate petitions of SQL in the function above:
< b >
IEumWorkflowActions < td > < table >
< td > INSERT IN EUM_WORKFLOW_ACTIONS (WORKFLOWACTION, WKFLACTIONID) values (?,?) < table >
< td > WORKFLOWACTION varchar
WKFLACTIONID int < table >
< /tr >
< b >
IEumWorkflowDocumentProcess < td > < table >
the values of < td > INSERT IN EUM_WORKFLOW_ACTIONS (DocumentProcessID, dDocName, WKFLACTIONID, dRevLabel) (?,?,?,?) < table >
WKFLACTIONIDint < td >
DocumentProcessID int
dDocName varchar
dRevLabel varchar < table >
< /tr >
And here's how to call this service by calling GenericSoapPort:
" < envelope soap: xmlns:soap = ' http://schemas.xmlsoap.org/SOAP/envelope/ ">
" < soap: Body = xmlns:ns1 ' http://www.Oracle.com/UCM "> "
< ns1:GenericRequest webKey = "cs" >
< ns1:Service IdcService = "EUM_WORKFLOW_UPDATE_ACTIONS" >
< ns1: User > < / ns1: User >
< ns1:Document >
reject < name ns1:Field = "WORKFLOWACTION" > < / ns1:Field >
< ns1:Field = "WKFLACTIONID" > 123 name < / ns1:Field >
< ns1:Field = "WKFLACTIONID" > 123 name < / ns1:Field >
< ns1:Field = "DocumentProcessID" > 45234 name < / ns1:Field >
< name ns1:Field = "dDocName" > 1554322 < / ns1:Field >
< ns1:Field = "dRevLabel" > 1 a name < / ns1:Field >
< / ns1:Document >
< / ns1:Service >
< / ns1:GenericRequest >
< / soap: Body >
< / envelope soap: >
Would it not possible do NOT use the WKFLACTIONID twice in the service somehow call?
Thank you very much for your help!
Yes, it is possible. You can run as many SQL statements in a service you want.
With respect to the parameters, see the DataAccess from samples of how many components component. Basically, what you're doing are map placeholders to the parameters of the services (such as David to the DataAccess component). Note that these settings can be taken from an application, but also calculated (for example a SELECT statement calculates a parameter for INSERTION, but you can also use Java/idocscript), so most likely you must map the parameters of SOAP on them.
-
Tuning sql insert that inserts 1 million lines makes a full table scan
Hi Experts,
I'm on Oracle 11.2.0.3 on Linux. I have a sql that inserts data into a table of History/Archives of a table main application based on the date. The application table has 3 million lines. and all the lines that are more then 6 months old must go in a table of History/Archives. This was decided recently, and we have 1 million rows that meet this criterion. This insertion in table archive takes about 3 minutes. Plan of the explain command shows a full table scan on the main Board - which is the right thing, because we are pulling 1 million rows in the main table in the history table.
My question is that, is it possible that I can do this sql go faster?
Here's the query plan (I changed the names of table etc.)
INSERT INTO EMP_ARCH SELECT * FROM EMP M where HIRE_date < (sysdate - :v_num_days); call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.00 0.00 0 0 0 0 Execute 2 96.22 165.59 92266 147180 8529323 1441230 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 96.22 165.59 92266 147180 8529323 1441230 Misses in library cache during parse: 1 Misses in library cache during execute: 1 Optimizer mode: FIRST_ROWS Parsing user id: 166 Rows Row Source Operation ------- --------------------------------------------------- 1441401 TABLE ACCESS FULL EMP (cr=52900 pr=52885 pw=0 time=21189581 us)
I heard that there is a way to use opt_param tip to increase the multiblock read County but did not work for me... I will be grateful for suggestions on this. can collections and this changing in pl/sql also make it faster?
Thank you
OrauserN
(1) create an index on hire_date
(2) tip 'additional' use in the 'select' query '
(3) run ' alter session parallel DML'; before you run the entire statement
Maybe you are looking for
-
I can't change any settings that are shown in a popup box. The box is too small to contain the message and cannot be adjusted. I can make changes, but cannot save them. As a result, I am stuck with either save no history, or the history. My problem i
-
Tecra S2 - NEW cd/dvd drive
HelloI just put in a new cd/dvd drive on my computer laptop tecra s2.Only problem, when I start under xp the cd/dvd drive works perfectly, but I need to install vista on my computer and my bios does not recognize this drive. When I change the priorit
-
Update Windows not work in Windows XP, get the error "0x8024D001."
Original title: update XP does not work I reinstalled XP SP2 and updated to SP3 network and get error 0x8024D001 when you run the update. I ran fixit update, and he said that registration for the service is missing or damaged. I ran another microsoft
-
Hello, my name is JLTowers... I tried to transfer most of my music from my old computer files using windows XP Home Edition, on my new computer using windows 7... I transferred some on USB, but when I tried to play them, my new computer ask me to re
-
I need a PCI of communication Simple controller for my Compaq Presario PC SR5350F?
It says I need this driver... I do? I have more disks.