PLSQL code to generate a simple test data
Hello
We need to create some test data for a customer, and I know that a PLSQL code would do the trick here. I would like the help of the community please because I'm not a programmer, or a guy PLSQL. I know that with a few simple loops and output statement, this can be achieved
We have a holiday table that has 21 rows of data:
CREATE TABLE "PARTY" ( "PARTY_CODE" NUMBER(7,0), "PARTY_NAME" VARCHAR2(50), ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS"
SELECT * FROM PARTY; PARTY_CODE PARTY_NAME ---------- ------------------ 2 PARTY 2 3 PARTY 3 4 PARTY 4 5 PARTY 5 8 PARTY 8 9 PARTY 9 10 PARTY 10 12 PARTY 12 13 PARTY 13 15 PARTY 15 20 PARTY 20 22 PARTY 22 23 PARTY 23 24 PARTY 24 25 PARTY 25 27 PARTY 27 28 PARTY 28 29 PARTY 29 30 PARTY 30 31 PARTY 31 32 PARTY 32
We have 107 events; each event, to create a dummy test data candidate (a candidate for each party code (to be found in the table above))
It's the example of test data:
001,100000000000, TEST001CAND01, FNCAND01, 1112223333, 2
001,100000000001, TEST001CAND02, FNCAND02, 1112223333, 3
001,100000000002, TEST001CAND03, FNCAND03, 1112223333, 4
001,100000000003, TEST001CAND04, FNCAND04, 1112223333, 5
...
...
001,100000000021, TEST001CAND21, FNCAND21, 1112223333, 32
002,100000000000, TEST002CAND01, FNCAND01, 1112223333, 2
002,100000000001, TEST002CAND02, FNCAND02, 1112223333, 3
002,100000000002, TEST002CAND03, FNCAND03, 1112223333, 4
...
...
002,100000000021, TEST002CAND21, FNCAND21, 1112223333, 32
and this goes completely to the 107 event.
I know it's trivial and with a little time, it can be done. I'm sorry asking such a simple code, and I really appreciate all the help in advance.
Concerning
I had sorted it by PLSQL.
DECLARE
CNTR NUMBER: = 1;
BEGIN
FOR I IN 1.107 LOOP
for v_party_code in)
Select party_code order by party_code
)
loop
DBMS_OUTPUT. Put_line (LPAD (i, 3, 0) |) «, » ||' 1000000000' | LPAD (CNTR, 2, 0). «, » ||' TEST' | LPAD (i, 3, 0). "CAND' | LPAD (CNTR, 2, 0). «,, » ||' FNCAND' | LPAD (cntr, 2, 0). ', 1112223333. "| v_party_code.party_code);
CNTR: = cntr + 1;
end loop;
CNTR: = 1;
END LOOP;
END;
Thanks to all those who have been.
Tags: Database
Similar Questions
-
Need to insert test data in all the tables that were present in a schema
Hello
I use Oracle 9i.
10 tables were present in my current schema. All tables are not having all the records.
I need to insert test data in each table using a single procedure. (the table name is inparameter for the procedure)
For example, I test_emp, test_sal tables.
CREATE TABLE test_emp (ename varchar2 (40), number of sal);
CREATE TABLE test_sal (it NUMBER, rank NUMBER, will designate the NUMBER);
I need to insert some test data in these tables. I shouldn't use utl_file or sql * loader for this.
I tried below way.
I am not able to transmit these values to the collection dynamically to the INSERT statement. I tried many ways, but I am not satisfied with the code I've written.-- Incomplete code CREATE OR REPLACE PROCEDURE test_proc_insertdata(p_table_name IN VARCHAR2) IS BEGIN --Selected all the column_names, data_type, data_length into a collection variable from user_tab_columns. SELECT u.column_name, u.data_type, u.data_length --BULK COLLECT INTO l_col_tab FROM user_tab_columns u WHERE u.table_name = p_table_name; -- generated the values using below statement SELECT decode(u.DATA_TYPE,'VARCHAR2',dbms_random.string('A', u.data_length),'NUMBER',TRUNC(dbms_random.value(1, 5000)),'DATE',SYSDATE) val_list -- INTO collection varaible FROM user_tab_columns u WHERE TABLE_NAME = p_table_name; END;
Please help me if you know a better idea.
Thank you
SuriSuri wrote:
HelloI use Oracle 9i.
10 tables were present in my current schema. All tables are not having all the records.
I need to insert test data in each table using a single procedure. (the table name is inparameter for the procedure)
For example, I test_emp, test_sal tables.
CREATE TABLE test_emp (ename varchar2 (40), number of sal);
CREATE TABLE test_sal (it NUMBER, rank NUMBER, will designate the NUMBER);I need to insert some test data in these tables. I shouldn't use utl_file or sql * loader for this.
I tried below way.
-- Incomplete code CREATE OR REPLACE PROCEDURE test_proc_insertdata(p_table_name IN VARCHAR2) IS BEGIN --Selected all the column_names, data_type, data_length into a collection variable from user_tab_columns. SELECT u.column_name, u.data_type, u.data_length --BULK COLLECT INTO l_col_tab FROM user_tab_columns u WHERE u.table_name = p_table_name; -- generated the values using below statement SELECT decode(u.DATA_TYPE,'VARCHAR2',dbms_random.string('A', u.data_length),'NUMBER',TRUNC(dbms_random.value(1, 5000)),'DATE',SYSDATE) val_list -- INTO collection varaible FROM user_tab_columns u WHERE TABLE_NAME = p_table_name; END;
I am not able to transmit these values to the collection dynamically to the INSERT statement. I tried many ways, but I am not satisfied with the code I've written.
Please help me if you know a better idea.
Thank you
SuriWith some effort, you can write dynamic insert queries. Read the data dictionary views ALL_TABLES and ALL_TAB_COLUMNS to get the data you need. You may need to limit the list to the tables you specify to hardcode the names of the tables. You can read the views for the information of table and column that you need generate the insert column orders. It will be a lot of work and it might be easier to simply hardcode values. Dynamic SQL is difficult to debug and work with: (.) Something like this (untested and totally undebugged)
declare cursor v_tab_col(p_table_name) is select * from all_tab_columns where table_name = p_table_name; v_text varchar2(32767); v_table_name varchar2(30); begin v_table_name := 'DUAL'; --chr(10) is a newline for readability when debugging v_text := 'insert into '||v_table_name||chr(10)||'('; --loop to build column list for v_tab_rec in v_tab_col loop --add comma if not first item in list if v_tab_col%rowcount > 1 then v_text := v_text ||','; end if; v_text := v_text || v_tab_rec.column_name; end loop; v_text := v_text ||') values ('|| --loop to build column values for v_tab_rec in v_tab_cur loop if (v_tab_rec.datatype = 'VARCHAR2') then --add comma if not first item in list if v_tab_col%rowcount > 1 then v_text := v_text ||','; end if; if v_tab_rec.datatype = 'NUMBER' then v_text := v_text || '9'; elsif v_tab_rec.datatype = 'VARCHAR2' then v_text := v_text ||'X'; end if; end loop; v_text := v_text || ')'; execute immediate v_text; end;
This code is not effective, but shows how to do what you described. You'll have to code for all data types you need and find a way to take into account the primary/foreign keys, yourself. I leave it to you to find a way to avoid selecting the data twice ;)
Good luck!Published by: riedelme on July 24, 2012 13:58
-
I am getting fake SQL code when generating types in JDevelper 11.1.1.3.0.
Process:
1. create a new application: Test
2. create a new project: Project1
3. create the database offline: ECIS
4. create a contact schema
5 create a type:
CREATE OR REPLACE TYPE HAS_REASON_OF_CETYPE AS OBJECT
(
has_reason_of varchar2 (36)
)
6 create a table based on the previous type type:
CREATE OR REPLACE TYPE HAS_REASON_OF_CETYPE_LIST
AS THE contact.has_reason_of_cetype TABLE;
7. generate SQL script. Results:
CREATE THE HAS_REASON_OF_CETYPE_LIST TYPE
AS_REASON_OF_CETYPE_LIST <-this is the wrong code
AS THE contact.has_reason_of_cetype TABLE;
/
CREATE THE HAS_REASON_OF_CETYPE TYPE
AS_REASON_OF_CETYPE AS OBJECT <-fact here too
(
has_reason_of varchar2 (36)
)
/
I have not seen this error with type names in our project, or this error in the previous version. Someone has seen this before and knows a way around it?
Published by: user13324293 on July 20, 2010 11:48It's a regression in the PS2 (11.1.1.3.0) during our generation of DDL has been rewritten. The problem, in a nutshell, is that while determining if the generated DDL must precede the name of the object with a differnet scheme, there are some erroneous (simpler) made of string manipulation. So if the name (or schema.name) in the source contains the token of what follows (ie the ACE or IS) has the problem. This problem is fixed in 11.1.2.0.0 and 11.1.1.4.0 streams.
There are two possible solutions.
You can use instead OF as in the above case (in the STATE does not appear in the name) or simply change the case of ACE so that it is not the same as in the name - that is to say use "beneath", 'As' or 'Sub '.
I hope this helps.
Pete - team JDeveloper DB
-
How to generate a matrix of data in column 3
I am eager to generate a matrix using data attached so that x is row 1 and column 1. I tried to divide the table and using the generation of table however it did not work. I checked the forums but no luck. any idea would be appreciated
"Board Index" resized to three exits. If you have a 2d array, leaving the low index unwired gives you a row and leaving the disconnected upper index gives you a column. The two indices of wiring gives you an element. See the online help.
My photo above is a snippet of code. Drag it to the diagram (LabVIEW 2012) and it will be transformed into executable code.
-
Creation of test data for a problem
Hello
I use this forum for a few months and it has been extremely helpful. The problem is that I really have no idea how to create some test data for a specific problem. I tried Googling, but to no avail. I had other users to create data test for some of my problems using a 'WITH' statement, but it would be great if someone could explain the logic behind it and how to address a specific problem where in the application, I use several tables.
I know this is probably a stupid question and I'm relatively new to sql, but it would help a lot if I understand the process.
Banner:
Oracle Database 11 g Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production."
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - ProductionWITH construction is known as factoring request void.
http://download.Oracle.com/docs/CD/E11882_01/server.112/e26088/statements_10002.htm#i2077142
(Not easy to find unless you know what it's called)
It allows you to start your request with a sub request which acts as a view definition that can then be used in your main query, just like any other view or a table.
This example declares two views on the fly - master_data and detail_data, which are then used in the example query. Each query sub emulates the data in the table by selecting literal values in the dual table a line using union all to generate multiple lines.
The two queries shows different results when an outer join is used in the second (+) {noformat} {noformat}
SQL> -- test data SQL> with 2 master_data as 3 ( 4 -- this query emulates the master data of a master detail query 5 select 1 id, 'Header 1' description from dual union all 6 select 2 id, 'Header 2' description from dual union all 7 select 3 id, 'Header 3' description from dual union all 8 select 4 id, 'Header 4' description from dual 9 ), 10 detail_data as 11 ( 12 -- this query emulates the detail data of a master detail query 13 select 1 id, 1 detail_id, 'Detail 1.1' description from dual union all 14 select 1 id, 2 detail_id, 'Detail 1.2' description from dual union all 15 select 1 id, 3 detail_id, 'Detail 1.3' description from dual union all 16 select 2 id, 1 detail_id, 'Detail 2.1' description from dual union all 17 select 2 id, 2 detail_id, 'Detail 2.2' description from dual union all 18 select 2 id, 3 detail_id, 'Detail 2.3' description from dual union all 19 select 2 id, 4 detail_id, 'Detail 2.4' description from dual union all 20 select 4 id, 2 detail_id, 'Detail 4.2' description from dual union all 21 select 4 id, 3 detail_id, 'Detail 4.3' description from dual 22 ) 23 -- main query 24 -- to select from test data 25 select 26 m.description, 27 d.description 28 from 29 master_data m, 30 detail_data d 31 where 32 m.id = d.id 33 order by 34 m.id, 35 d.detail_id; DESCRIPT DESCRIPTIO -------- ---------- Header 1 Detail 1.1 Header 1 Detail 1.2 Header 1 Detail 1.3 Header 2 Detail 2.1 Header 2 Detail 2.2 Header 2 Detail 2.3 Header 2 Detail 2.4 Header 4 Detail 4.2 Header 4 Detail 4.3 9 rows selected. SQL> edi Wrote file afiedt.buf 1 with 2 master_data as 3 ( 4 -- this query emulates the master data of a master detail query 5 select 1 id, 'Header 1' description from dual union all 6 select 2 id, 'Header 2' description from dual union all 7 select 3 id, 'Header 3' description from dual union all 8 select 4 id, 'Header 4' description from dual 9 ), 10 detail_data as 11 ( 12 -- this query emulates the detail data of a master detail query 13 select 1 id, 1 detail_id, 'Detail 1.1' description from dual union all 14 select 1 id, 2 detail_id, 'Detail 1.2' description from dual union all 15 select 1 id, 3 detail_id, 'Detail 1.3' description from dual union all 16 select 2 id, 1 detail_id, 'Detail 2.1' description from dual union all 17 select 2 id, 2 detail_id, 'Detail 2.2' description from dual union all 18 select 2 id, 3 detail_id, 'Detail 2.3' description from dual union all 19 select 2 id, 4 detail_id, 'Detail 2.4' description from dual union all 20 select 4 id, 2 detail_id, 'Detail 4.2' description from dual union all 21 select 4 id, 3 detail_id, 'Detail 4.3' description from dual 22 ) 23 -- main query 24 -- to select from test data 25 select 26 m.description, 27 d.description 28 from 29 master_data m, 30 detail_data d 31 where 32 m.id = d.id (+) 33 order by 34 m.id, 35* d.detail_id SQL> / DESCRIPT DESCRIPTIO -------- ---------- Header 1 Detail 1.1 Header 1 Detail 1.2 Header 1 Detail 1.3 Header 2 Detail 2.1 Header 2 Detail 2.2 Header 2 Detail 2.3 Header 2 Detail 2.4 Header 3 Header 4 Detail 4.2 Header 4 Detail 4.3 10 rows selected.
-
display a value from PLSQL code for screen
How to display a PLSQL code on screen without loading value or refresh the page?
I'm using ajax to call javascript code to run the PLSQL code. I want to see a value on the screen when I launch the PLSQL code
SKUD.everything you print from the PLSQL code (using htp.p, htp.prn etc.) with will be available in Javascript as the response from the server. You can only analyze this string in javascript and display on the screen or change the page elements or create objects / dynamic elements using these values.
A minimal example
OnDemand PLSQL process: TEST_PROCESSbegin htp.prn('hello world'); end;
JavaScript code
var ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=TEST_PROCESS',0); ajaxResult = ajaxRequest.get(); alert(ajaxResult);
Displays an alert message "hello world".
You can build the string to JSON/XML in PLSQL from the structures of complex data (or more values) or even code HTML, then the treatment required in Javascript, for example extract the values of element of it and set the elements, convert the JSON array to an item from the selection list in the page or put the HTML for a div element on the page.
-
The monitoring of test data to write in the CSV file
Hi, I'm new to Labview. I have a state machine in my front that runs a series of tests. Every time I update the lights on the Panel with the State. My question is, how is the best way to follow the test data my indicators are loaded with during the test, as well as at the end of the test I can group test data in a cluster, and send it to an another VI to write my CSV file. I already have a VI who writes the CSV file, but the problem is followed by data with my indicators. It would be nice if you could just the data stored in the indicators, but I realize there is no exit node =) any ideas on the best painless approach to this?
Thank you, Rob
Yes, that's exactly what typedef are to:
Right-click on your control and select make typedef.
A new window will open with only your control inside. You can register this control and then use it everywhere. When you modify the typedef, all controls of this type will change also.
Basically, you create your own type as 'U8 numéric', 'boolean', or 'chain' except yours can be the 'cluster of all data on my front panel' type, "all the action my state machine can do," etc...
-
Hello
I am very new to TestStand, please see the question below and give advice.
I want to set up a simple test sequence.
I want a message to popup on the screen that asks the operator what unit of 6 units (maximum 10) to test (i.e. There is say box of 6 to 10 s to select from).
Then the sequence goes to the specific part of the sequence and performs the test on a unit that either has been selected.
What is the best way to do it?
I use pop-up message windows to do this? and if so what should I connect to the correct part of the sequence file?
Pop-up message windows allow only 6 options to select from?
Thank you
Hello
You can do this by using the method of message popup. You can ask the user what unit want to run message by inserting in the expression of the message in the message popup step parameters. Something like below
"Enter the number of execution unit.
1 Unit1
2 unit 2
.......
10 Unit 10 "
then check the 'Enable response text box"tab is different from the stage. When the user enters the unit number you can get the value entered by the user by inserting the below statement post expression of message popup step parameters
Locals.String = Step.Result.Response
Note: The string is a local variable to be set.
Convert string to number and send that output to pass the expression you can use a sequence of call step to call the sequence according to which must be performed. (I hope your each unit will file separate sequence)
I hope that this solves your problem. If you do not understand please let me know so that I can put a small example and send it to.
See you soon,.
Krishna
-
I have a compaq presario cq60 with vista. Could not start after the installation of windows updates. HP recovery failed with error code 100a and bios self-test gave error fail #1-07. I took the hard drive and installed in my office. Windows Explorer displays the main and recovery partitions.
The primary partition has the following folders (including hidden & system)
The recovery partition has the following (including the language files more)
Someone at - it ideas why my laptop does not work?
Thank you
Greg
Hello
You press F11 on startup with a HP Compaq to start the recovery process.
For problems with the recovery process, you will need to contact HP.
BIOS problems:
There are messages for the HP Forums for posters with similar errors:
All the answers it point to a drive about to fail
See you soon.
-
Can you call a java code or write a java code to clean or normalize the data in a Disqualification processor?
We're not your script:
#! function : doit
var st = new com.dq.SampleTest();
function doit()
{
st.Inputs(5);
output1 = st.result;
} -
To automate SQL using PLSQL Code scripts
Hi all
I have 20 (11.2.0.3) database server hosted on unix and Windows platforms.
Every day I have to kill sessions inactive of all these 20 databases of servers. I made a script below:
-----------------------------------------------------------------------------------------------------------------------------------
connect sys / & & sys_password @& & tns_database_name as sysdba
COIL E:\DELETE_INACTIVE_SESSIONS. SQL
set PAGESIZE 1000
whole FLAX 5000
SET ECHO OFF;
SET FEEDBACK OFF;
SET THE OFF POSITION;
Select "alter system kill session ' |'" | " SID | «, » || SERIES # | ' "|' immediate; "session $ v where status = 'INACTIVE' and username in ('OSS_DICTIONARY', 'ADMINISTRATOR');
SPOOL OFF;
@E:\DELETE_INACTIVE_SESSIONS. SQL
-----------------------------------------------------------------------------------
Is there a way that this execution of the script can be automated in the PLSQL code for 20 servers as well and that the code that can be inserted in the batch file to run (i.e. can be run through my computer batch file windows laptop).
Thank you
Boujemaa wrote:
No there is no way to manage the sql scripts in the PLSQL code?
Well, remember that PL/SQL is executed on a server specified by a certain user if you are already connected when executing a PL/SQL code.
You can actually use a more SQL script to connect to different servers to help connect and run your script.
that is to say:
SQL > connect sys/pwd_server1@db_server1
SQL > @killinactive.sql
SQL > connect sys/pwd_server2@db_server2
SQL > @killinactive.sql
But there is not much difference with my previous solution.
Please explain exactly what you want to do.
Kind regards.
Al
-
Hello
I created a few test (req.s, tests etc.) data in my OTM. Suppose that if I reinstall OATS, how can I get these test data in the new OTM. Can I export these test data to a CSV (windows) so that I can use in important in OTM.
Can someone help me in this topic?Hello
I see, well, you could do a report and export all the test cases, but I think it will be a lot of your time and you would lose another users, attachments, custom projects etc. fields...
If you need to re - install the database, the best thing to do is a back up and restore, I assume that you use the database default installed (Oracle XE), here are the instructions on how to do a back up and restore:
http://www.Oracle.com/technology/software/products/database/XE/files/install.102/b25144/TOC.htm#BABJCFBD
Concerning
Rajesh -
Run DA plsql code table updated using the click of checkbox
Hello
I have a box with action Dynamics plsql code to update a table when event = click/change, but only when the box is turned "on" everything seems to be ok, but the code plsql for updating the table does not work because the record in the table is not updated. Any help on this pls?Tell us is there a LOV for item checkbox?
Try sth like this:
Lets assume the id box is P1_CHECK.
Interior check point to put the list of values like this:STATIC:CheckMe;1
Then, when you create a dynamic action, put smth like this:
Event: Clicked Selection Type: Item Item: P1_CHECK Condition: equal to Value: 1
or
Event: Clicked Selection Type: Item Item: P1_CHECK Condition: JavaScript expression Value: $x('P1_CHECK_0').checked
Hope this helps you, Mimi
Published by: Mimi on October 28, 2012 21:06
Published by: Mimi on October 28, 2012 21:09
-
get the oracle environment variables by using the plsql code
Hey Geeks,
Can someone tell me how to get an environment variable Oracle (for example db_cache_size) from inside a plsql code or via a sql query block?
Thank you
PrabhuYou can query the parameter$ v.
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/dynviews_2012.htm#REFRN30176select * from v$parameter where name like '%cache%';
-
show more than one value of PLSQL code for screen
How to display more than one value of PLSQL code on screen?
Below the code has the function of printing two PLSQL code. Can someone pls change the Javascript code according to the code below.
JavaScript:begin htp.prn('hello world'); htp.prn('hi'); end;
SKUD.Javascript Code var ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=TEST_PROCESS',0); ajaxResult = ajaxRequest.get(); alert(ajaxResult);
OPPS...
Need arr = ajaxResult.split(':');
Kind regards
Shijesh**
Maybe you are looking for
-
Get tabs for reload on startup
I use Firefox to read the news. I have it on a schedule, so that it opens half an hour before I get up, so when I'm in front of my computer, they are all loaded and waiting. Before the last update, all tabs loaded at startup. Today, many sites don't.
-
If I restore to factory settings, do I lose the files?
my laptop has 50 on drive C and 300 GB on the drive D. apparently I can't use this space in C drive unless I have restore factory settings. If I do this I lose etc that I put on the files?
-
Remove any element without removing them
Hi all If I declare a queue of channel 50 elements, is there a way to output all the elements of an indicator of string without taking the elements of the queue, since I need the items in the queue again? Thank you! Yik
-
Activation error code: 0xC004F063
Hi, I ran the same copy of windows 7 for probably around 8 years now, he spent from my old house built computer that I used for about 7 years on my new computer, which is now 1 year old and has been fine so far. The next day (26 December), I installe
-
Can't go beyond blue HP startup screen
In the hope of some help... I have a HP Media Center with Windows XP Media Center 2005 m7170n. Met a virus last week (Redirected my research on the internet) and using Symantec Technical Support to rid the system of it and now my system won't boot.