How to generate synthetic rows (raw(16) guid cols) in one SQL statement?
We're populating a table containing two GUID columns:
create table object
( object_guid raw(16) primary key
, project_guid raw(16)
)All object GUIDs are unique (thus the PK), and each object belongs to a given project (should be a FK to some project table). We want N objects / rows, belonging to only 100 projects, i.e. 1% of the rows of the object table belong to the project #1, 1% to #2, etc...
Right now we're using about 25 lines of C++/OCI code to do that (one query doing a "select sys_guid() from dual", and using the generated GUIDs to do inserts into object), but I suspect it's possible to do this using a single SQL statement using mysterious connect by or some other Oracle SQL magic. (our OCI code does quite a few round-trips to do the equivalent).
Would anyone please demonstrate how to generate the rows as explained above, and possibly describe how it works for the non-initiated?
Thanks, --DD
PS: I'm sure it can be done in PL/SQL as well, but I'm interested in a SQL version if one's possible.
I've found two ways, both taking a few SQL statements, but somehow I think this ought to be possible without intermediary tables... I'm sure there's a better way.
#1drop table project_tmp;
create table project_tmp
as select rownum pid, sys_guid() guid from dual
connect by level <= 100;
drop table object_tmp;
create table object_tmp
as select mod(rownum, 100) + 1 pid, sys_guid() guid from dual
connect by level <= 1000;
drop table object;
create table object
as select o.guid object_guid, p.guid project_guid
from object_tmp o, project_tmp p
where o.pid = p.pid;
drop table project_tmp;
drop table object_tmp;#2:drop table project;
create table project
as select mod(rownum, 100) + 1 prj_id, sys_guid() guid from dual
connect by level <= 100;
drop table object;
create table object
as select mod(rownum, 100) + 1 prj_id, sys_guid() object_guid from dual
connect by level <= 1000;
alter table object add project_guid raw(16);
update object o set o.project_guid = (select guid from project p where p.prj_id = o.prj_id);
drop table project;
alter table object drop column prj_id;Verification:select count(distinct project_guid) from object;
select project_guid, count(OBJECT_GUID) from object group by project_guid;
Similar Messages
-
How can i use one SQL statement to solve problem?
How can i use one SQL statement to solve the question below?
For a Table named A, there is a column named F(char type).
Now select all the records where F like '%00' and update their F value to '%01'
Just one SQL statement.Do not use PL/SQL block.
How to do that?
Thanks.What is the data volume for this table?
Do you expect lots of rows to have '%00' as their value?
Following two statements come to mind. Other experts would be able to provide better alternatives:
If you have index on SUBSTR(f, 2):
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) || '01'
WHERE substr(f,
-2) = '00';If most of the rows have pattern '%00':
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) ||
DECODE(SUBSTR(f,
-2),
'00',
'01',
SUBSTR(f,
-2)); -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
How to generate dummy rows in jsp??
Hi,
I have 2 records in my DB while iam displaying the page i should generate six rows, in that first twos should contain those 2 records from DB (this i had done) and the next four rows should be empty. I am using JSP and SERVLET i need to generate dummy rows in jsp. How could i do it.
Thanks in advance.@hunter9000
yes but rows will be generated dynamically. so it wont be helpful.
@quitte
did not get you. kindly go through my code. here am using ajax for getting refreshed for every 10 seconds.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/theme/common.css" />
<TITLE>DepartureInfo.jsp</TITLE>
</HEAD>
<script type="text/javascript">
var dummy=0;
function loadDepartureList() {
dummy++;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = getDepartureList;
url="./departurescreen?action=depart&dummy="+dummy;
req.open("GET", url, true);
req.send(null);
function getDepartureList() {
if (req.readyState == 4)
if (req.status == 200)
html = req.responseText;
document.getElementById('deptdata').innerHTML = html;
else
alert('There was a problem with the request.'+req.readyState+","+req.status);
</script>
<%@page import="com.rak.uiobjects.response.FlightInfoResponseObject,java.util.*" %>
<jsp:useBean id="displayList" scope="request" class="java.util.ArrayList"></jsp:useBean>
<BODY topmargin="0" leftmargin="0">
<!--<%
String language;
String country;
language = new String("en");
country = new String("US");
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle",
currentLocale);
System.out.println(messages.getString("farewell"));
String Greet = messages.getString("farewell");
%>
--><table border="0" height="1411" width="2509" cellspacing="0" cellpadding="0">
<tr>
<td height="80%" valign="top">
<table border="0" width="100%">
<tr >
<td width="100%" colspan="8" height="7%" class="mainheader">Departure</td>
</tr>
</table>
<div id="deptdata">
<table border="0" cellspacing="0" height="86%" width="100%">
<tr valign="top">
<td class="subheader" height="7%">Flight No</td>
<td class="subheader">Airline</td>
<td class="subheader">Time</td>
<td class="subheader">Destination</td>
<td class="subheader">Flying Time</td>
<td class="subheader">Status</td>
<td class="subheader">ETD</td>
<td class="subheader">Gate</td>
</tr>
<%if(displayList.size() == 0) {%>
<tr >
<td class="rowdatahighlight" height="66%" colspan="8">List is Empty</td>
</tr>
<%}else{
String clazz="";
int record=1;
Iterator i = displayList.iterator();
while(i.hasNext()){
FlightInfoResponseObject flightInfoResponseObjects = (FlightInfoResponseObject)i.next();
if(record%2==0){
clazz="rowdata";
}else{
clazz="rowdatahighlight";
System.out.println("SIZE IS::"+displayList.size());
%>
<tr class="<%=clazz %>">
<td height="11%"><%=flightInfoResponseObjects.getFlightNo() %></td>
<td ><%=flightInfoResponseObjects.getAirLine()%></td>
<td ><%=flightInfoResponseObjects.getDeptTime() %></td>
<td ><%=flightInfoResponseObjects.getToDestination() %></td>
<td ><%=flightInfoResponseObjects.getFlyingTime()%></td>
<td ><%=flightInfoResponseObjects.getStatus() %></td>
<td ><%=flightInfoResponseObjects.getEtdOrA() %></td>
<td ><%=flightInfoResponseObjects.getGate()%></td>
</tr>
<% record = record +1;} }%>
</table>
</div>
</td>
</tr>
<tr>
<td height="20%" valign="top">
<div id="deptbanner">
<table border="0" height="100%" width="100%">
<tr>
<td width="100%" colspan="8" class="mainheader"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
window.setInterval("loadDepartureList()",10000);
</SCRIPT>
</BODY>
</HTML> -
How to generate a row in report to compute total?
Hi:
I need help to generate a report. In an accounting report, I need to make sum for each client regarding outstanding balance. The format of report is following:
invoice#, invoice date, invoice amount, paid amount paid date, write off, outstanding balance
Client Name: Baker Express / Debtor Name: Kurt Weiss inc.
137308001, 04/18/2012, 438.07, 537.07, 06/05/2012, , (99)
137308002, 04/18/2012, 100, 90, 06/05/2012, 10,
client Total: total payment:627.07, total outstanding balance: (99)
another client and debtor pair
My question is how to generate total payment and total outstanding balancefor every pair of client and debtor. And there are multiple pairs. I tried to use group by, but how can I display every invoice tuple as well in the report?
Any help would be appreciated.
SamOne method would be to use ROLLUP in your SQL
http://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php -
How to generate individual records out of a date interval in SQL?
I have the following table in my db:
group varchar(3), start date, end date, value number
Obs.: The dates are in the format DD/MM/YYYY
This table has this single record:
'group1', 01/11/2007, 15/11/2007, 3
I need to query this table (using SQL) and generate the following result:
'group1', 01/11/2007, 3
'group1', 02/11/2007, 3
'group1', 03/11/2007, 3
'group ', 15/11/2007, 3
Does anybody know how I can produce this output?
Thank you
Message was edited by:
user596855> This table has this single record:
'group1', 01/11/2007, 15/11/2007, 3
If, at sometime in the future, this table contains more than one record, then the solutions above won't work and you might need a SQL statement like this:
SQL> create table mytable (groep,start_date,end_date,value)
2 as
3 select 'group1', date '2007-11-01', date '2007-11-15', 3 from dual union all
4 select 'group2', date '2007-11-10', date '2007-11-20', 88 from dual
5 /
Tabel is aangemaakt.
SQL> select groep
2 , day
3 , value
4 from mytable
5 model
6 partition by (groep,value)
7 dimension by (0 i)
8 measures (start_date day, end_date)
9 rules
10 ( day[for i from 1 to end_date[0] - day[0] increment 1] = day[0] + cv(i)
11 )
12 order by groep
13 , day
14 /
GROEP DAY VALUE
group1 01-11-2007 00:00:00 3
group1 02-11-2007 00:00:00 3
group1 03-11-2007 00:00:00 3
group1 04-11-2007 00:00:00 3
group1 05-11-2007 00:00:00 3
group1 06-11-2007 00:00:00 3
group1 07-11-2007 00:00:00 3
group1 08-11-2007 00:00:00 3
group1 09-11-2007 00:00:00 3
group1 10-11-2007 00:00:00 3
group1 11-11-2007 00:00:00 3
group1 12-11-2007 00:00:00 3
group1 13-11-2007 00:00:00 3
group1 14-11-2007 00:00:00 3
group1 15-11-2007 00:00:00 3
group2 10-11-2007 00:00:00 88
group2 11-11-2007 00:00:00 88
group2 12-11-2007 00:00:00 88
group2 13-11-2007 00:00:00 88
group2 14-11-2007 00:00:00 88
group2 15-11-2007 00:00:00 88
group2 16-11-2007 00:00:00 88
group2 17-11-2007 00:00:00 88
group2 18-11-2007 00:00:00 88
group2 19-11-2007 00:00:00 88
group2 20-11-2007 00:00:00 88
26 rijen zijn geselecteerd.Regards,
Rob. -
How to insert 22.5K rows in one sql statement in Oracle
Hi Gurus,
I have a one table with one column. I require to input 22.5k numbers example "08323459" in that table. Can anyone tell me how to insert those 22.5K numbers with one sql command.
I am using PL/SQL client. And oracle version is 11G.If you have an Excel file, the simplest approach is generally to save the file as a CSV, copy it to the database server, create an external table that exposes the file as a table, and then write your INSERT by selecting the data from the external table.
INSERT INTO permanent_table( column_name )
SELECT column_name
FROM external_tableAssuming you have SQL*Loader installed on your client machine, you could also use SQL*Loader to read the data in the file and load it into the database table.
Justin -
How can i put the value of a variable in an SQL statement?
Hi,
Can someone please tell me how i can use a variable as part of an sql statement.
So instead of "SELECT * FROM tablename WHERE username='john'"
I can put in "SELECT * FROM tablename WHERE username.text"What would happen if someone entered "(delete *
from tablename)" into the username field?The SELECT would fail and the DELETE
would never run.
Or am I missing something?Ok, that wasn't valid SQL, so lets change it into valid SQL. What would this do
"SELECT * FROM tablename WHERE username=" + user
where user is "blah;DROP TABLE tablename;"
The SQL would become
SELECT * FROM tablename WHERE username=blah;DROP TABLE tablename;
And that would select, and then drop the table
Kaj
Message was edited by:
kajbj -
How to generate a row value automatically...(row count)
Hi,
I have a Table in my application with fields like
ID CNAME
i should generate the values for the ID field dynamically with a Prefix..also this ID field is not visible to users, its for the database update alone...
Thanx.
Arjun.GHi,
Make this Id attribute calculated.
When you make an attribute calculated you will be able to see the getter method created for the attribute
In side the getter you can generate the value you needed.
For Ex.
public java.lang.String getID(IPrivateTestCompView.IContextElement element)
//@@begin getID
return UUID.randomUUID().toString() ;
//@@end
Regards
Ayyapparaj -
How to select first row of each group in a group by statement
Table
ProdCode PackType BatchCode ExpDate
BURSLO 1 BS20GO-2001 01/12/2004
BURSLO 1 BS20GO-2011 01/01/2007
BURSLO 2 BS20GO-2027 01/02/2003
BURSLO 3 BS20GO-2060 01/02/2004
BURSOI 9 BU10F12 01/02/2006
BURSOI 9 BU10GO-1301 01/05/2005
BURSOI 11 BU10GO-131 01/06/2008
BURSOI 2 BU10GO-1311 01/06/2007
BURSOI 13 BU10GO-1328 01/07/2006
Output
ProdCode PackType BatchCode ExpDate
BURSLO 1 BS20GO-2011 01/01/2007
BURSLO 2 BS20GO-2027 01/02/2003
BURSLO 3 BS20GO-2060 01/02/2004
BURSOI 9 BU10F12 01/02/2006
BURSOI 11 BU10GO-131 01/06/2008
BURSOI 2 BU10GO-1311 01/06/2007
BURSOI 13 BU10GO-1328 01/07/2006
i need first row after group by ProdCode, PackType and decreading order of ExpDate
Please Help me.
Thanks.
Try the below:
;With cte
as
(Select *,Row_Number()Over(partition by Prodcode,Packtype Order by expdate desc) Rn From Tablename)
Select * From cte where rn=1 -
How to generate specific # of items in tabular form from one item
Looking to display or render additional elements to a tabular form based on the number entered in a quantity field. ie. if someone orders 10 items, I would like to have 10 tabular items display on blur, so the operator can enter the data in those fields for the 10 items. Then of course I need all items processed on submit.
Is there a way to do this so the # of line items are rendered after a quantity has been entered to match or is this something that would have to be done with display values and a set number of items already on the page?
ThanksHi Naresh,
You need to use Billing Plans for Service Contracts Scenario to create BRI items.
In the Billing Plan - you can assign whether it is a Periodic Billing or Milestone Billing. Then you need to assign this billing plan to item categories. So based on the period (monthly,quarterly,yearly) - the BRI items will be generated.
So Please try using Billing Plans for your scenario. As you mentioned earlier, you are using ECC for all Billing purposes. So the system will create one Debit Memo Request document per Contract and it will each line item for each of the BRI's in Service Contract. System will not generate one DMR per BRI item.
You can check the BRI items generated at the item level --> Billing Plan Tab page (Assignment Block in Web UI).
Hope this helps.
Regards,
Siraj -
How to generate formated (defined position) text and image using pl/sql and
Hello,
I need to use pl/sql to create a dynamic html page (or image , if possible) with defined positions for text and bar code. It is necessary because the page will be printed and it should be able to be read by one other process , OCR, that needs to have all the data in defined positions.
Any suggestion are welcome.
Thanks in advance,
EmilioI don't think it's that easy. Notice that if you put the insert into an actual pl/sql block, you don't get the correct column pointer anymore.
BEGIN insert into bob(col1, col2) values (123.12, 12345.12); END;
ERROR at line 1:
ORA-01438: value larger than specified precision allows for this column
ORA-06512: at line 1
Richard -
Multiple rows in a single column in a SQL statement
Can anyone provide me with a simple sql which will run on the below table (USERROLE table)
ID ROLEUSER ROLENAME
1 user1 GL
2 user2 OBI_AP
3 user1 OBI_AP
4 user2 GL
5 user1 OBI_AR
6 user2 AR
7 user3 GL
and give the result as
ROLEUSER ROLENAMES
user1 GL;OBI_AP;OBI_AR
user2 OBI_AP;GL;AR
user3 GL
Thanks
VikramIn 10g,
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:01.12
satyaki>
satyaki>
satyaki>with t2
2 as
3 (
4 select 1 id, 'user1' ROLEUSER, 'GL' ROLENAME from dual
5 union all
6 select 2, 'user2', 'OBI_AP' from dual
7 union all
8 select 3, 'user1', 'OBI_AP' from dual
9 union all
10 select 4, 'user2', 'GL' from dual
11 union all
12 select 5, 'user1', 'OBI_AR' from dual
13 union all
14 select 6, 'user2', 'AR' from dual
15 union all
16 select 7, 'user3', 'GL' from dual
17 )
18 select ROLEUSER ,
19 substr( string, 2 ) as string
20 from dual
21 where 1 = 2
22 model
23 reference t_ref
24 on
25 (
26 select row_number() over ( order by id ) - 1 as row_num ,
27 count(*) over () - 1 as max_row_num ,
28 ROLEUSER ,
29 ROLENAME
30 from t2
31 where ROLENAME is not null
32 order by ROLENAME
33 )
34 dimension by( row_num )
35 measures ( max_row_num, ROLEUSER, ROLENAME )
36 main t_main
37 dimension by ( cast( null as varchar2(4000) ) as ROLEUSER )
38 measures ( cast( null as varchar2(4000) ) as string )
39 rules
40 iterate( 4294967295 )
41 until
42 (
43 t_ref.max_row_num[0] is null or
44 iteration_number >= t_ref.max_row_num[0]
45 )
46 (
47 string[ t_ref.ROLEUSER[iteration_number] ] = string[ cv() ] || ';' ||
48 t_ref.ROLENAME[ iteration_number ]
49 )
50 order by 1;
ROLEUSER STRING
user1 GL;OBI_AP;OBI_AR
user2 OBI_AP;GL;AR
user3 GL
Elapsed: 00:00:00.26
satyaki>Regards.
Satyaki De. -
Insert multiple rows with one sql statement in access
Hi,
I'm trying to copy a table into another. What I want to do is to use "Insert into table1 select * from table2 where field > val". Something like that. I know a lot of databases support it. I was wondering if ms access ODBC driver also supports it. I searched quite a bit and haven't found a definitive answer on this.
Thank youYes, M$ Access 2000 supports it. This is from their help:
INSERT INTO Statement
Adds a record or multiple records to a table. This is referred to as an append query.
Syntax
Multiple-record append query:
INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression
Single-record append query:
INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])
The way you've written the INSERT, table1 and table2 have to have the same # of columns and the same types, of course. -
Script error - Inserting multiple rows in one SQL statement.
Hi,
Tried using INSERT ALL INTO command inside Script. But getting below error.
Oracle <> error message for operation <OCIStmExecute>: <ORA-00928: missing SELECT keyword>.
Same query with single insert statement runs fine without any issues.
Oracle eg:
INSERT ALL
INTO item (title) VALUES ('title5')
INTO item (title) VALUES ('title6')
INTO item (title) VALUES ('title7')
SELECT * FROM dual;
Appreciate your suggestions.
ThxHi,
Actual syntax is as below:
INSERT ALL
INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'IBM')
INTO suppliers (supplier_id, supplier_name) VALUES (2000, 'Microsoft')
INTO suppliers (supplier_id, supplier_name) VALUES (3000, 'Google')
SELECT * FROM dual;
Now in your non working query, you have applied comma after first INTO statement.
Please remove it.
Thanks,
Swapnil
Maybe you are looking for
-
PartialTriggers to a trh:script is not working.
<af:panelGroupLayout layout="scroll" id="pgl3"> <af:panelBox text="Click arrow at left to hide message" id="pb3" clientComponent="true" binding="#{TextScrollerBean.tickerPanel}" inlineStyle="margin-right:10px;margin-left:10px;" contentStyle="height:5
-
Printing to a shared printer on a PC
I am new to Mac. I have a PC with a Linksys wireless router hooked up to it. My printer is a HP 6210 all in one that is set as a shared printer on my PC wireless network. I can find my network and shared printer on the powerbook but when I try to set
-
ITunes crashes on launch for all but one user
iTunes works fine for me (main user), but it crashes for any other user. I've tried deleting and creating new accounts, but no matter what I do iTunes crashes on launch for any user but me. Here's the crash report: Date/Time: 2007-08-12 13:09:51.731
-
I am using Crystal Report XI. I created a pie chart that shows the number of vehicles stolen by the day of the week. The problem is that the legend is sorted in alphabetical order. It starts with Friday - Monday - Saturday - Sunday, etc. I need to
-
After purchasing a lacie drive Im struggling to move data and drop it onto my rugged external harddrive........................infact it wont do it atall?? is there a way of formatting the drive on my mac so it works or is the external hardrive not s