SQL Qurey Problem
I have produced the below query for the production department to see what orders are due to be despatched in a particular month. Some of our sales orders are split delivery so i have to do this on a line basis. I am wondering whether i can use a case clause to sum together the lines that are within the particular date range entered in the where clause? Anyone got any suggestions, i am currentlly getting the error "ORDR. Docnum is invalid in the select list becuase it is not contained in either an aggregate function or group by clause
SELECT DISTINCT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DocDueDate], cast (T0.[U_Equipment]as varchar(50)), SUM(CASE WHEN T1.[ShipDate] >= [%0] and T1.[ShipDate] <= [%1]THEN T1.[LineTotal] ELSE 0 END) as 'Value' FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T1.[ShipDate] >= [%0] and T1.[ShipDate] <= [%1]AND T0.[DocStatus] = 'o'
SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DocDueDate], SUM(CASE WHEN T1.[ShipDate] >= [%0] and T1.[ShipDate] <= [%1] THEN T1.[LineTotal] ELSE 0 END) as 'Value', cast(T0.[U_Equipment] as varchar(50)) AS 'Details'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T1.[ShipDate] >= [%0] and T1.[ShipDate] <= [%1]AND T0.[DocStatus] = 'o'
GROUP BY T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DocDueDate], cast(T0.[U_Equipment] as varchar(50))
Hi Gordon,
I think i have solved my problem by grouping the cast formula. It seems to work anyway bit of a fluke on my part.
Thanks very much for all your help
Similar Messages
-
NEED HELP IN SQL HOMEWORK PROBLEMS
I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....Try this:
SELECT SUBSTR( TN,
DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
- DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
) xxx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XXX
234123
1254343
909823
908232
12345
SELECT regexp_substr(tn, '[^#]+', 1, level) xx
FROM (
SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
XX
234123
1254343
909823
908232
12345 -
hi
How can we solve SQL injection problem in JDBC ?
this means if we have a form with text field and the user must enter a number say 4 , instead he entered "4 or true" this will concatenated with the SQL query and return all records because of "or true"....
is there any solutions ?
i tried PreparedStatment and it words but not alwayes
good lucki clearfied this in my first post
if u didnt got what i mean u can google it
http://www.google.com
thanksYou didn't gently provide keywords, like I always do, so I cannot learn from you.
Well, with a "reproduceable example" I mean that you have to post a short but complete working code snippet which reproduces the problem. So that we can copy'n'paste it in our environment here and test/debug it ourself and then eventually confirm the SQL injection. -
Not Converted : Free-hand SQL connection problem
While converting a Free Hand SQL report from Desktop Intelligence to Web Intelligence report in BI XI 3.1, I am faced with the problem
Not Converted : <REPNAME> - Free-hand SQL connection problem
It is be noted that there are some other Free Hand SQL Reports, that go converted and published without any error. The subject report has two Data Providers; one referring to the Universe and other from the Free Hand SQL tagged to a DB ConnectionAjay,
Some more points that can be of consideration to you to help understand my problems.
The conversion from DeskI to WebI is in the same version BI XI 3.1 and not to BI 4.0 in which Free Hand SQLs is not supported.
I have converted one other Free Hand SQL Report with an error "Partially Converted : <REPNAME2> - Conditional or permanent Hide Header not available in Web Intelligence", for which I had to edit the report in InfoView and un-tick the "Show When Empty" property of the table ( http://www.forumtopics.com/busobj/viewtopic.php?t=197157&view=next&sid=e6840aafa2d1267c66dae164d1dbf9db ). I think the solution mentioned in this link does not meet the purpose as the table is not displayed in the design time after the above untick.
Coming back to our issue, further probing into this aspect I stumbled upon this link meant for RCT for BI 4.0 version
https://csdwportal.dhhs.state.nc.us/downloads/Business%20Objects%20XI%20R4.0%20Docs/SAP%20BusinessObjects%20Report%20Con…
where in Section 3.4.9, there is a mention of the limitation in conversion as under
"Conversion of reports with free-hand SQL or stored procedures is only possible in Connected mode, since the Report Conversion Tool needs to use the secured connection to the database that is saved in the CMS."
I want to how the secured connection to the database in REPNAME2 is different from the subject report REPNAME1 as REPNAME2 got partially converted. The error reported for Subject report is "Free Hand SQL Connection Problem" and not conversion problem which can occur after the connection is established.
I did check the security properties of various FHSQL connections in the CMC and all of them are identical in nature.
Please advise -
SQL Command problem in Application Express 3.2.0.00.27
To Oracle Application Express Development Team,
Yesterday I installed Oracle Application Express 3.2.0.00.27.
While doing my r&d, I came across one problem in SQL Command.
For example I wanted to run sql "select * from tab"
When I checked "Autocommit" checkbox it worked fine.
But when I unchecked the "Autocommit" checkbox it gave me following error:
ORA-01003: no statement parsed
Please check post
http://www.oraclebrains.com/2009/03/sql-command-problem-in-application-express-3200027/ for more details.
CheersI can't find the log file (a good indication that something went wrong)
Here's the transcript of the session...
SQL> startup upgrade
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 1288820 bytes
Variable Size 264242572 bytes
Database Buffers 331350016 bytes
Redo Buffers 2904064 bytes
Database mounted.
Database opened.
SQL> @apxpatch.sql
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
Wrote file apxset.sql
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
SQL>
SQL> @apxldimg.sql
PL/SQL procedure successfully completed.
Enter value for 1: C:\Documents and Settings\jtench\Desktop\My Downloads\Oracle\apex_3.2.1
old 1: create directory APEX_IMAGES as '&1/apex/images'
new 1: create directory APEX_IMAGES as 'C:\Documents and Settings\jtench\Desktop\My Downloads\Oracle\apex_3.2.1/apex/images'
Directory created.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
Commit complete.
timing for: Load Images
Elapsed: 00:03:30.03
Directory dropped.
SQL> -
SQL Express problem client connection
SQl Express problem, I can't connect another computer.
I have sql express on win xp, and one client win 7 starter. The firewall is disable, I can ping the server computer (win xp pro). On Sql Configuration Manager I enable TCP/IP protocol and named pipes. ODBC local is fine, but remote don't connect.
If anyone has an idea about this
Felipe Script CenterYou hae to enable remote Connections as well, in Express Edition it's disabled by default, see
Configure the remote access Server Configuration Option
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Pls help me(sql server problem)
Im using sql server 2000
i had 2 database servers
'srv1', 'srv2'
in srv1 had 'db1' database
first create a user called 'db1usr1' with read and write previlages only(not dbowner)
then take backup of 'db1' as 'db1bakup'
then u hav to restore the 'db1bakup' in srv2 as 'db2'
then u have 2 login in the 'srv2' machine as 'db1usr1'
here is the problem : it is(db1usr1) not logged in srv2 machine through query analyserYou're asking about a sql server problem on an Oracle forum?
Don't you think a sql server forum would be a more appropriate place for your question? -
Form_check.php returns SQL Configuration Problem
Hello, I am hosting the MUSE outside of BC and the form cannot send out email. http://<website>/scripts/form_check.php shows that there is a SQL Configuration Problem. How to fix?
Repplying to myself Ok, after lots of frustration, tickets to web host admin, forum crawlign it looks like the problem was either on the PHP-versio or the name of the form. The forms were titled with Scandinavian characters and "/"-mark so after simplified the forename from muse the messages came trough! The thing is that also did change in control panel of my web host from PHP-version 4.3 to PHP 4.5 so not sure which one did the job, actually i did try with fresh-starndard forms out of Muse and also with the complexly-named ones and the later did not come trough with the PHP-version change. So i would expect that it was both - naming and php-version.
Hopefully this will help others since painful form-issue it was. Used woo-forms for whole but in terms of easy updatebility i decided to go with MUSE one. Tool still missing crucial features like radio buttons but looks like Muse been little hobby of Adobe so features coming in one by one, slowly but surely.
Not sure though if next time will be building site using DW since these small limitations - issues makes life so much harder. When the app works it works like charm but when issue arrises you better of building stuff from scratch. -
PL/SQL Performance problem
I am facing a performance problem with my current application (PL/SQL packaged procedure)
My application takes data from 4 temporary tables, does a lot of validation and
puts them into permanent tables.(updates if present else inserts)
One of the temporary tables is parent table and can have 0 or more rows in
the other tables.
I have analyzed all my tables and indexes and checked all my SQLs
They all seem to be using the indexes correctly.
There are 1.6 million records combined in all 4 tables.
I am using Oracle 8i.
How do I determine what is causing the problem and which part is taking time.
Please help.
The skeleton of the code which we have written looks like this
MAIN LOOP ( 255308 records)-- Parent temporary table
-----lots of validation-----
update permanent_table1
if sql%rowcount = 0 then
insert into permanent_table1
Loop2 (0-5 records)-- child temporary table1
-----lots of validation-----
update permanent_table2
if sql%rowcount = 0 then
insert into permanent_table2
end loop2
Loop3 (0-5 records)-- child temporary table2
-----lots of validation-----
update permanent_table3
if sql%rowcount = 0 then
insert into permanent_table3
end loop3
Loop4 (0-5 records)-- child temporary table3
-----lots of validation-----
update permanent_table4
if sql%rowcount = 0 then
insert into permanent_table4
end loop4
-- COMMIT after every 3000 records
END MAIN LOOP
Thanks
Ashwin N.Do this intead of ditching the PL/SQL.
DECLARE
TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;
TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;
pnums NumTab;
pnames NameTab;
t1 NUMBER(5);
t2 NUMBER(5);
t3 NUMBER(5);
BEGIN
FOR j IN 1..5000 LOOP -- load index-by tables
pnums(j) := j;
pnames(j) := 'Part No. ' || TO_CHAR(j);
END LOOP;
t1 := dbms_utility.get_time;
FOR i IN 1..5000 LOOP -- use FOR loop
INSERT INTO parts VALUES (pnums(i), pnames(i));
END LOOP;
t2 := dbms_utility.get_time;
FORALL i IN 1..5000 -- use FORALL statement
INSERT INTO parts VALUES (pnums(i), pnames(i));
get_time(t3);
dbms_output.put_line('Execution Time (secs)');
dbms_output.put_line('---------------------');
dbms_output.put_line('FOR loop: ' || TO_CHAR(t2 - t1));
dbms_output.put_line('FORALL: ' || TO_CHAR(t3 - t2));
END;
Try this link, http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm#23723 -
PL/SQL reporting problem - "The webpage cannot be found" error
Dear All Expert,
I'm here having a problem on generating apex report using PL/SQL. "The webpage cannot be found" error appear when "Search" button pressed.
I'm appreciating if anyone can give their idea on this issue.
PL/SQL will be fired when "Search" button pressed.
My PL/SQL code as below;
DECLARE
lv_desc CLOB:='';
lv_note_desc varchar2(4000);
lv2 CLOB;
lv_title varchar2(2000);
lv_ti varchar2(10);
lv_tg varchar2(10);
lv_tr_cnt integer:= 0;
lv_ti_code varchar2(6);
lv_age number(6):= 0;
lv_note_flag varchar(1);
fv_note_flag varchar2(6);
fv_ti_code varchar2(6);
ti_code varchar2(20);
ti_name varchar2(50);
ti_tm_code varchar2(6);
ti_test_grp varchar2(6);
note_desc varchar2(4000);
ti_unit varchar2(20);
ti_insurance_code varchar2(20);
ti_price number(14);
ti_sex varchar(1);
ti_age varchar(10);
ti_tr_desc varchar(30);
ti_lolimit number(10);
ti_uplimit number(10);
ti_plolimit number(10);
ti_puplimit number(10);
lv_hkey number(10):= 0;
lv_found varchar2(1):= 'N';
lv_itpv varchar2(4000);
lv_lolimit char(15);
lv_uplimit char(15);
lv_tr char(15);
lv_tc char(30);
CURSOR READ_C1_REC IS
select ti_code, ti_name, ti_tm_code, ti_test_grp,ti_unit, ti_itpv_flag,ti_attached_cmt
from test_item
where ti_code like NVL(:P11104_TI_CODE,'%')
and ti_test_grp like NVL(:P11104_TG_CODE,'%')
and ti_code not like '0MB%'
order by ti_code;
C1_REC READ_C1_REC%ROWTYPE;
CURSOR READ_C2_REC IS
select tr_sex_code,tr_ageto,tr_agecode,tr_range_desc,tr_mrr_desc,tr_normal_lolimit,tr_upper_uplimit,tr_panic_lolimit,tr_panic_uplimit
from tr_range
where tr_ti_code = lv_ti_code
order by tr_ageto asc,tr_sex_code desc;
C2_REC READ_C2_REC%ROWTYPE;
cursor READ_C3_REC is
select tivh_key
from test_itpvh
where tivh_ti_code = ti_code
order by tivh_efd desc;
C3_REC READ_C3_REC%ROWTYPE;
cursor READ_C4_REC is
select tivd_lolimit,tivd_uplimit,tivd_value,tivd_rr_desc
from test_itpvd
where tivd_hkey = lv_hkey
order by tivd_seqno;
C4_REC READ_C4_REC%ROWTYPE;
BEGIN
lv_title := '<div style="overflow: auto;height: 500px; width: 1000px;"><table style="width: 500px" cellpadding="0" cellspacing="0"><thead><tr><th>Code</th><th>Name</th></tr></thead>';
htp.p(lv_title);
OPEN READ_C1_REC;
LOOP
FETCH READ_C1_REC INTO C1_REC;
EXIT WHEN READ_C1_REC%NOTFOUND;
lv_note_flag := 'N';
fv_note_flag := 'N';
fv_ti_code := c1_rec.ti_code;
ti_code := c1_rec.ti_code;
ti_name := ' '||c1_rec.ti_name;
ti_tm_code := c1_rec.ti_tm_code;
ti_test_grp := c1_rec.ti_test_grp;
lv_desc := '<tbody><tr><td><input type="hidden" name="f01" value="'||fv_ti_code||'" /></td>'||
'<td><input type="text" name="f02" size="20" maxlength="20" value="'||ti_code||'" /></td>'||
'<td><input type="text" name="f03" size="50" maxlength="50" value="'||ti_name||'" /></td>'||
'<td><input type="text" name="f04" size="6" maxlength="6" value="'||ti_tm_code||'" /></td>'||
'<td><input type="text" name="f05" size="6" maxlength="6" value="'||ti_test_grp||'" /></td>';
if c1_rec.ti_itpv_flag = 'Y' then
lv_note_flag := 'Y';
open read_c3_rec;
loop
fetch read_c3_rec into c3_rec;
exit when read_c3_rec%notfound;
lv_hkey := c3_rec.tivh_key;
lv_found := 'Y'; exit;
end loop;
close read_c3_rec;
if lv_found = 'Y' then
lv_lolimit := 'Lower limit'; lv_uplimit := 'Upper limmit';
lv_tr := 'Result'; lv_tc := 'Comment';
lv_itpv := 'INTERPRETED TEST RESULT'||chr(10)||'-----------------------'||chr(10)||lv_lolimit||lv_uplimit||lv_tr||lv_tc||chr(10);
open read_c4_rec;
loop
fetch read_c4_rec into c4_rec;
exit when read_c4_rec%notfound;
lv_lolimit := to_char(c4_rec.tivd_lolimit,'999990.999');
lv_uplimit := to_char(c4_rec.tivd_uplimit,'999990.999');
lv_tr := c4_rec.tivd_value;
lv_tc := c4_rec.tivd_rr_desc;
lv_itpv := lv_itpv||chr(10)||lv_lolimit||lv_uplimit||lv_tr||lv_tc;
end loop;
close read_c4_rec;
end if;
note_desc := lv_itpv||chr(10)||chr(10);
end if;
if ltrim(rtrim(c1_rec.ti_attached_cmt)) is not null then
lv_note_flag := 'Y';
note_desc := note_desc||'ATTACHED COMMENTS'||chr(10)||'-----------------'||chr(10)||ltrim(rtrim(c1_rec.ti_attached_cmt))||chr(10);
end if;
begin
select unit_name into ti_unit
from unit_tbl
where unit_code = c1_rec.ti_unit;
exception when no_data_found then
ti_unit := null;
end;
lv_desc := lv_desc ||'<td><input type="text" name="f06" size="20" maxlength="20" value="'||ti_unit||'" /></td>';
begin
select imh_insurance_code, imh_curr_p1 into ti_insurance_code, ti_price
from item_masterh
where imh_code = c1_rec.ti_code;
exception when no_data_found then
ti_insurance_code := null; ti_price := null;
end;
lv_desc := lv_desc ||'<td><input type="text" name="f07" size="20" maxlength="20" value="'||ti_insurance_code||'" /></td>'||'<td><input type="text" name="f08" size="14" maxlength="14" value="'||to_char(ti_price)||'" /></td>';
lv_ti_code := c1_rec.ti_code;
lv_tr_cnt := 0;
lv2 := '<table width="100%" border="0" bgcolor="#009900" cellspacing="0">';
OPEN READ_C2_REC;
LOOP
FETCH READ_C2_REC INTO C2_REC;
EXIT WHEN READ_C2_REC%NOTFOUND;
lv_tr_cnt := lv_tr_cnt + 1;
if c2_rec.tr_agecode = 'Y' then
lv_age := c2_rec.tr_ageto / 365;
elsif c2_rec.tr_agecode = 'M' then
lv_age := c2_rec.tr_ageto / 30;
else
lv_age := c2_rec.tr_ageto;
end if;
ti_sex := c2_rec.tr_sex_code;
ti_age := lv_age||c2_rec.tr_agecode;
ti_tr_desc := ' '||c2_rec.tr_range_desc;
ti_lolimit := c2_rec.tr_normal_lolimit;
ti_uplimit := c2_rec.tr_upper_uplimit;
ti_plolimit := c2_rec.tr_panic_lolimit;
ti_puplimit := c2_rec.tr_panic_uplimit;
if c2_rec.tr_range_desc = 'MRR' then
lv_note_flag := 'Y';
note_desc := 'MRR DESCRIPTION'||chr(10)||'---------------'||chr(10)||c2_rec.tr_mrr_desc||chr(10)||chr(10)||note_desc;
end if;
if lv_note_flag = 'Y' then
fv_note_flag := 'Y';
end if;
lv2 := lv2 || '<tr><td><input type="text" name="f09" size="1" maxlength="1" value="'||ti_sex||'" /></td>'||'<td><input type="text" name="f10" size="10" maxlength="10" value="'||to_char(ti_age)||'" /></td>'||'<td><input type="text" name="f11" size="30" maxlength="30" value="'||ti_tr_desc||'" /></td>'||'<td><input type="text" name="f12" size="10" maxlength="10" value="'||to_char(ti_lolimit,'99990.999')||'" /></td>'||'<td><input type="text" name="f13" size="10" maxlength="10" value="'||to_char(ti_uplimit,'99990.999')||'" /></td>'||'<td><input type="text" name="f14" size="10" maxlength="10" value="'||to_char(ti_plolimit,'99990.999')||'" /></td>'||'<td><input type="text" name="f15" size="10" maxlength="10" value="'||to_char(ti_puplimit,'99990.999')||'" /></td></tr>';
END LOOP; lv2 := lv2||'</table>';
CLOSE READ_C2_REC;
if lv_tr_cnt = 0 then
if lv_note_flag = 'Y' then
fv_note_flag := 'Y';
end if;
end if;
lv_desc := lv_desc||'<td><input type="hidden" name="f16" value="'||fv_note_flag||'" /></td>'||'<td><input type="hidden" name="f17" value="'||note_desc||'" /></td>';
lv_desc := lv_desc||'<td>'||lv2||'</td></tr></tbody>';
htp.p(lv_desc);
END LOOP;
CLOSE READ_C1_REC;
htp.p('</table>');
END;
Thanks you very much in advance!First thing I'd say is that you're code doesn't compile:
lv_title := ' // <----Secondly, does no-one use comments anymore? Isn't this drilled into people in programming classes at colleges? There's a whole bunch of code there but not much in the way of explanation as to what you are trying to achieve. It might make perfect sense to you now but try going back to it in a year and see if you can untangle it's purpose.
Thirdly, is there a specific reason why you've chosen to manually generate a report in PL/SQL, rather than delegating it to a report region? I understand that for particular formatting requirements (denormalised data, cells-within-cells etc), it is occasionally necessary to go to these lengths but I can't help but feeling a well-written query could simplify a lot of this, particularly the references multiple cursors. -
Creating pl/sql procedure problems
Dear all,
I have problems with creating a procedure which select returns more then one row.
CREATE OR REPLACE PROCEDURE ECM_DATA.check_padrones_datos
IS
v_padron_check VARCHAR2(50);
v_padron_number VARCHAR2(50);
BEGIN
SELECT count(pd.estado)
INTO v_padron_check
FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
where pd.estado not in ('2000','8000')
AND PD.ARCHIVO = P.ARCHIVO
AND P.FECHA = F.datum_s;
DBMS_OUTPUT.PUT_LINE('Št. neuspešnih zapisov : ' || v_padron_check);
SELECT distinct pd.archivo
INTO v_padron_number
FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
where pd.estado not in ('2000','8000')
AND PD.ARCHIVO = P.ARCHIVO
AND P.FECHA = F.datum_s;
DBMS_OUTPUT.PUT_LINE('Padron št. : ' || v_padron_number);
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_padron_number := 'Vsi padroni so OK';
DBMS_OUTPUT.PUT_LINE('Padron št. : ' || v_padron_number);
END;
Error -> -01422: exact fetch returns more than requested number of rows
Select returns 2 or more rows.
SELECT distinct pd.archivo
FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
where pd.estado not in ('2000','8000')
AND PD.ARCHIVO = P.ARCHIVO
AND P.FECHA = F.datum_s;
How to write correct syntax in pl/sql. I apologize in advance for rookie questions. Any help would be appreciated.
Regards,
RobertThe exact implementation depends on the use case.
You can loop through the results
FOR r IN (
SELECT DISTINCT pd.archivo
FROM par6.padrones_datos pd
,par6.padrones p
,par6.fechas f
WHERE pd.estado not in ('2000','8000')
AND pd.archivo = p.archivo
AND p.fecha = F.datum_s
LOOP
dbms_output.put_line('Padron št. : ' || r.archivo);
END LOOP;
Or maybe you can process all results in one step, e.g. if you want to update a table based on the select.
Regards
Marcus -
PL/SQL Evaluation problem of where clause in case of NUMBER column type
I found the following problem in Oracle® Database 2 Day Developer's Guide 11g Release 1 (11.1) B28843-04:
The sole parameter of function eval_frequency is employee_id IN employees.employee_id%TYPE.
An ORA-01422 exception occurs when the execution reaches the following select command
SELECT e.hire_date
INTO hire_date
FROM employees e
WHERE employee_id= e.employee_id;
A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there were no WHERE clause at all.
Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function and used this variable in the where clause, but I consider this "solution" as being no solution.
It is pointless to use %TYPE parameter of a function for flexibility if I must degrade this flexibility by a fixed declaration of a temporary variable of the same type as the column in question.
What is wrong?
The Developer'Guide I used, the Oracle Sql Developer I used or the PL/SQL version ?Hi,
Welcome to the forum!
user8949829 wrote:
A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there I don't think so. The variable employee_id is defined as having the exact same type as the eponymous column. Even if it didn't, I believe Oracle will always implicity convert between datatypes when possible, rounding if necessary. That may cause errors, but it isn't causing this error.
No, the error has nothing to do with the data type. It has to do with the ambiguity of employee_id: is it a column, or is it a variable?
The default is that it means the column name, so
WHERE employee_id = e.employee_idis equivalent to saying
WHERE e.employee_id = e.employee_idwhich isn't quite the same thing as not having a WHERE clause; rows with NULL employee_id would still be excluded, if there were any.
I think it's best not to use variable names that are the same as column names. You could call the variable v_employee_id, or, since it's an IN-argument, in_employee_id.
If you must use a variable that can be mistaken for a column, then qulaify it with the name of the procedure, like this:
WHERE eval_frequency.employee_id = e.employee_id
Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function That makes sens. You probably gave that variable a name that couldn't be mistaken for a column in the table.
Edited by: Frank Kulash on Jan 12, 2011 8:27 PM -
SQL 2008 Problem Calling an SP on an Oracle 10G Linked Server
Hi everyone
I've read through a number of posts on many sites about this issue but haven't found anything that has helped me so far. The machine I'm using is running Microsoft SQL Server 2008 64bit and the linked server I've created to Oracle 10G is using OraOLEDB.Oracle. If I test the connection in SQL Management Studio it succeeds and for any queries I have using OpenQuery to select from the Oracle DB I have no problem getting results.
The Oracle 32bit client and 64bit client versions are installed on the machine.
My problem is that I need to exec an Oracle SP which in turn inserts into various Oracle tables. I previously had this all working fine on 32bit SQL Server 2000 installation connected to Oracle 10G. Using the same code in SQL Server 2008 I get the following error:
Msg 7357, Level 16, State 2, Line 1
Cannot process the object "{CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, 'BLPO0099998', 'BLPO0099998', '', '', 39804, 21883, 'BLPO0099998', 249, 1, 950, 'Main', 190506, 37336, '1', TO_DATE( '20090706','YYYYMMDD' ), TO_DATE( '20090706','YYYYMMDD' ), 'INCOMPLETE',37336, {RESULTSET 1, P_Success})}". The OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" indicates that either the object has no columns or the current user does not have permissions on that object
The call is made by the following piece of code in SQL:
SET @execCmd = N'SELECT
P_Success
FROM
OPENQUERY( ORACLE, '''+ @oracleCmd + ''')';
EXECUTE (@execCmd);
Where @oracleCmd = {CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, ''BLPO0099998'', ''BLPO0099998'', '''', '''', 39804, 21883, ''BLPO0099998'', 249, 1, 950, ''Main'', 190506, 37336, ''1'', TO_DATE( ''20090706'',''YYYYMMDD'' ), TO_DATE( ''20090706'',''YYYYMMDD'' ), ''INCOMPLETE'',37336, {RESULTSET 1, P_Success})}
I also tried using the below snippet from another post I found and got no joy either.
declare @result varchar(255)
exec ('BEGIN
?:= your_SP_Name(''arg1'', ''arg2'', etc);
END;
',@result OUTPUT) at your_LinkedServerName;
select @result;
OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" returned message "ORA-06550: line 3, column 7:
PLS-00222: no function with name 'INTF_TW_PO_REQ_INTERFACE' exists in this scope
ORA-06550: line 3, column 1:
PL/SQL: Statement ignored".
I can't figure out why it doesn't work in SQL 2008 when it worked fine in SQL 2000 - PLEASE HELP!
Thank you
Alida HopeWhy development on 10g and production on 8i? Either both should be 8i or both should be 10g.
If you will keep production on 8i and development on 10g then you cannot stop such errors as there are features that are enabled by default in 10g and both the versions have very big differences.
Just go ahead and install 8i. -
SQL query problem - select max (case... aggregate function)
Hi,
I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
select
max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
from sag
join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
Any ideas?Moved to more sutable forum, sorry.
-
SQL recursion problem in custom groups table
hi all,
Consider the following seemingly simple table structure ( with sample rows ) :
PERMISSION_ID P_ID DESCRIPTION DESIGNATION
============= ==== =========== =======
1776 Null Z-ENGINEERING 88888
1860 Null Z-LABORATORY 88888
1909 Null Z-RESEARCH 88888
1902 Null Z-PLANT 88888
1905 Null Z-SOFTWARE DESIGN 88888
1903 Null Z-BLANKET 88888
1904 Null Z-OFFICE 88888
40000 1909 James Gosling 67890
40001 1909 Edgar Codd 21135
40002 1904 Alan Turing 85542
40003 1909 Z-SOFTWARE DESIGN 88888
40004 1905 Dennis Ritchie 12111
40005 1909 Z-OFFICE 88888
40006 1776 Brian Kernighan 84251
40007 1904 Z-ENGINEERING 88888
Explanation of table structure :
(1) All rows with P_ID = {Null} are the root groups, and they all have a uniform DESIGNATION of 88888.
(2) All rows that starts with 40000 are memberships; under these memberships scheme, a root group can become a member of another root group, cascaded, which means that root groups can be members of another root group or they can be members of multiple root groups ( and cascaded even ), as long as the cascade do not end up in a circular reference, or an endless cycle. The idea here is so that the memberships for both groups and human members can be chained.
(3) Both root groups and human memberships are stored in the same table above, using rules (1) & (2) as the logic.
(4) No additional table may be added to this table in order to implement rules (1), (2), & (3); columns may be added, though.
(5) Use only plain SQL statements ( SELECT, CONNECT BY, PRIOR, NOCYCLES, etc ... ); PL/SQL, functions, and procedures are strongly discouraged.
Desired output of the query is as follows :
The SELECT query should return a list of all human members which belongs to a specific root group. Using the example table above, the initial query should have the following intended result set:
(start with p_id = 1909) -- 1909 is root group Z-RESEARCH
PERMISSION MEMBERS
========== =======
40000 James Gosling
40001 Edgar Codd
40003 Z-SOFTWARE DESIGN
40005 Z-OFFICE
However, Z-SOFTWARE DESIGN has it's own member , Dennis Ritchie, so the updated result set should be :
PERMISSION MEMBERS
========== =======
40000 James Gosling
40001 Edgar Codd
40004 Dennis Ritche
40005 Z-OFFICE
Same is true for Z-OFFICE, but it's member is another root group, Z-ENGINEERING, whose member is Brian Kernighan, thus the final result set list would be as follows, which is the final intended list :
PERMISSION MEMBERS
========== =======
40000 James Gosling
40001 Edgar Codd
40004 Dennis Ritche
40002 Alan Turing
40006 Brian Kernighan
The problem now would be, how to generate the final intended list using the table scheme illustrated above, with no additional tables, but possible additional columns, using Oracle's SELECT ... START WITH ... CONNECT BY PRIOR ?
Any theoretical advice is greatly appreciated; even our consulting firm cannot solve this problem. Coming here to the Oracle Forums itself is a last resort. Perhaps someone here can take a gander at this seemingly simple problem. Fact is, solving this problem has lots of applications, one of which is the ability to mimic Outlook's nested distribution groups list.
Thank you so much for your time.Ok, first time back at a database, here my 2 cent.
I use the with-clause to simulate your sample-data, i have also added the master-reference-column i suggested. Just restrict the result to the group you want to. (i only put the id's in the query)
WITH DATA AS (SELECT 1776 PERMISSION_ID, TO_NUMBER(NULL) P_ID, TO_NUMBER(NULL) MASTER_PERMISSION_ID, 'Z-ENGINEERING' DESCRIPTION, 88888 DESIGNATION FROM DUAL
UNION ALL
SELECT 1860, Null, Null, 'Z-LABORATORY', 88888 FROM DUAL
UNION ALL
SELECT 1909, Null, Null, 'Z-RESEARCH', 88888 FROM DUAL
UNION ALL
SELECT 1902, Null, Null, 'Z-PLANT' ,88888 FROM DUAL
UNION ALL
SELECT 1905, Null, Null, 'Z-SOFTWARE DESIGN', 88888 FROM DUAL
UNION ALL
SELECT 1903, Null, Null, 'Z-BLANKET', 88888 FROM DUAL
UNION ALL
SELECT 1904, Null, Null, 'Z-OFFICE', 88888 FROM DUAL
UNION ALL
SELECT 40000, 1909, Null, 'James Gosling', 67890 FROM DUAL
UNION ALL
SELECT 40001, 1909, Null, 'Edgar Codd', 21135 FROM DUAL
UNION ALL
SELECT 40002, 1904, Null, 'Alan Turing', 85542 FROM DUAL
UNION ALL
SELECT 40003, 1909, 1905, 'Z-SOFTWARE DESIGN', 88888 FROM DUAL
UNION ALL
SELECT 40004, 1905, Null, 'Dennis Ritchie', 12111 FROM DUAL
UNION ALL
SELECT 40005, 1909, 1904, 'Z-OFFICE', 88888 FROM DUAL
UNION ALL
SELECT 40006, 1776, Null, 'Brian Kernighan', 84251 FROM DUAL
UNION ALL
SELECT 40007, 1904, 1776, 'Z-ENGINEERING', 88888 FROM DUAL
SELECT GROUP_REFERENCE,
THE_USERS.PERMISSION_ID,
USER_NAME,
FROM_GROUP
FROM (SELECT PERMISSION_ID,
DESCRIPTION FROM_GROUP,
CONNECT_BY_ROOT(PERMISSION_ID) GROUP_REFERENCE
FROM (SELECT PERMISSION_ID, TO_NUMBER(NULL) P_MASTER, DESCRIPTION
FROM DATA
WHERE DESIGNATION=88888
AND P_ID IS NULL
UNION ALL
SELECT MASTER_PERMISSION_ID PERMISSION_ID, P_ID P_MASTER, DESCRIPTION
FROM DATA
WHERE DESIGNATION=88888
AND P_ID IS NOT NULL
CONNECT BY PRIOR PERMISSION_ID=P_MASTER
START WITH P_MASTER IS NULL
) THE_GROUPS,
(SELECT P_ID PERMISSION_REFERENCE,
PERMISSION_ID,
DESCRIPTION USER_NAME
FROM DATA
WHERE MASTER_PERMISSION_ID IS NULL
AND P_ID IS NOT NULL
) THE_USERS
WHERE THE_GROUPS.PERMISSION_ID=THE_USERS.PERMISSION_REFERENCE
Maybe you are looking for
-
PI 7.11 ESB hangs on startup
Hi Gurus Would love your help with this one! We have a PI 7.11 SP4 landscape and a particular user cannot launch the QA server's Enterprise Services Builder. She used to be able to, but now when she clicks on the link, she gets the login prompt, ent
-
Transaction Launcher : How to get return parameters from an external URL
Hello, We need to launch an external URL in the Web Client UI. After the URL is launched, the user does some processing which results in some output values. These value have to be passed back to the Web Client UI and become a part of the quotation he
-
Stressed out Student!!!! Servets
Well lads hows it goin. Listen im getting an error trying to connect to the database to return some information. The class and the servlet app are both compiling fine, and SHOULD work, but there acting like proper knobs and i dont know why. I think i
-
How to adjust start up for iTunes Helper.exe
XP Home, SP2, iTunes 7.1.0.59, in msconfig there are two start up iTunes releated items: iTuneshelper.exe, qttask.exe I wish to tweak my system and remove these from Starting up, thus, msconfig startup, and access them only when I start iTunes or som
-
Rebate conditions with mulitple validity dates
Hello, I have an urgent requirement. My customer wants to define different rebate rate by date in one agreement like normal pricing condition types. for an example, The validity date of the agreement is 1/1/2008 ~ 3/31/2008 Rebate conditons are as f