SQL doubt
Hi all,
SELECT plaf~matnr plaf~gsmng INTO CORRESPONDING FIELDS OF TABLE it_plan FROM plaf
INNER JOIN mara ON
plaf~matnr EQ mara~matnr
WHERE plaf~matnr IN s_matnr AND
plaf~plwrk EQ p_werks AND
mara~mtart EQ 'FERT' AND
plaf~umskz EQ 'X' AND
plaf~paart EQ 'LA' AND
plaf~pedtr IN s_date.
"In this query i want to get total quantity (gsmng) of particular material with in date range...
for example :
now I'm getting like this..
MATNR GSMNG
947604015 10.00 "13.12.2007
947604015 20.00 "16.12.2007
947604016 45.00 "11.12.2007
947604015 15.00 "18.12.2007
but I want like this...
947604015 30.00
947604016 60.00
please give me some suggetions....
You can try with the following code:
SELECT plafmatnr sum(plafgsmng) as gsmng
INTO CORRESPONDING FIELDS OF TABLE it_plan FROM plaf
INNER JOIN mara ON
plafmatnr EQ maramatnr
WHERE plaf~matnr IN s_matnr AND
plaf~plwrk EQ p_werks AND
mara~mtart EQ 'FERT' AND
plaf~umskz EQ 'X' AND
plaf~paart EQ 'LA' AND
plaf~pedtr IN s_date
group by plaf~matnr.
This will help you to collect the figures per matnr from the ddatabase at one shot.
Regards,
Anindita
Similar Messages
-
Hi ABAP Gurus,
Please help me in solving following ABAP SQL doubt.
In the table Zonfig there are two fields: FNAME and REQFLAG
FNAME.....REQFLAG
S1...........X
S2...........X
S3..........._
S4...........X
Other table T_Zconfig has one field : XNAME
XNAME
S1
S3
Now I have to select REQFLAG from Zconfig table for the values of field XNAME in T_Zconfig table.
That is in this case for FNAME S1 and S2 in Zonfig I need to fetch REQFLAG since in XNAME in T_Zonfig we just have S1 and S2.
Points will be surly awarded...
Thanks.Hi ABAP Gurus,
Please help me in solving following ABAP SQL doubt.
In the table Zonfig there are two fields: FNAME and REQFLAG
FNAME.....REQFLAG
S1...........X
S2...........X
S3..........._
S4...........X
Other table T_Zconfig has one field : XNAME
XNAME
S1
S3
Now I have to select REQFLAG from Zconfig table for the values of field XNAME in T_Zconfig table.
That is in this case for FNAME S1 and S3 in Zonfig I need to fetch REQFLAG since in XNAME in T_Zonfig we just have S1 and S3.
Points will be surly awarded...
Thanks. -
Pl/sql doubts clarification
Hi,
I have doubts with some of the questions given below:
1.Identify two features of obfuscation. (Choose two.)
A. The Import and Export utilities accept wrapped files.
B. SQL' Plus cannot process the obfuscated source files.
C. Only the wrap utility can obfuscate multiple programs at a time.
D. Both the DBMS_DDL package and the Wrap utility can obfuscate multiple programs at a time.
E. The source code is visible only through the DBA_SOURCE view and not through the USER_SOURCE or
ALL_SOURCE View
ANSWER: A and C(not sure)
2.The anonymous block gives an error on execution. What Is the reason?
A.
The assignment in line 7 is not valid.
B.
The SQL does not support the Boolean data type.
C.
A null value cannot be applied to the bind arguments In the using clause in line 10
D.
The names of bind variables must be the same as the using clause bind arguments in line 10
Answer: A or B.
3.SCOTT executes the procedure as follows:
SQL>SET SERVEROUTPUT ON
SQL>EXEC read_file ('MY_DIR', FACULTYLIST.TXT')
What is the outcome?
A.
It goes into an infinite loop.
B.
It executes successfully and displays only the list of faculty names.
C.
It does not execute and displays an error message because the end-of-file condition is not taken care of.
D.
It executes successfully and displays the list of faculty names followed by a “no data found” error message.
Answer: D is right or not
4.Which two tasks should be created as functions instead of as procedures? (Choose two.)
A.
reference host or bind variables in a PL/SQL block of code
B.
tasks that compute and return multiple values to the calling environment
C.
tasks that compute a value that must be returned to the calling environment
D.
tasks performed in SQL that increase data independence by processing complex data analysis within the Oracle server, rather than by retrieving the data into an application
Answer: A and B(not sure B or C).
Please,kindly reply to me ASAP.
Thank you,
karthi
Edited by: 998492 on Apr 7, 2013 2:32 AM1. Thare are so many problems in this code. I will list a few.
1. You cant specify the size of an argument in a procedure.
2. You can call this procedure only once in a schema, coz the name of the table to be created is static.
3. *No need to create the table dynamically*. You can create the table at the design time and truncate/insert as required.
Even it will not be required, I hope, to meet your requirement( A Cursor will be enough).
4. In the EMP table join_date should be of date datatype. If it is already a date, no need of to_date in the procedure.
5. Not using BIND Variables.
6. Variable "v_cmd" is not declared2. Search for "string aggregation " in this forum and show us what you tried so far. -
Declare
cursor curname is select * from employees where employee_id in (100,101);
v_emp curname%rowtype;
begin
open curname;--this stage the query is executed and datas are available in Active set which is the area oracle allocated for this cursor
loop
fetch curname into v_emp;
exit when curname%notfound;--first value is retrieved in the above statement and the cursor is pointing to second value in the active set..so this wil result no
--bt for the next loop here cursor should nt point to anything and this should exit.. Am i ryt? becaz there are totally two values.. tis should exit witout printing..
-- i mean.. eventhough tis query gives two values second value should not be printed becaz we have given exit before before dbms_ouput statement.. ple help
--mainly I am getting confused about the functionalities of exit explain please.....
dbms_output.put_line('name:'||v_emp.first_name);
end loop;
close curname;
end;
tis is confusing somebody help please?? and gimme the link where can I find docs to clarify these doubts.. explain about for loop for the same please...
I am starter in PL/SQL please help.....
Edited by: user12869307 on Apr 19, 2010 2:43 PMHi,
Please don't post unformatted code.
Indent line to show the extent of BEGIN, LOOP and similar statements.
Don't put too much on one line.
For example:
Declare
cursor curname is select *
from employees
where employee_id in (100,101);
v_emp curname%rowtype;
begin
open curname; -- this stage the query is executed and
-- datas are available in Active set which is
-- the area oracle allocated for this cursor
loop
fetch curname into v_emp;
exit when curname%notfound; -- first value is retrieved in the above
-- statement and the cursor is pointing to
-- second value in the active set..so this wil result no
-- bt for the next loop here cursor should nt point to
-- anything and this should exit Am i ryt? becaz there
-- are totally two values.. tis should exit witout printing wiout
-- doing the below print..
dbms_output.put_line ('name:' || v_emp.first_name);
end loop;
close curname;
end;
/Type these 6 characters:
(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
I'm not sure I understand your comments. It would help if you posted the contents of your table, and the output you get, and asked a question specifically about those results, such as "Why do the results include ... ? Isn't the code supposed to ... because of ... in the data?"
If the query returns 2 rows, then FETCH will work 2 times with %FOUND = true. Only after the 3rd call to FETCH will %NOTFOUND become true. -
Hi All,
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
can we use MERGE SQL like this
CREATE OR REPLACE PROCEDURE SAVE_PCS_SUMMARY(vENTRYDATE IN VARCHAR2, vCELLID IN VARCHAR2, vMACHINEID IN VARCHAR2, vFREQUENCY IN CHAR)
IS
l_sqlstr varchar2(32000);
BEGIN
l_sqlstr := PCS_PC_SUMMARY.GETSQLFORPLDAY_TIME(vENTRYDATE, vCELLID, vMACHINEID, vFREQUENCY); -- RETUEN SQL STATEMENT
MERGE INTO PCS_TL_MONTH_COMP P
USING ( SELECT * FROM l_sqlstr) S -- HERE I HAVE PROBLEM
ON (P.COMPANYID = S.FACT_COMPANYID AND P.ENTRYDATE = S.PRLM_ENTRYDATE)
WHEN NOT MATCHED THEN
INSERT VALUES(l_sqlstr); - HERE I HAVE PROBLEM
END;
My problem is i cannot use the stores sql string in USING clause and to INSERT values.
or is any other way there?Sorry for not giving full details,
I try to explain.
Requirement is Generate Summary Data
Source tables are PCS_TL_MST, PCS_TL_DTL
Target table is PCS_TL_MONTH_COMP
Specification is to select data from the source tables to target tables whenever source tables are getting affected
Why I have used dynamic sql is that the select query will have lot of calculations that will be another query
Whole things are in a package
CREATE OR REPLACE PACKAGE BODY RRLVASPRD_APR13.PCS_PC_SUMMARY
IS
PROCEDURE SAVE_PCS_SUMMARY(vENTRYDATE IN VARCHAR2, vCELLID IN VARCHAR2, vMACHINEID IN VARCHAR2, vFREQUENCY IN CHAR)
IS
l_sqlstr varchar2(32000);
BEGIN
l_sqlstr := GETSQLFORPLDAY_TIME(vENTRYDATE, vCELLID, vMACHINEID, vFREQUENCY);
MERGE INTO PCS_TL_MONTH_COMP P
USING ( l_sqlstr) S
ON (P.COMPANYID = S.FACT_COMPANYID AND P.ENTRYDATE = S.PRLM_ENTRYDATE)
WHEN NOT MATCHED THEN
INSERT VALUES(l_sqlstr);
WHEN MATCHED THEN
DELETE WHERE PRLM_ENTRYDATE = vENTRYDATE AND MACHINEID = vMACHINEID
INSERT INTO PCS_TL_MONTH_COMP SELECT * FROM || l_sqlstr;
END;
FUNCTION GetSubSqlForIns RETURN VARCHAR2
IS
vSQLSTR VARCHAR2(30000);
CURSUBLOSS SYS_REFCURSOR;
PLCMKEY PCS_TL_LOGCONFIGURATION.PLCM_KEYID%TYPE;
PARAMNAME PCS_TL_LOGCONFIGURATION.PLCM_PARAMETERNAME%TYPE;
PARAMCODE PCS_TL_LOGCONFIGURATION.PLCM_PARAMETERCODE%TYPE;
ISLOSS PCS_TL_LOGCONFIGURATION.PLCM_ISLOSS%TYPE;
MAPFIELD PCS_TL_LOGCONFIGURATION.PLCM_MAPFIELD%TYPE;
MAPCOLUMNNO PCS_TL_LOGCONFIGURATION.PLCM_MAPCOLUMNNO%TYPE;
N NUMBER;
BEGIN
vSQLSTR := ', SUM(QAACCEPTEDQTY) AS QAACCEPTEDQTY, (' || PCS_PC_PRODUCTIONCALC.CELLEFF || ') AS CELLEFF
, SUM(' || PCS_PC_PRODUCTIONCALC.GetExpectedProductionVAS(NULL,NULL,'N','N') || ') AS THEORITICALPRODUCTION
, SUM(' || PCS_PC_PRODUCTIONCALC.GetOperatingTime(NULL,NULL,'N', 'N') || ') AS NETOPERATINGTIME
, SUM(DECODE(NVL(STARTUPLOSS_ML,0),0,0,1)) AS STARTUPLOSS_ML_INS
, SUM(DECODE(NVL(MINORSTOPPAGELOSS_ML,0),0,0,1)) AS MINORSTOPPAGELOSS_ML_INS
, SUM(DECODE(NVL(SPEEDLOSS_ML,0),0,0,1)) AS SPEEDLOSS_ML_INS
, SUM(DECODE(NVL(OPERATINGMOTIONLOSS_ML,0),0,0,1)) AS OPERATINGMOTIONLOSS_ML_INS
, SUM(DECODE(NVL(LINEORGANISATIONLOSS_ML,0),0,0,1)) AS LINEORGANISATIONLOSS_ML_INS
, SUM(DECODE(NVL(LOGISTICSLOSS_ML,0),0,0,1)) AS LOGISTICSLOSS_ML_INS
, SUM(DECODE(NVL(MEASURINGANDADJLOSS_ML,0),0,0,1)) AS MEASURINGANDADJLOSS_ML_INS
, SUM(DECODE(NVL(ENERGYLOSS_ML,0),0,0,1)) AS ENERGYLOSS_ML_INS
, SUM(DECODE(NVL(DIETOOLANDJIGLOSS_ML,0),0,0,1)) AS DIETOOLANDJIGLOSS_ML_INS
, SUM(DECODE(NVL(YIELDLOSS_ML,0),0,0,1)) AS YIELDLOSS_ML_INS
, SUM(DECODE(NVL(DEFECTSANDREWORKLOSS_ML,0),0,0,1)) AS DEFECTSANDREWORKLOSS_ML_INS ';
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(EQUIPMENTFAILURE_ML,0) ,0,0,1)) AS EQUIPMENTFAILURE_ML_INS ';
N:=PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL(CURSUBLOSS, 'EF');
LOOP
FETCH CURSUBLOSS INTO PLCMKEY,PARAMNAME,PARAMCODE,ISLOSS,MAPFIELD,MAPCOLUMNNO;
EXIT WHEN CURSUBLOSS%NOTFOUND;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(' || MAPFIELD || ' ,0),0,0,1)) AS ' || PARAMCODE || '_INS';
END LOOP;
N:=PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL(CURSUBLOSS, 'SETUPANDADJ');
LOOP
FETCH CURSUBLOSS INTO PLCMKEY,PARAMNAME,PARAMCODE,ISLOSS,MAPFIELD,MAPCOLUMNNO;
EXIT WHEN CURSUBLOSS%NOTFOUND;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(' || MAPFIELD || ' ,0),0,0,1)) AS ' || PARAMCODE || '_INS';
END LOOP;
N:=PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL(CURSUBLOSS, 'TOOLCHANGELOSS');
LOOP
FETCH CURSUBLOSS INTO PLCMKEY,PARAMNAME,PARAMCODE,ISLOSS,MAPFIELD,MAPCOLUMNNO;
EXIT WHEN CURSUBLOSS%NOTFOUND;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(' || MAPFIELD || ' ,0),0,0,1)) AS ' || PARAMCODE || '_INS';
END LOOP;
N:=PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL(CURSUBLOSS, 'SHUTDOWNLOSS');
LOOP
FETCH CURSUBLOSS INTO PLCMKEY,PARAMNAME,PARAMCODE,ISLOSS,MAPFIELD,MAPCOLUMNNO;
EXIT WHEN CURSUBLOSS%NOTFOUND;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(' || MAPFIELD || ' ,0),0,0,1)) AS ' || PARAMCODE || '_INS';
END LOOP;
N:=PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL(CURSUBLOSS, 'MANAGEMENTLOSS');
LOOP
FETCH CURSUBLOSS INTO PLCMKEY,PARAMNAME,PARAMCODE,ISLOSS,MAPFIELD,MAPCOLUMNNO;
EXIT WHEN CURSUBLOSS%NOTFOUND;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(' || MAPFIELD || ' ,0),0,0,1)) AS ' || PARAMCODE || '_INS';
END LOOP;
vSQLSTR := vSQLSTR || ',SUM(DECODE(NVL(COMMONUTILITYLOSS_SL,0),0,0,1)) AS COMMONUTILITYLOSS_SL_INS ';
vSQLSTR := vSQLSTR || ',SUM(DECODE(NVL(DEFECTTIME_SL,0),0,0,1)) AS DEFECTTIME_SL_INS ';
vSQLSTR := vSQLSTR || ',SUM(NVL(' || PCS_PC_PRODUCTIONCALC.GetMapFieldForLoss('PM','N') || ',0)) AS PLANNEDMAINTENANCE ';
--+NVL(' || PCS_PC_PRODUCTIONCALC.GetMapFieldForLoss('BBM','N') || ',0)
vSQLSTR := vSQLSTR || ', SUM(NVL(' || PCS_PC_PRODUCTIONCALC.GetMapFieldForLoss('UPM','N') || ',0) ) AS ANCILLARYEQPFAIL ';
-- + NVL(' || PCS_PC_PRODUCTIONCALC.GetMapFieldForLoss('ANCEQUFAIL','N') || ',0)
vSQLSTR := vSQLSTR || ', SUM(NVL(REJECTEDQTY,0) + NVL(REWORKQTY,0)) AS DEFECTSANDREWORKLOSS_ML ';
vSQLSTR := vSQLSTR || ', SUM(NVL(' || PCS_PC_PRODUCTIONCALC.GetMapFieldForLoss('QAREJECTION','N') || ',0)) AS QAREJECTION ';
RETURN vSQLSTR;
End;
FUNCTION GetMainSql(vCELLID IN VARCHAR2, vMACHINEID IN VARCHAR2, vforcalc IN BOOLEAN DEFAULT FALSE, vFREQUENCY IN CHAR, vRECURSION IN NUMBER DEFAULT 1) RETURN VARCHAR2
IS
vSQLSTR VARCHAR2(30000);
BEGIN
vSQLSTR := ' SELECT ' ;
IF vFREQUENCY = 'M' THEN
IF vRECURSION = 1 THEN
vSQLSTR := vSQLSTR || ' SELECT TO_CHAR(PRLM_ENTRYDATE,''MON-YYYY'') PRLM_ENTRYDATE';
ELSE
vSQLSTR := vSQLSTR || ' SELECT ''01-'' || PRLM_ENTRYDATE ';
END IF;
ELSE
vSQLSTR := vSQLSTR || ' SELECT PRLM_ENTRYDATE';
END IF;
vSQLSTR := vSQLSTR || ',FACT_COMPANYID, PRLM_FACTORYID, PRLM_SECTIONID, CELLID ';
IF TRIM(vMACHINEID) <> '-99' AND TRIM(vMACHINEID) <> '{}' AND TRIM(vMACHINEID) IS NOT NULL THEN
vSQLSTR := vSQLSTR || ', MACHINEID ';
End If;
vSQLSTR := vSQLSTR || ', 0 AS PRODANDREJCTION,
SUM(NVL(CALENDARTIME,0)) AS CALENDARTIME,
SUM(NVL(NOPLANINMINS,0)) AS NOPLANINMINS,
SUM(NVL(PRODUCEDQTY,0)) AS PRODUCEDQTY,
SUM(NVL(MCHAVAILABLETIME,0)) AS MCHAVAILABLETIME,
SUM(NVL(UNACCOUNTEDTIME,0)) AS UNACCOUNTEDTIME,
SUM(NVL(DEFECTTIME_SL,0)) AS DEFECTTIME_SL,
SUM(NVL(PRODUCTIONLOSSES,0)) AS PRODUCTIONLOSSES,
SUM(NVL(EQUIPMENTFAILURE_ML,0)) AS EQUIPMENTFAILURE_ML,
SUM(NVL(SETUPANDADJUSTMENT_ML,0)) AS SETUPANDADJUSTMENT_ML,
SUM(NVL(TOOLCHANGELOSS_ML,0)) AS TOOLCHANGELOSS_ML,
SUM(NVL(STARTUPLOSS_ML,0)) AS STARTUPLOSS_ML,
SUM(NVL(MINORSTOPPAGELOSS_ML,0)) AS MINORSTOPPAGELOSS_ML,
SUM(NVL(SPEEDLOSS_ML,0)) AS SPEEDLOSS_ML,
SUM(NVL(SHUTDOWNLOSS_ML,0)) AS SHUTDOWNLOSS_ML,
SUM(NVL(MANAGEMENTLOSS_ML,0)) AS MANAGEMENTLOSS_ML,
SUM(NVL(COMMONUTILITYLOSS_SL,0)) AS COMMONUTILITYLOSS_SL,
SUM(NVL(OPERATINGMOTIONLOSS_ML,0)) AS OPERATINGMOTIONLOSS_ML,
SUM(NVL(LINEORGANISATIONLOSS_ML,0)) AS LINEORGANISATIONLOSS_ML,
SUM(NVL(LOGISTICSLOSS_ML,0)) AS LOGISTICSLOSS_ML,
SUM(NVL(MEASURINGANDADJLOSS_ML,0)) AS MEASURINGANDADJLOSS_ML,
SUM(NVL(ENERGYLOSS_ML,0)) AS ENERGYLOSS_ML,
SUM(NVL(DIETOOLANDJIGLOSS_ML,0)) AS DIETOOLANDJIGLOSS_ML,
SUM(NVL(YIELDLOSS_ML,0)) AS YIELDLOSS_ML,
SUM(NVL(LOADINGTIME,0)) AS LOADINGTIME,
SUM(NVL(PRODUCTIONAVLTIME,0)) AS PRODUCTIONAVLTIME,
SUM(NVL(EFFECTIVEPRODMINS,0)) AS EFFECTIVEPRODMINS ';
IF vforcalc = TRUE THEN
vSQLSTR := vSQLSTR || ',' || PCS_PC_PRODUCTIONCALC.GETROA(NULL,NULL, 'N') || ' AS ROA ';
vSQLSTR := vSQLSTR || ',' || PCS_PC_PRODUCTIONCALC.GETROP(NULL,NULL, 'N') || ' AS ROP ';
vSQLSTR := vSQLSTR || ',' || PCS_PC_PRODUCTIONCALC.GETROQ(NULL,NULL) || ' AS ROQ ';
vSQLSTR := vSQLSTR || ',' || PCS_PC_PRODUCTIONCALC.GETOEE(NULL,NULL, 'N') || ' AS OEE ';
ELSE
vSQLSTR := vSQLSTR || ', SUM(NVL(ROA,0)) AS ROA, SUM(NVL(ROP,0)) AS ROP,
SUM(NVL(ROQ,0)) AS ROQ, SUM(NVL(OEE,0)) AS OEE ';
END IF;
vSQLSTR := vSQLSTR || ', SUM(NVL(PLANNEDQTY,0)) AS PLANNEDQTY
, SUM(NVL(PRODUCEDQTY,0) + NVL(PRODUCTIONLOSSES,0)) AS SUMOFALLQTY ';
vSQLSTR := vSQLSTR || ' , SUM(NVL(THEORITICALCYCLETIME,0)) AS THEORITICALCYCLETIME ';
DBMS_OUTPUT.PUT_LINE('GETMAINSQLFORPLDAY');
GEN_PC_COMMONFUNCTIONS.GEN_FN_ADDDEBUGSQL(vSQLSTR,'PCS_PC_PRODUCTIONCALC', 'GETMAINSQLFORPLDAY');
RETURN vSQLSTR;
End;
FUNCTION GetSubSql RETURN VARCHAR2
IS
vSQLSTR VARCHAR2(30000);
vSUBLOSSCOL VARCHAR2(10000);
SubLossSql VARCHAR2(10000);
VALU NUMBER;
BEGIN
vSQLSTR := ',SUM(NVL(DEFECTSANDREWORKLOSS_ML,0)) AS DEFECTSANDREWORKLOSS_ML
, SUM(NVL(DEFECTSANDREWORKLOSS_ML_INS,0)) AS DEFECTSANDREWORKLOSS_ML_INS
, SUM(NVL(STARTUPLOSS_ML_INS,0)) AS STARTUPLOSS_ML_INS
, SUM(NVL(MINORSTOPPAGELOSS_ML_INS,0)) AS MINORSTOPPAGELOSS_ML_INS
, SUM(NVL(SPEEDLOSS_ML_INS,0)) AS SPEEDLOSS_ML_INS
, SUM(NVL(OPERATINGMOTIONLOSS_ML_INS,0)) AS OPERATINGMOTIONLOSS_ML_INS
, SUM(NVL(LINEORGANISATIONLOSS_ML_INS,0)) AS LINEORGANISATIONLOSS_ML_INS
, SUM(NVL(LOGISTICSLOSS_ML_INS,0)) AS LOGISTICSLOSS_ML_INS
, SUM(NVL(MEASURINGANDADJLOSS_ML_INS,0)) AS MEASURINGANDADJLOSS_ML_INS
, SUM(NVL(ENERGYLOSS_ML_INS,0)) AS ENERGYLOSS_ML_INS
, SUM(NVL(DIETOOLANDJIGLOSS_ML_INS,0)) AS DIETOOLANDJIGLOSS_ML_INS
, SUM(NVL(YIELDLOSS_ML_INS,0)) AS YIELDLOSS_ML_INS ';
SubLossSql := PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL1('EF');
If TRIM(SubLossSql) IS NOT NULL Then
vSQLSTR := vSQLSTR || ',' || SubLossSql || ' AS EQUIPMENTFAILURE_ML_INS ';
Else
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(EQUIPMENTFAILURE_ML,0),0,0,1)) AS EQUIPMENTFAILURE_ML_INS ';
End If;
SubLossSql := PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL1('SETUPANDADJ');
If TRIM(SubLossSql) IS NOT NULL Then
vSQLSTR := vSQLSTR || ',' || SubLossSql || ' AS SETUPANDADJUSTMENT_ML_INS ';
Else
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(SETUPANDADJUSTMENT_ML,0),0,0,1)) AS SETUPANDADJUSTMENT_ML_INS';
End If;
SubLossSql := PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL1('TOOLCHANGELOSS');
If TRIM(SubLossSql) IS NOT NULL Then
vSQLSTR := vSQLSTR || ',' || SubLossSql || ' AS TOOLCHANGELOSS_ML_INS ';
Else
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(TOOLCHANGELOSS_ML,0),0,0,1)) AS TOOLCHANGELOSS_ML_INS';
End If;
SubLossSql := PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL1('SHUTDOWNLOSS');
If TRIM(SubLossSql) IS NOT NULL Then
vSQLSTR := vSQLSTR || ',' || SubLossSql || ' AS SHUTDOWNLOSS_ML_INS ';
Else
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(SHUTDOWNLOSS_ML,0),0,0,1)) AS SHUTDOWNLOSS_ML_INS ';
End If;
SubLossSql := PCS_PC_PRODUCTIONCALC.PCS_FN_GETSUBLOSSSQL1('MANAGEMENTLOSS');
If TRIM(SubLossSql) IS NOT NULL Then
vSQLSTR := vSQLSTR || ',' || SubLossSql || ' AS MANAGEMENTLOSS_ML_INS ';
Else
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(MANAGEMENTLOSS_ML,0),0,0,1)) AS MANAGEMENTLOSS_ML_INS ';
End If;
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(COMMONUTILITYLOSS_SL,0),0,0,1)) AS COMMONUTILITYLOSS_SL_INS ';
vSQLSTR := vSQLSTR || ', SUM(DECODE(NVL(DEFECTTIME_SL,0),0,0,1)) AS DEFECTTIME_SL_INS ';
vSQLSTR := vSQLSTR || ', SUM(NVL(PLANNEDMAINTENANCE,0)) AS PLANNEDMAINTENANCE ';
vSQLSTR := vSQLSTR || ', SUM(NVL(ANCILLARYEQPFAIL,0)) AS ANCILLARYEQPFAIL ';
vSQLSTR := vSQLSTR || ', SUM(NVL(THEORITICALPRODUCTION,0)) AS THEORITICALPRODUCTION ';
vSQLSTR := vSQLSTR || ', SUM(NVL(NETOPERATINGTIME,0)) AS NETOPERATINGTIME ';
vSQLSTR := vSQLSTR || ', SUM(NVL(QAACCEPTEDQTY,0)) AS QAACCEPTEDQTY ';
vSQLSTR := vSQLSTR || ', SUM(NVL(CELLEFF,0)) AS CELLEFF ';
vSQLSTR := vSQLSTR || ', SUM(NVL(QAREJECTION,0)) AS QAREJECTION ';
GEN_PC_COMMONFUNCTIONS.GEN_FN_ADDDEBUGSQL(vSQLSTR,'PCS_PC_PRODUCTIONCALC', 'GETSUBSQLFORPLDAY');
RETURN vSQLSTR;
End;
FUNCTION GETSQLFORPLDAY_TIME(vENTRYDATE IN VARCHAR2, vCELLID IN VARCHAR2, vMACHINEID IN VARCHAR2, vFREQUENCY IN CHAR) RETURN VARCHAR2
IS
vSQLSTR VARCHAR2(30000);
vPLDTLTBL VARCHAR2(200);
vSECTIONID VARCHAR2(20);
N NUMBER;
BEGIN
IF TRIM(vMACHINEID) IS NOT NULL AND TRIM(vMACHINEID) <> '{}' THEN
SELECT CELL_SECTIONID INTO vSECTIONID FROM GEN_TL_MACHINEMST, GEN_TL_CELLMST WHERE MCHM_CELLID = CELL_KEYID AND MCHM_KEYID = vMACHINEID;
ELSIF TRIM(vCELLID) IS NOT NULL AND TRIM(vCELLID) <> '{}' THEN
SELECT CELL_SECTIONID INTO vSECTIONID FROM GEN_TL_CELLMST WHERE CELL_KEYID = vCELLID;
END IF;
IF TRIM(vSECTIONID) IS NOT NULL THEN
N:=PCS_FN_GETPLDETAILSTBL(vPLDTLTBL,vSECTIONID,'Y');
END IF;
vSQLSTR := GetMainSql(vCELLID, vMACHINEID,FALSE,vFREQUENCY);
vSQLSTR := vSQLSTR || GetSubSql;
vSQLSTR := vSQLSTR || ' FROM (';
vSQLSTR := vSQLSTR || GetMainSql(vCELLID, vMACHINEID,TRUE,vFREQUENCY);
vSQLSTR := vSQLSTR || GetSubSqlForIns;
vSQLSTR := vSQLSTR || ' FROM ' || vPLDTLTBL || ', PCS_TL_MST ';
vSQLSTR := vSQLSTR || ' GEN_TL_FACTORYMST ';
vSQLSTR := vSQLSTR || ' WHERE TRUNC(PRLM_ENTRYDATE) = ' || CHR(39) || vENTRYDATE || CHR(39) || '
AND PRLM_KEYID = PLMASTERID AND CELLID = ' || CHR(39) || vCELLID || CHR(39);
-- AND COMPLETEDFLAG = ''C''
vSQLSTR := vSQLSTR || ' PRLM_FACTORYID = FACT_KEYID ';
IF TRIM(vMACHINEID) <> '-99' AND TRIM(vMACHINEID) <> '{}' AND TRIM(vMACHINEID) IS NOT NULL THEN
vSQLSTR := vSQLSTR || ' AND MACHINEID = ' || CHR(39) || vMACHINEID || CHR(39);
End If;
--vSQLSTR := vSQLSTR || ' AND PRLM_LOGTYPE = ''H'' ';
vSQLSTR := vSQLSTR || ' GROUP BY ';
IF vFREQUENCY = 'M' THEN
vSQLSTR := vSQLSTR || ' TO_CHAR(PRLM_ENTRYDATE, ''MON-YYYY'')';
ELSE
vSQLSTR := vSQLSTR || ' PRLM_ENTRYDATE ';
END IF;
vSQLSTR := vSQLSTR || ' , FACT_COMPANYID, PRLM_FACTORYID, PRLM_SECTIONID, CELLID ';
If TRIM(vMACHINEID) <> '-99' AND TRIM(vMACHINEID) <> '{}' AND TRIM(vMACHINEID) IS NOT NULL THEN
vSQLSTR := vSQLSTR || ', MACHINEID ';
End If;
vSQLSTR := vSQLSTR || ')';
vSQLSTR := vSQLSTR || ' GROUP BY ';
IF vFREQUENCY = 'M' THEN
vSQLSTR := vSQLSTR || ' TO_CHAR(PRLM_ENTRYDATE, ''MON-YYYY'')';
ELSE
vSQLSTR := vSQLSTR || ' PRLM_ENTRYDATE ';
END IF;
vSQLSTR := vSQLSTR || ' , FACT_COMPANYID, PRLM_FACTORYID, PRLM_SECTIONID, CELLID ';
If TRIM(vMACHINEID) <> '-99' AND TRIM(vMACHINEID) <> '{}' AND TRIM(vMACHINEID) IS NOT NULL THEN
vSQLSTR := vSQLSTR || ', MACHINEID ';
End If;
GEN_PC_COMMONFUNCTIONS.GEN_FN_ADDDEBUGSQL(vSQLSTR,'PCS_PC_PRODUCTIONCALC', 'GETSQLFORPLDAY_TIME');
RETURN vSQLSTR;
End;
END PCS_PC_SUMMARY; -
Dear buddies,
I have a problem to fix.
I have a table:
t1
STKey: Just a primary key created using a sequence
Stable: source table name
SKey: Key that matches with the target table
Ttable: Target table's name
Tkey: The primary key in the target table
t2
FK: the same as t1's STKeyy
Source: The column in the source table
Target: The matching column from source to target
So the same FK can have more than 1 row
This is for some updating purpose.
Now my problem is I need to perform an update or create another table if the values of the columns are not the same, for example:
t1
STKey | STable | SKey | TTable | TKey
27 old_staff trim(staffid) new_staff trim(Staff_code)
t2
FK | Source | Target
27 address_1 home_address <- these are column names
27 address_2 office_address <- these are column names
I need to create a script which will check if both the columns given has the same value
like : if address_1 = home_address
How can I do this? It should be a script which runs for thousands of rows.
Please guide me?
Thanks in advance.select * from table_info;
create table t1
*(STKey varchar2(10),*
STable varchar2(30),
SKey varchar2(200),
TTable varchar2(30),
TKey varchar2(10),
TLastUpdate varchar2(30)
drop sequence seq_counter;
CREATE SEQUENCE seq_counter
MINVALUE 0
MAXVALUE 100
START WITH 1
INCREMENT BY 1;
-- to insert the source table details
insert into t1 (STKey, Ttable, tkey, TLastUpdate)
select seq_counter.nextval, tablename, 'LegacyKey', 'LastUpdateDate'
from table_info;
update t1
set stable = 'staff_details'
where ttable = 'S_Recruitment';
update t1
set skey = 'trim(staff_id) || ''_'' || trim(dep_no) || ''_'' || trim(campus_id)'
where ttable = 'S_Recruitment';
-- to create the columns table
drop table t2;
create table t2
*(FK number(10),*
Source varchar2(150),
Target varchar2(300)
--this has to be done manually*
insert into t2
select * from*
*(select 27, 'MIGRATION', 'created user' from dual) union*
*(select 27, to_char(sysdate), 'createddate' from dual) union*
*(select 27, 'case when trim(conditional) = ''1'' then ''Y'' else null end', 'Is_Borderline' from dual)*
I want to do something like this:
Update S_Recruitment
set dep_no = staff_details.dep_no
where legacykey = (select 'trim(staff_id) || ''_'' || trim(dep_no) || ''_'' || trim(campus_id)' from staff_details);
or
create table GenericUpdate
*(objectid varchar2(20),*
columnName varchar2(50),
NewValue varchar2(300));
insert into GenericUpdate
select a.objectid, b.target, ....
from S_Recruitment a , t1 b, t2 c
where a.legacykey = (trim(staff_id) || ''_'' || trim(dep_no) || ''_'' || trim(campus_id))
and c.fk = b.stkey
*.* -
hi all
observe the below query
SELECT RTRIM(XMLAGG(xmlelement (e,ename,',')).EXTRACT('//text()')) a
FROM EMP
group by deptno
it gives output as below
A
KING,MILLER,CLARK,
JONES,ADAMS,SMITH,FORD,SCOTT,
BLAKE,JAMES,TURNER,MARTIN,WARD,ALLEN,
CF_TYPE,CF_TYPE,CF_TYPE,
in the above output fourth row is having duplicate names
but i need to avoid duplicates and print all distinct as below
A
KING,MILLER,CLARK,
JONES,ADAMS,SMITH,FORD,SCOTT,
BLAKE,JAMES,TURNER,MARTIN,WARD,ALLEN,
CF_TYPE,Please help me on this.
am using oracle Application Express 4.0.2.00.08thanks for all in advanceHi,
WITH data AS
SELECT deptno, ename, DENSE_RANK() OVER (PARTITION BY deptno ORDER BY ename) rn
FROM emp
SELECT DISTINCT deptno, LTRIM(SYS_CONNECT_BY_PATH(ename,','),',') ename
FROM data
WHERE CONNECT_BY_ISLEAF = 1
CONNECT BY PRIOR rn + 1 = rn
AND PRIOR deptno = deptno
START WITH rn = 1
; -
HOW TO FIND THE RETURNING DATA TYPE OF THE FOLLOWING:
SELECT NVL(A,B) FROM DUAL ;
HERE 'A' HAS CHARACTER DATA TYPE AND 'B' HAS NUMBER DATA TYPE?
pLEASE HELPNVL is an overloaded function with different in params, Depending on the in-params, the return-value is defined. So look up the onlinehelp for the return-type. If you want to "proof", you could create a view with that expression as column and check USER_TAB_COLUMNS for the datatype.
-
Hi,
I have a table that shows the people who have barrowed a book :
book_id user_id date_barrowed date_returned
16 340 01/05/1998 05/05/1998
16 340 20/02/2007 25/02/2007
17 340 01/05/1998 05/10/1998
17 450 04/12/1998
23 500 20/02/2007 25/02/2007
65 510 18/03/2008
76 7540 05/07/2008 10/07/2008How can I query those who have presently barrowed a book that they have already barrowed before ?
Thank you.Pls., re-post your SQL and PL/SQL doubts in PL/SQL
Regards,
Sabdar Syed. -
hi frs,
i have a doubt in sql query.
this is my query
select * from scott.emp where comm like '3%'it will fetch all the values starting with 3.
2nd query
select * from scott.emp where comm like '%'this will give all the values except null. but i want to get null values also.how can i get i have used following query
select * from scott.emp where comm like '%' or comm is not nullits working whether there is an any other option.because i am going to use similar kind of condition in my report query if iam going to use or in where condition it will affect the performance.
pls help
regards
RajeshHi Rajesh,
I'm sure I do not understand your requirement correctly.
You say you want to retrieve rows that have or have not null in colum 'comm', right?
If so, simply get rid of this part of your where clause (provided you have more conditions).
select * from scott.emp shall be enough.
Cheers,
Guido -
Hi Friends,
Am using Oracle 10g DB - 10.2.0.3.0
I have some basic doubts regarding sql query execution by Oracle.
Say, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
Same thing happens for every 15 minutes.(Any specific reason for this ??).
It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this.
Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query everytime I run. How do I improve the performance in this situation (May sound odd :)).
Regards,
MarlonSay, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
Same thing happens for every 15 minutes.(Any specific reason for this ??).
It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this. Share Pool caches the SQL statement. So when you execute the same SQL for the second time it goes for a soft parse. But this is not the only reason for the query to execute faster the second time. The time difference between a soft parse and hard parse is very minimal. So it really does not matter unless you are executing the same query several number of times.
The thing that really matters is the Data Buffer Cache. That is the rows that are selected by your query are cached into the Data buffer that is available in the SGA. So for the next time when you run the same query the IO is reduced as the data is available in the memory and you don't have to go to your disk to get the data.
But the data in Data Buffer is not persistent, meaning it follows the FIFO rule. That is first in first out. When the Data Buffer is full the content of the buffer is removed in the FIFO order.
Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query every time I run. How do I improve the performance in this situation (May sound odd :)). Like the Data Buffer the Shared Pool is also maintained in the FIFO order. So if the query is still in the Shared Pool the query will be soft parsed else it will be hard parsed. But its very rare that you will have a query in your Shared Pool for a month. -
Hi all...
I am beginner of oracle sql 10g and also trainee.. i know why v r using views but im getting confused to use views bcoz im little weak to understand in english.. i have one doubt is it possible to use views in same table? can any one tell me?
ThankzThink of a view as a stored query. A view can be created by querying one table or from a complex query joining many tables. But the end-user just sees the result, which looks like a table of rows to them. Generally you aren't trying to hide implementation but either hide sensitive data or filter unimportant data. For instance, let's say you have an employee table that has all sorts of information about an employee. Some of that information is sensitive (like their salary, any medical information, etc.). Other information (e.g., what department they work in, who their manager is) is not sensitive. If all that information is in one table but you want to hide the salary information from everyone but the HR dept., then you could make a view that selects the non-sensitive columns from the employee table and only grant select on that view to non-HR personnel. If you wanted managers only to have access to certain data in the employee table for employees that they manage, you could make a view for that as well.
-
Hi,
First doubt:
When I execute the SQL*LOADER the following error occurs:
SQL*LOADER-350: Erro de sintaxe na linha 6.
Esperando especificagco de coluna valida, ", ou ")"; localizado "VARCHAR2".
(NAME POSITION(01:64) VARCHAR2,
^
The control file is like this:
ARQUIVO1.CTL
LOAD DATA
INFILE 'C:\testes\ARQUIVO1.TXT'
BADFILE 'C:\testes\ARQ1_ERRO.TXT'
TRUNCATE
INTO TABLE CARLA.TEMP_TESTE
(NAME POSITION(01:64) VARCHAR2,
ENDERECO POSITION(65:81) VARCHAR2,
TELEFONE POSITION(82:95) VARCHAR2)
Somebody, knows what happens?
Second doubt: How can I execute sqlldr in a procedure? Is there any command that simulates the DOS line command? Is there any example?
Thanks
CarlaHere are a couple of links to pages on Tom Kyte's site. The first one shows how to use java to enable execution of an operating system file from pl/sql. Just store your SQL*Loader commands in a .bat file and use Tom's code to enable execution of the .bat file from pl/sql. The second one uses utl_file that acts like a "mini sqlloader" in pl/sql and includes an example that demonstrates some data validation, checking for numeric values. I have used both methods succesfully. For large files, SQL*Loader is much faster than utl_file.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:952229840241
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:464420312302 -
Andrew - one more doubt in the donsample.sql file,it is urgent
Andrew,
I believe you can answer this ,i hope i am not trying too much on your patience.Thanks .I am connected to the oracle server.In that i execute a procedure which i believe is executing on the oracle server.i supply arguments to it .The arguement is a file on my local directory .The error code follows:-
I have problem running a oracle procedure which uses a xml parser built on java libraries.When i executed this procedure the following error came:-
SQL> execute domsample('\oraclexdk\xdk\demo\plsql\parser','family.xml','error.txt');
BEGIN domsample('\oraclexdk\xdk\demo\plsql\parser','family.xml','error.txt'); END;
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.SecurityException: relative pathnames are not
allowed(\oraclexdk\xdk\demo\plsql\parser)
ORA-06512: at "SYS.XMLPARSERCOVER", line 0
ORA-06512: at "SYS.XMLPARSER", line 144
ORA-06512: at "IWADM.DOMSAMPLE", line 77
ORA-06512: at line 1
Do you know something about this .ie. classpath variables or something like that.if you want the domsample arguement syntax for further clarifications ,i am enclosing this in the following lines.The setbasedir(p,dir) prompts for a parser object and a complete directory path.what i give here is the path on my local directory and i think this creates the error.
How do i rectify this error.is it on my(client) side or the server side.If it on the oracle server side or my side can you tell me what went wrong.The parser and the dom package everything else is working fine.It is really urgent ,andrew.This is holding up all the work.The arguement syntax help says on 'dir' that this is a pointer to external file system .I have a confusion that whether this refers to external file system of the server or the client.if so form the server how to route it to the client directory or should i have a space on the server, upload this file and execute the domsample.sql file.Can you clear this concept for me.
'dir' - must point to a valid directory on the external file system
and should be specified as a complete path name
'inpfile' - must point to the file located under 'dir', containing the
XML document to be parsed
'errfile' - must point to a file you wish to use to record errors; this
file will be created under 'dir'
I know i might be bugging you ,but your answers are really great.Thanks.
regards
gopalI seem to have this error with both windows and unix directory space.Please help me with debugging this .I am really struck with it.The error occurs at the same line when executed with the file on the unix server.
SQL> execute domsample('/user/sb8066/','family.xml','error.txt');
BEGIN domsample('/user/sb8066/','family.xml','error.txt'); END;
ERROR at line 1:
ORA-20100: Error occurred while parsing: Permission denied
ORA-06512: at "SYS.XMLPARSER", line 22
ORA-06512: at "SYS.XMLPARSER", line 69
ORA-06512: at "IWADM.DOMSAMPLE", line 63
ORA-06512: at line 1
I won't clutter the forum.just to get your attention,i hope you can help me solving this problem,please can you see this thread,because in future i will be using this only to contact you.Thanks for the continued help.The windows space idea was not used.Many configurations had to be changed.Can you note what is peculiar at line 22 ,line 69.line 63 of domsample reads is just an 'end-if';I will expecting your answer as soon as possible.
regards
gopal -
Doubt in case statement in sql
hiii guruz
i am writing a code in HR schema for case its like this it works fine as i want it to
select commission_pct ,
case
when commission_pct is null
then 'null'
else 'not null' end "comm"
from employees
but when i write+
select commission_pct ,
case commission_pct
when null then 'null'
else 'its not null'
end "chk"
from employees
the o/p that i get is only in every field
its not null
why is it not showing
*'null'*
as it was supposed to show it
thksoracle 10g
using sql *plus
Maybe you are looking for
-
Creation of control file failed
Hi all when i am trying to create control file my terminal is hanging on following stage SQL> @/u02/ORACLE/orcldb/9.2.0/dbs/contrl.sql ORACLE instance started. Total System Global Area 581506668 bytes Fixed Size 452204 bytes Variable Size 402653184 b
-
Error when trying to create an Application System
Hi everybody, I've installed on my computer Personal Oracle 8i and Designer 6.0. For the installation, I used valuable informations from someone called Mark (he's on this list - thank you very much) but I still have a problem: when I try to create a
-
We have internal and external load Step 1 is internal load from source sql to destination flat file and step 2 is external load from source flat file to destination sql Step 1 :Using DTS I am extracting DateTime source Field"2007-08-20 10:46:00.710"
-
TIFF unsupported compression type
Dear all I want to get the RGB values of every pixel of a TIFF-File. Therefore I use JAI. My first steps are... PlanarImage image = JAI.create("fileload", in_path); BufferedImage bufferedImage = image.getAsBufferedImage(); ...because in other cases (
-
Hello, To implement a customer solution i need to know the ASN status. Does anyone know the table or function to obtain it??? I have found table CRM_JEST table but the status number doesn't mean anything for me Thanks in advance Nacho