Quote problem in Generating Insert Statement Script to Extract Data
Hi every body;
I would like to write an sql/plsql script which can extract data from an oracle existing table in insert statements.
example:
the table employees:
empno name
1 john
2 M'hir
3 M'silou
My problem is that i have the following result:
insert into employees values('1','john');
insert into employees values('2','m'hir');------- Problem with M'hir qote
insert into employees values('3','M'silou');----- Problem with M'silou quote
How can i have :
insert into employees values('2','m''hir');------- two quotes with M'hir =M''hir
insert into employees values('3','M''silou');----- Problem with M'silou=M''silou
plz your help
thank you at advance
Hi,
What is your DB version?? If it is >10g, you can use the Q delimiter (as mentioned by Solomon).
Check this out.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_sqltypes.htm#BABFEDBG
-Arun
Similar Messages
-
Generate Insert Statement Script to Extract Data from Table in Oracle 7i
Hi all, I have an old Oracle legacy system that is running for over 15 years.Every now and then we need to extract data from this table@ ORacle 7i to be imported back to Oracle 10G.
My thoughts are to create a script of Insert statements in oracle 7 and that to be deployed back to Oracle 10G.
I found this scripts in Google and not sure how exactly this works.Any explanation on thsi scripts , would be greatly appreciated.I find this scripst may help to generate a set of insert statements from that table to the latest table at 10G.
<pre>
-- Step 1: Create this procedure:
create or replace Function ExtractData(v_table_name varchar2) return varchar2 As
b_found boolean:=false;
v_tempa varchar2(8000);
v_tempb varchar2(8000);
v_tempc varchar2(255);
begin
for tab_rec in (select table_name from user_tables where table_name=upper(v_table_name))
loop
b_found:=true;
v_tempa:='select ''insert into '||tab_rec.table_name||' (';
for col_rec in (select * from user_tab_columns
where
table_name=tab_rec.table_name
order by
column_id)
loop
if col_rec.column_id=1 then
v_tempa:=v_tempa||'''||chr(10)||''';
else
v_tempa:=v_tempa||',''||chr(10)||''';
v_tempb:=v_tempb||',''||chr(10)||''';
end if;
v_tempa:=v_tempa||col_rec.column_name;
if instr(col_rec.data_type,'CHAR') > 0 then
v_tempc:='''''''''||'||col_rec.column_name||'||''''''''';
elsif instr(col_rec.data_type,'DATE') > 0 then
v_tempc:='''to_date(''''''||to_char('||col_rec.column_name||',''mm/dd/yyyy hh24:mi'')||'''''',''''mm/dd/yyyy hh24:mi'''')''';
else
v_tempc:=col_rec.column_name;
end if;
v_tempb:=v_tempb||'''||decode('||col_rec.column_name||',Null,''Null'','||v_tempc||')||''';
end loop;
v_tempa:=v_tempa||') values ('||v_tempb||');'' from '||tab_rec.table_name||';';
end loop;
if Not b_found then
v_tempa:='-- Table '||v_table_name||' not found';
else
v_tempa:=v_tempa||chr(10)||'select ''-- commit;'' from dual;';
end if;
return v_tempa;
end;
show errors
-- STEP 2: Run the following code to extract the data.
set head off
set pages 0
set trims on
set lines 2000
set feed off
set echo off
var retline varchar2(4000)
spool c:\t1.sql
select 'set echo off' from dual;
select 'spool c:\recreatedata.sql' from dual;
select 'select ''-- This data was extracted on ''||to_char(sysdate,''mm/dd/yyyy hh24:mi'') from dual;' from dual;
-- Repeat the following two lines as many times as tables you want to extract
exec :retline:=ExtractData('dept');
print :retline;
exec :retline:=ExtractData('emp');
print :retline;
select 'spool off' from dual;
spool off
@c:\t1
-- STEP3: Run the spooled output c:\recreatedata.sql to recreate data.
Source:http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml
</pre>Thanks Justin.
I get what you are saying,i really wanted to see the output of the codes, because the furtherst i could get from that code is
SELECT EXTRACTDATA('MYTABLE') FROM MYTABLE;
and it generated this:
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
I was expecting a string of
insert into mytable values (19/1/2009,1,1);
insert into mytable values (19/10/2008,5,10);
Thanks for the explanation . -
Unable to generate insert stmt scripts using sql developer
We are not able to generate INSERT statement script using SQL Developer. In the INSERT script system is inserting some spaces due to carriage return which we cannot reviewed individually.
DELETE FROM IM_INSTANCE_EXT_VAL_FRM
WHERE IEVF_TRG_FLD_NAME = 'PRAI_NUM_03'
AND IEVF_INST_CODE = 'APV-QQ-03'
AND IEVF_BLK_NAME = 'PGIT_POL_RISK_ADDL_INFO_01';
-- INSERTING into IM_INSTANCE_EXT_VAL_FRM
Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03','PRAI_DATA_15,','ENABLED','VFB_EV_GEN.EXT_VAL_DISABLE_PHY_DAMAGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_NO_IDX,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_SR_NO,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_LVL1_SYS_ID,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,:P_FLAG_OUT)',1,null,'N','01','VALIADTION',null,null,'PREMIA',
to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','0','1');
Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03',null,'VALIDATE','VFB_EV_GEN.EXT_VAL_VEHICLE_AGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID, :PGIT_POL_RISK_ADDL_INFO_01.PRAI_PSEC_SYS_ID,
''APV'',
''APV'',
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_07,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_08,
:P_FLAG_OUT,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_35_OUT) ',3,null,'N','01','VALIADTION',null,null,'PREMIA',to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','1','1');
Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03','PRAI_DATA_15,','DEFAULT','VFB_EV_GEN.DEFAULT_PHYSICAL_DAMAGE_SYMBOL(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_PROD_CODE,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_PSEC_SYS_ID,
''APV'',
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_07,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_03,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
:P_FLAG_OUT,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_DATA_15_OUT)',2,null,'N','01','DEFAULT',null,null,'PREMIA',to_date('30-AUG-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','0','1');
Insert into IM_INSTANCE_EXT_VAL_FRM (IEVF_SYS_ID,IEVF_INST_CODE,IEVF_PROG_CODE,IEVF_BLK_NAME,IEVF_TRG_FLD_NAME,IEVF_ACT_FLDS,IEVF_ACTION,IEVF_PROC,IEVF_SRNO,IEVF_ERR_NO,IEVF_ERR_YN,IEVF_APP_CODE,IEVF_REMARKS,IEVF_UPD_UID,IEVF_UPD_DT,IEVF_CR_UID,IEVF_CR_DT,IEVF_TRG_NAME,IEVF_CLEAR_FLD_YN,IEVF_VALIDATE_YN) values (IEVF_SYS_ID.NEXTVAL,'APV-QQ-03','PGIT6_03','PGIT_POL_RISK_ADDL_INFO_01','PRAI_NUM_03',null,'VALIDATE','VFB_EV_GEN.EXT_VAL_PHY_DAMAGE(:PGIT_POL_RISK_ADDL_INFO_01.PRAI_POL_SYS_ID,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_NO_IDX,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_END_SR_NO,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_LVL1_SYS_ID,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_CODE_02,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_NUM_03,
:P_FLAG_OUT,
:PGIT_POL_RISK_ADDL_INFO_01.PRAI_DATA_15_OUT)',9,null,'N','01','VALIADTION',null,null,'PREMIA',
to_date('19-SEP-07','DD-MON-RR'),'WHEN-VALIDATE-ITEM','1','1');
script which is taken from Sql Developer and got error while running in SQL* PLUS
Following error was raised on running the script in SQL * PLUS
5 rows deleted.
1 row created.
1 row created.
1 row created.
SP2-0734: unknown command beginning ":P_FLAG_OU..." - rest of line ignored.
SP2-0734: unknown command beginning ":PGIT_POL_..." - rest of line ignored.
SP2-0734: unknown command beginning "to_date('1..." - rest of line ignored. -
Generate INSERT Statements question
Is there a built-in PL/SQL procedure that SQL Developer utilizes to generate the INSERT statements when one exports data from a worksheet in 'insert' format? Is it part of the DBMS_METADATA package?
MikeNo this is all done in Java, we use the DBMB-METADATA only for generating DDL...
-
Script for generating insert statements
I have different tables with data and I would like to have the insert statements generated of the data in the tables. Does someone have a generic script to do the job?
Hi trafoc,
You can also check out SQL Developer which has function to output table ddl and/or
data under Tools selection. Link is "http://www.oracle.com/technology/software/products/sql/index.html"
Below is a sample output :
-- DATA FOR TABLE PEOPLE
-- FILTER = none used
REM INSERTING into PEOPLE
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('SMITH','CLERK',800,20);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('ALLEN','SALESMAN',1600,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('WARD','SALESMAN',1250,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('JONES','MANAGER',2975,20);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('MARTIN','SALESMAN',1250,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('BLAKE','MANAGER',2850,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('CLARK','MANAGER',2450,10);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('KING','PRESIDENT',5000,10);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('TURNER','SALESMAN',1500,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('GRIZZLY','CLERK',1100,20);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('JAMES','CLERK',950,30);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('FORD','ANALYST',3000,20);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('MILLER','CLERK',1300,10);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('SCOTT','Clerk',9999,20);
Insert into PEOPLE (USERNAME,JOB,SALARY,DEPTNO) values ('TEST_VPD','Clerk',1500,20);
-- END DATA FOR TABLE PEOPLE
HTH
Zack -
Generate insert statement using columns from all_tab_cols view
i am trying to generate a dynamic insert statement using the columns for a table from the all_tab_cols view. if i do a select, i get the output as rows. How do i convert the row out to columns so that i get something like this : INSERT INTO TABLE_NAME (COL1, COL2, COL3,COL4.....) .
Any help will be appreciated!SQL> select * from my_test;
no rows selected
SQL> desc my_Test;
Name Null? Type
COL1 NUMBER
COL2 NUMBER
COL3 NUMBER
SQL> declare
2 cursor c1 is select column_name from all_tab_cols where table_name = 'MY_TEST';
3 v_sql VARCHAR2(10000) := NULL;
4 v_cnt NUMBER := 0;
5 BEGIN
6 FOR I in C1 LOOP
7 v_cnt := v_cnt + 1;
8 v_sql := 'INSERT INTO my_test('||I.column_name||') values('||v_cnt||')';
9 EXECUTE IMMEDIATE v_sql;
10 END LOOP;
11 COMMIT;
12 end;
13 /
PL/SQL procedure successfully completed.
SQL> select * from my_Test;
COL1 COL2 COL3
1
2
3
SQL> -
How to set commit interval after n rows when generating insert statements?
Hi
I'm trying to generate a sql insert script with a few million rows using SQL Developer 1.5.4.
I can generate insert scripts ok, but can't see anywhere to set the commit interval.
In the preferences screen under migration I see you can set the commit interval under data move options, but I assume this is something different.
I know we could use sql loader, but this insert is part of deployment package which has a series of sql scripts that we need to run together. So I don't want to run a series of sql scripts, then run sql loader, and then go back to sql scripts.
Am i missing something, or is this just not possible with SQL Developer?
Thanks in advance for your help,
PeteUnfortunately, SQL Developer doesn't cover all of the SQL*Plus commands. There is a preference in SQL Developer to switch on autocommit in the SQL worksheet (Tools > Preferences > Database > Worksheet Parameters), but that is presumably every record, rather than every 100 as you are trying to do.
There is a document on SQL Developer's SQL*Plus support (here), but that doesn't list autocommit in either the supported or unsupported sections.
theFurryOne -
Is it possible to extract data from HFM application using VB script? If so how?
Thanks.You could use this to create a command line program which you could easily call to do what you want.
https://github.com/cgiogkarakis/hfm-batch
This is one way of doing this.
Charles -
Problem with using INSERT INTO script
Hi guys,
I was trying to duplicate a table with the following script:
CREATE TABLE TAB3(
KEYATTR NUMBER(3) NOT NULL,
BODY1 CHAR(1000) NOT NULL,
BODY2 CHAR(1000) NOT NULL,
BODY3 CHAR(1000) NOT NULL,
CONSTRAINT TAB3_PKEY PRIMARY KEY(KEYATTR) )
INSERT INTO TAB3
SELECT *
FROM system.table3
ORDER BY DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) DESC, KEYATTR DESC
However, when I execute the script, I keep getting a 'missing right parenthesis' error. Any idea what went wrong?You don't need braces.
Just
INSERT INTO TAB3
SELECT *
FROM system.table3
ORDER BY DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) DESC, KEYATTR DESCshould work. -
Nds Insert statement little problem
DB version XE 10g
Hello
I have little problem with my insert statement.
In my code, are many examples, but plz focus on V2 and V3 part.
As you can see V2 and V3 are not working
I get following errors
V2
Error report:
ORA-00984: column not allowed here
ORA-06512: AT line 28
00984. 00000 - "column not allowed here"
V3
Error report:
ORA-00917: missing comma
ORA-06512: AT line 33
00917. 00000 - "missing comma"
I really have no idea, why i'm getting these errors...
DROP TABLE FILMYARNOLD;
CREATE TABLE FILMYARNOLD
FIL_ID VARCHAR2 (329),
FIL_NAME VARCHAR2 (592),
FIL_YEAR VARCHAR2 (294),
FIL_ACTOR VARCHAR2 (392),
FIL_TEXTT VARCHAR2 (2596)
SET SERVEROUTPUT ON
DECLARE
TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
vfilmiczki FIL_TABLE := fil_table();
statement VARCHAR2 (2048);
BEGIN
vfilmiczki.EXTEND;
vfilmiczki(1) := '77804';
vfilmiczki.EXTEND;
vfilmiczki(2) := 'Predator';
vfilmiczki.EXTEND;
vfilmiczki(3) := '1984';
vfilmiczki.EXTEND;
vfilmiczki(4) := 'Arnold';
vfilmiczki.EXTEND;
vfilmiczki(5) := 'get to the choppa';
/*statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
statement := statement|| '''chlip'',''lol'',''lol'',''chlip''';--
statement := statement||',''hmm'')';*/
-------V1------------working-----------------
--statement := 'INSERT INTO FILMYARNOLD (FIL_ID) VALUES ( ';
--statement := statement||vfilmiczki(1)||' )';
--EXECUTE IMMEDIATE statement;
--------V2-------------------- not working -----------------------------------------
--statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
--statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||' )';
--EXECUTE IMMEDIATE statement;
----V3------------ not working ------------
statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||','||vfilmiczki(3)||','||vfilmiczki(4)||','||vfilmiczki(5)||' )';
EXECUTE IMMEDIATE statement;
/* statement := 'INSERT INTO FILMYARNOLD VALUES (:jeden, :dwa, :trzy, :cztery, :piec)';
EXECUTE IMMEDIATE statement
USING vfilmiczki(1)
, vfilmiczki(2)
, vfilmiczki(3)
, vfilmiczki(4)
, vfilmiczki(5); */
statement := 'INSERT INTO FILMYARNOLD VALUES ('; --(:jeden, :dwa, :trzy, :cztery, :piec)';
FOR i IN 1..vfilmiczki.COUNT
LOOP
IF i = vfilmiczki.LAST THEN
statement := statement||vfilmiczki(i)||' )';
ELSE
statement := statement||vfilmiczki(i)||', ';
END IF;
--DBMS_OUTPUT.PUT_LINE (vfilmiczki(i));
END LOOP;
EXECUTE IMMEDIATE statement;
--INSERT INTO FILMYARNOLD
--VALUES (vfilmiczki(vfilmiczki.FIRST),vfilmiczki(2),vfilmiczki(3),
--vfilmiczki(4), vfilmiczki(5));
--DBMS_OUTPUT.PUT_LINE ('*****************');
--DBMS_OUTPUT.PUT_LINE (vfilmiczki((vfilmiczki.LAST)));
END;
/Im waiting for your replys
greetingsHi,
change V2 to:
STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''' )';
EXECUTE IMMEDIATE statement;and V3 to:
----V3------------ not working ------------
STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''','||VFILMICZKI(3)
||','''||VFILMICZKI(4)||''','''||VFILMICZKI(5)||''' )';
EXECUTE IMMEDIATE statement;EXECUTE IMMEDIATE statement;One general remark: INSERT can be used directly in PL/SQL, you don't need to bother with dynamic SQL,
and the direct SQL will be probably more efficient than dynamic SQL.
Try this:
SET SERVEROUTPUT ON
DECLARE
TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
vfilmiczki FIL_TABLE := fil_table();
statement VARCHAR2 (2048);
BEGIN
vfilmiczki.EXTEND;
vfilmiczki(1) := '77804';
vfilmiczki.EXTEND;
vfilmiczki(2) := 'Predator';
vfilmiczki.EXTEND;
vfilmiczki(3) := '1984';
vfilmiczki.EXTEND;
vfilmiczki(4) := 'Arnold';
vfilmiczki.EXTEND;
vfilmiczki(5) := 'get to the choppa';
-------V1------------working-----------------
INSERT INTO FILMYARNOLD (FIL_ID) VALUES ( VFILMICZKI(1) );
--------V2-------------------- not working -----------------------------------------
INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( VFILMICZKI(1),VFILMICZKI(2));
----V3------------ not working ------------
INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT)
VALUES ( VFILMICZKI(1), VFILMICZKI(2), VFILMICZKI(3), VFILMICZKI(4), VFILMICZKI(5));
END;
/ -
Generate SQL Insert Statements
Hello,
I am testing generating insert statements for which I have a function which will return a sql statement.
This sql statement when I execute would results as sql insert statements.
What I am trying to acheive through a procedure is when I execute function, the result I would like to execute automatically and then the second sql I would like to store to a control file or sql file.
How can I acheive this?
Any help is very helpful
Regards
Edited by: user20090209 on Aug 20, 2009 11:34 AMHere is the function to generate sql
CREATE OR REPLACE function insert_sql(v_table_name varchar2)
return varchar2 as
b_found boolean := false;
v varchar2(32000);
v1 varchar2(32000);
v2 varchar2(32000);
begin
for s in (
select *
from all_tables
where table_name=upper(v_table_name)
--and owner=upper(v_owner)
) loop
b_found := true;
for ss in (
select *
from all_tab_columns
where table_name = s.table_name
order by column_id
) loop
if ss.data_type='NUMBER' then
v1:=v1||','||ss.column_name;
v2:=v2||',''''''||to_char('||ss.column_name||')||''''''';
end if;
if ss.data_type in ('VARCHAR2','CHAR') then
v1:=v1||','||ss.column_name;
v2:=v2||',''''''||replace(replace('||ss.column_name||','''''''',''''''''''''),''&'','''')||''''''';
end if;
if ss.data_type='DATE' then
v1:=v1||','||ss.column_name;
v2:=v2||',to_date(''''''||to_char('||ss.column_name||',''dd.mm.yyyy hh:mi:ss'')||'''''',''''dd.mm.yyyy hh:mi:ss'''')';
end if;
end loop;
v:='select ''insert into '||s.table_name||' (';
v:=v||substr(v1,2,9999)||') '||chr(10)||' values ('||substr(v2,2,9999)||'); '' txt from '||s.table_name;
end loop;
if not b_found then
v:='- Table ' || v_table_name || ' not found';
else
v:=v;
end if;
return v;
end;
/And I am calling like
CREATE OR REPLACE PROCEDURE test_gen_script_exec IS
type v_ref_cur is REF CURSOR;
v_ref_cur_var v_ref_cur;
v_temp_sql VARCHAR2(4000);
v_sql varchar2(4000);
begin
v_sql := insert_sql('table_name');--change here
open v_ref_cur_var for v_sql;
loop
fetch v_ref_cur_var into v_temp_sql;
exit when v_ref_cur_var%notfound;
execute immediate v_temp_sql;
end loop;
close v_ref_cur_var;
end;
/Edited by: user20090209 on Aug 20, 2009 1:24 PM -
Problem using insert statement....?
I am facing problem while using insert statement.
It is not updating the database table though the same code is working very well on another server.
Please tell what could be the problem.......?Hi Vijendra ,
You need to check few parameters while creating the table
1. Table Manitainance
2.Buffering
Also , as per you , if ur insert statement is working perfectly fine in another serve..
, it is highlt possible that table created has 'mandt ' filed , which means this table is client dependent.
Also , another reason is that , you may not this table at all in the new server .
So , check onall thiese parameters.
Ihope this solves ur problem.
Regards.
Note: Rewad if useful -
Hi
I am using Flex to insert data through remoteobject and using
SAVE method generated from CFC Wizard.
My VO contains the following variables where id has a default
value of 0 :
public var id:Number = 0 ;
public var date:String = "";
public var accountno:String = "";
public var debit:Number = 0;
public var credit:Number = 0;
id is set as the primary key in my database.
I have previously used MySQL which automatically generates a
new id if I either omitted the id value in my insert statement or
use 0 as the default value.
However, now I am using MS SQL Server and the insert
generated this error:
Unable to invoke CFC - Error Executing Database Query.
Detail:
[Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert
explicit value for identity column in table 'Transactions' when
IDENTITY_INSERT is set to OFF.
Strange thing is that I dont see this problem with another
sample application. I compared with that application (it has the
same VO with default value of 0 for id) and everything looks
similar so I can't understand why I have this error in my
application.
This is SQL used to create the table:
USE [Transactions]
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [dbo].[Transactions](
[id] [int] IDENTITY(1,1) NOT NULL,
[date] [datetime] NULL,
[accountno] [varchar](100) NULL,
[debit] [int] NULL,
[credit] [int] NULL,
CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =
OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Has anyone encountered this problem before with insert
statements dealing with a unique id (with MS SQL Server)?Change "addRecords =
connection.prepareStatement("
to "addRecords =
connection.preparedStatement("
-BIGD -
Simple SELECT query to generate INSERT for a table
Hi,
I am looking for a SELECT query which generates INSERT statements for a table.Please guide.
Thanks
PG.Like this?
SQL> SELECT * from kons;
COL1 COL2
1 1
2 2
SQL> SELECT 'INSERT INTO kons VALUES('||col1||','||col2||');' statement FROM kons;
STATEMENT
INSERT INTO kons VALUES(1,1);
INSERT INTO kons VALUES(2,2);
SQL> If you have character and / or date columns you will have to change my example,
but you might get the idea from it.
You can spool the result to a file.
Regards,
Guido
Edit: ';' added to end of statement... -
How to generate Income Statement from Crystal Report
Hi, Experts,
I have:
SAP BUSINESS ONE 2007A
CRYSTAL REPORT 2008
I have a problem with generating Income Statement related reports from CRYSTAL.
For example,
My revenue accounts are: '411000-00-00' and '412000-00-00', my expense accounts are: '510000-00-00' and '520000-00-00'.
I'd like to generate the Income statement for Dec 1 - 31, 2008. Please advise how to generate this report. Thanks!
LorrieHi, Experts,
Currently, what I tested to generate the income statement is:
1. find out the account detail table: JDT1. My database path: Company Name -> dbo -> Tables -> JDT1
2. follow the standard report menu: add 'JDT1', show 'RefDate', 'ContraAct'; group by'Account', summarize by 'Account'.
I have the following problems:
1. with this method, I am not able to find the amount for each transaction. Because the amount does not have a name as 'RefDate' or some other fields.
2. the 'Account' and 'ContraAct' are all shown as 'SYS00000001685'. It's sysmtem message but not the actual account number or contra account number.
Thanks!
Lorrie
Maybe you are looking for
-
F110- not able to clear the debit and credit entry with the same reference
Hi, I am not able to clear the debit and credit entry with the same reference in F110 even after having the payment terms as immediate payment, payment method is maintained in document no and vendor master data. Both debit and credit entry is appeari
-
I'm trying to convert some ACC files form my iTunes library into MP3 files to burn on a CD and, have run into a problem. I created a new playlist of 130 songs from my library to burn on to the CD. 27 of the 130 songs need to be in MP3 format. So, I c
-
Delay in loading webpages!
I recently started to notice (about 2-3 days ago) that the loading of a webpage was slower than normal. I started to investigate and realized that it was just when loading a webpage and that when I tried to download something or use internet in any o
-
HT4623 unresponsive ipad in the middle of updating
My ipad 3 is updating and in the middle of it a charging cord and i tunes logo appeared and it has become unresponsive what do i do?
-
hi, lately whenever i burn a disc, wether on 8% or 98% it keeps telling me 'incompatible media' or something like that and it burns the disc and messes up... does anyone have any idea why this could be?? i assume its not the blanks i got, because som