NULL in PL/SQL SELECT statement..
Hi allI need to use as a result of a SELECT statement in my function to get PCODE from the table. Cur_rec here. CODE comes from cursor that runs before the declaration.
SELECT PCODE in v_pcode TABLE_XYZ where CODE = cur_rec. CODE and PCODE = 'VIEW '.
Now the problem is the part of the CODE has all the information in the table TABLE_XYZ. In this case, it triggers an error NO_DATA_FOUND. To solve it, I can put a part of the EXCEPTION and handle it. But I think in another way...
If there is no data for a CODE, the default value of v_pcode would be 'No Code'. I tried to use the NVL function, but it does not work here as a SQL SELECT statement.
Can someone give an idea how to achieve this?
Hello
declare
...
v_cnt number;
begin
SELECT count(*)
into v_cnt
from TABLE_XYZ
where CODE = cur_rec.CODE
and PCODE='SEE';
if v_cnt=0 then
v_pcode = 'No code';
else
v_pcode = 'SEE';
end if;
end;
Bartek
Tags: Database
Similar Questions
-
What is the sql SELECT statement to list all service names in the database?
What is the sql SELECT statement to list all service names in the database?
I tried
SELECT name FROM dba_services
But a long with valid service, he list also some other documents that are not the names of services.Hello
You can try this query:
select name, value from v$parameter where name = 'service_names';
Hope this helps.
Best regards
Jean Valentine -
SQL SELECT statement as a parameter in the procedure of string
Hi all
I'm new to PL/SQL and I must get a procedure as parameter select SQL select statement as a VARCHAR and the production output the result of the statement with a few changes. Can someone help me solve this problem?
A possibility I thought at was to use a REF CURSOR. The following example works but binds me to a specific table (in the example of the "customers" table). However, I need the ability to specify arbitrary tables in the select statement parameter.
My idea was to modify this example to work in the following code, but it does not work (I get a compile error):SET SERVEROUTPUT ON DECLARE TYPE my_cur IS REF CURSOR; query_cursor my_cur; BEGIN OPEN query_cursor FOR 'SELECT * FROM customers'; DECLARE record_type customers%ROWTYPE; BEGIN LOOP FETCH query_cursor INTO record_type; EXIT WHEN query_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE('some output ... '); END LOOP; END; CLOSE query_cursor; END; /
Does anyone has an idea how can I solve my problem?SET SERVEROUTPUT ON DECLARE TYPE my_cur IS REF CURSOR; query_cursor my_cur; BEGIN OPEN query_cursor FOR 'SELECT * FROM customers'; DECLARE record_type query_cursor%ROWTYPE; BEGIN LOOP FETCH query_cursor INTO record_type; EXIT WHEN query_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE('some output ... '); END LOOP; END; CLOSE query_cursor; END; /
Thank you very much!
(I'm using Oracle 11 g)This can help.
Re: Dynamic Extraction on dynamic Sql -
Hey everybody,
First of all, Yes, I searched through the 8.5 database schema guide. As I went through the scheme, I've developed some ideas on how to collect the data you want. However, if someone has already developed or found the SQL statements (which I'm sure that someone already has) it would help by reducing to the minimum of the buggs in my data collection program.
All these statistics must be grouped by CSQ and selected for a certain time interval (
and ). That is, levels of 1 hour. I have no problem to get a list of results and then perform v.f. to achieve the desired final result. Also, if I need to run several select statements for tables of essentially two join, please include two statements. Finally, I saw the RtCSQsSummary table, but I need to collect data for the past, not at this time. 1 total calls presented by the CSQ
2. total number of calls answered by the CSQ
3 total number of calls abandoned by the CSQ
4. percentage of calls abandoned by CSQ (if it is not stored in the database, I think:
/ ) 5. average abandon time in seconds (if it is not stored in the DB, I think: sum (
) / ) 6. service level - % calls answered in 90 seonds by a set of skills (I have seen metServiceLevel in the ContactQueueDetail table; however, I need to find how to configure this threshold for application)
7. average speed of response by CSQ
8 average conversation by CSQ calls
9. the aggregates connected full-time resources or agents CSQ
10. resources/agents of CSQ ready time
I realize that some of them should be easy to find (as I always am search in the guide of db schema), but I was reading how a new record is created for each step of the call so I could easily see how I could get inaccurate information without properly developed select statements.
Any help will be greatly appreciated.
Brendan
Brendan,
I read your message very well.
You have the schema of database with tables and description. each table has its associated tables (connected with primary and foreign keys). I think you should start the tables to determine what you need.
Cisco uses the stored procedure to prepare the reports. the stored procedure is 'sp_csq_interval' to create the report.
Activity report of Queue Service contact"
HTH
Anas
Please note all useful posts
-
With the help of inplace column number of the column name in the SQL Select statement
Is it possible to execute instructions select sql with the number of columns in
place names of columns?
Run SQL
Is it possibleselect AddressId,Name,City from Address
Thanks in advanceselect 1,2,5 from Address
You can extract the names of the columns for user_tab_columns
withSELECT Column_name FROM user_tab_columns where table_name = 'MY_TABLE' and Column_id in (1,2,5)
Use dynamic SQL and then the result to get the values.
But as others already mentioned, this wil it be given incorrect if your table is changed.
-
A loop using the SQL select query.
Hello
I wanted to know, if the concept of loop is possible thanks to the SQL select statement.
For example
=======
Table T1
Col1 Col2
Slim 10
I want to write a query in such a way, so that when I get the result of the query, I format below.
Col1 Col2
Slim 10
Slim 10
Slim 10
Basically what I'm trying to achieve is, I have a table with two columns and it has a single line displayed above.
I want to display this line several times as the output of my SELECT query.
Let me know, if this target is achievable.
Kind regards
SaurabhLike this?
SQL> SELECT 10 col1, 'Sourabh' col2 2 FROM DUAL 3 CONNECT BY LEVEL <= 3; COL1 COL2 ---------- ------- 10 Sourabh 10 Sourabh 10 Sourabh SQL>
-
Handeling string in a select statement
Hi friends,
I would like to know how I can handle strings in a SQL select statement?
SQL > SELECT 'string' from dual
Her send me errors when the string is "or &." For example, as if string = Mike & Karen project
You can also tell me wht other characters, such as ', & can make a question?
Thank you.citing alternative:
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14251/adfns_sqltypes.htm#sthref377 -
JDBC PreparedStatement gives null after the execution of a valid SELECT statement
Hello
I have the following code:
As you can see, this function executes a select statement. Before I continue, let me first say that executing the exact same statement in PL/SQL Developer (external program) gives correct/expected results. In addition, run this on my Windows gives correct results environment. I seem to have this problem only on my Unix (SunOS) environment.public static String GetJobLogLocation(Connection connection, int jobId) throws SQLException { String sqlstr = "SELECT LOGFILE_NAME FROM apps.fnd_concurrent_requests WHERE REQUEST_ID = ?"; PreparedStatement prest = connection.prepareStatement(sqlstr); prest.setInt(1, jobId); ResultSet rs1 = prest.executeQuery(); String rv = null; if (rs1.next()) { rv = rs1.getString(1); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + rv); } rs1.close(); prest.close(); return rv; }
in any case, I get out of this function (running against my Unix environment, of course):
+ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > + null
The thing is, it doesn't error out, which means that the result set contains a string, but the string is returned to me with the null value, even if there is a real valid result (that is, in this case, a path).
Someone has an idea, what happens? I tried to use ojdbc6.jar AND ojdbc14.jar is, with the same results. I just don't understand...
Thank you.
Published by: 964530 on 4 January 2013 14:31
Published by: EJP on 01/07/2013-17:48: added {noformat}{noformat} tags and removed your bizarre bold formatting. Please do this properly in future.
ASCI says:
I'm glad that this is a not prove to be a stupid question. At least I'm feeling a little justified due to this fact.There is no stupid question...; (o)
So what remains is: your selection is too early. Can join after insertion, update to each line to trigger the table that loggs insert/update timestamp and the contents of the LOGFIILE_NAME field?
Good bye
DPT -
How can I include multiple SELECT statements in a PL/SQL?
I want to be able to include multiple SELECT statements in a PL/SQL script. Here are 2 of my SELECT statements. They compile them and run successfully, but when I try to run them together, I get the error: ORA-06550: line 26, column1: PLS-00103: encountered the symbol "BEGIN." Line 26, it is where the 2nd script begins. Thank you in advance for your help!
Set serveroutput on
DECLARE
v_item_type VARCHAR2 (20);
number of v_total_count;
v_approved VARCHAR2 (20);
number of v_apprv_count;
BEGIN
SELECT ITEM_TYPE, count (*)
IN v_item_type, v_total_count
Of
APPLSYS. WF_ITEMS
WHERE
ITEM_TYPE = "GLBATCH" AND
End_date is not null
ITEM_TYPE GROUP;
dbms_output.put_line ('Item_type: ' | v_item_type);
dbms_output.put_line ('Count: ' | v_total_count);
END;
BEGIN
SELECT B.ACTIVITY_RESULT_CODE, COUNT (*)
IN v_approved, v_apprv_count
Of
APPLSYS. WF_ITEMS, A.
APPLSYS. B WF_ITEM_ACTIVITY_STATUSES,
APPLSYS. FND_USER C.
APPLSYS. FND_USER D
WHERE
A.ITEM_TYPE = B.ITEM_TYPE AND
A.ITEM_KEY = B.ITEM_KEY AND
A.ITEM_TYPE = "GLBATCH" AND
A.END_DATE is not null AND
A.OWNER_ROLE = C.USER_NAME and
B.ACTIVITY_RESULT_CODE = "APPROVED" AND
B.ASSIGNED_USER is not null and
B.ASSIGNED_USER (+) = D.USER_NAME
GROUP BY b.activity_result_code;
dbms_output.put_line (' approved: ' | v_approved);
dbms_output.put_line ('Count: ' | v_apprv_count);
END;Try this,
Declare v_item_type Varchar2(20); v_total_count Number; v_approved Varchar2(20); v_apprv_count Number; Begin -- First SQL SELECT ITEM_TYPE ,Count(*) INTO v_item_type ,v_total_count FROM APPLSYS.WF_ITEMS WHERE ITEM_TYPE = 'GLBATCH' AND END_DATE Is Not Null Group BY ITEM_TYPE; dbms_output.put_line('Item_type: ' || v_item_type); dbms_output.put_line('Count: ' || v_total_count); -- Second SQL SELECT B.ACTIVITY_RESULT_CODE ,Count(*) INTO v_approved ,v_apprv_count FROM APPLSYS.WF_ITEMS A ,APPLSYS.WF_ITEM_ACTIVITY_STATUSES B ,APPLSYS.FND_USER C ,APPLSYS.FND_USER D WHERE A.ITEM_TYPE = B.ITEM_TYPE AND A.ITEM_KEY = B.ITEM_KEY AND A.ITEM_TYPE = 'GLBATCH' AND A.END_DATE Is Not Null AND A.OWNER_ROLE = C.USER_NAME AND B.ACTIVITY_RESULT_CODE = 'APPROVED' AND B.ASSIGNED_USER Is Not Null AND B.ASSIGNED_USER(+) = D.USER_NAME Group BY b.activity_result_code; dbms_output.put_line('Approved: ' || v_approved); dbms_output.put_line('Count: ' || v_apprv_count); End;
Hope this helps,
Christian Balz -
How to format the output of a .sql script that has select statements.
Hello
I have a .sql script which is having several select statements. Each Select statement is to have hundreds of Table columns.
When we run the .sql script, we are unable to read the output.
Please let know us the commands that we include for better readable output format.
You work with the lin standard set 80.
Increase this setting to set lin 3000 or more. -
Is it possible to use the record type or a PL/SQL table in the Select statement
Hi all
My requirement is that.
I want to write a query and write a function, function, I want to return multiple columns at the same time in a Select statement.
I select the return values in the Select no statement in a PL/SQL block.
Is it possible to use the PL/SQL Table or Variable of Type record, or any other method in the statement Select?
Please help me understand the solution.
Kind regards830960 wrote:
do we like it?In general, Yes, if the function is a function table, you can do something like:
select t.col1, t.col2, f.col1, f.col2, f.col3 from table_name t, table(some_table_function(param1,...paramN)) f /
SY.
-
Skip and capture the Oracle SQL record dirty in a select statement
Hello
I have the Oracle Oracle 11.2.0.4 database when I run a select query.
Question:
10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.
Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error
OK, you have several TO_DATE functions fed a string that is built on the fly. At least part of the time, the chain that is built does not match the date format mask used.
For example:
TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")
"SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12. You'll have to do an analysis on this column. From its data and how that is managed by to_char. What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?
As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second). ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.
-
the combination of two select statements to increase the maintainability and performance
Hi SQL Experts,
I use the Version of Oracle 11g DB and got both of the statements below.
My mind can´t get his head around it how and if these two can be combined.
They look like they could, but I can't figure out how... and I don't mean with a UNION ALL operation
My main goal is a gain in performance and maintainability.
SELECT *.
OF T_TEMP_42 T1 WHERE T1. MATRIX_2 IS NULL AND
(T1. BL_CODE | T1. YASSINE | T1. MATRIX_1 | T1. FIRMTYPE)
PO NO
(
SELECT BL_CODE. YASSINE | MATRIX_1 | FIRMTYPE
OF T_TEMP_41, WHERE MATRIX_2 IS NULL).
------------------------------------------------------------------------------------
SELECT *.
OF T_TEMP_42 T1 WHERE T1. MATRIX_2 IS NOT NULL AND
(T1. BL_CODE | T1. YASSINE | T1. MATRIX_1 | T1. MATRIX_2 | T1. FIRMTYPE)
PO NO
(
SELECT BL_CODE. YASSINE | MATRIX_1 | MATRIX_2 | FIRMTYPE
OF T_TEMP_41, WHERE MATRIX_2 IS NOT NULL
);
Thanks for your suggestions.
Try this
SELECT *.
OF T_TEMP_42 T1
WHERE (BL_CODE, YASSINE, MATRIX_1, FIRMTYPE, MATRIX_2) NOT IN (SELECT BL_CODE, YASSINE, MATRIX_1, FIRMTYPE, T_TEMP_41 MATRIX_2)
It came off really simple... maybe too simple
-
Hello community, I have a problem when creating a function. The purpose of this function is to check the table of weather gave yesterday or not. We must check this on different tables on different sachems. We are creating a function with input variables.
CREATE OR REPLACE FUNCTION IN_SCHEMA.IS_YDAYDATA_TO_TABLE
(
in_schema IN VARCHAR2,
in_tablename IN VARCHAR2,
in_datefield IN VARCHAR2,
)
RETURNS INTEGER
AS
-Declaring variables
v_is_true INTEGER.
BEGIN
SELECT
CASE
WHEN MAX (in_datefield) = TRUNC(SYSDATE-1)
THEN 1
ON THE OTHER
0
END
IN
v_is_true
Of
in_schema.in_tablename
;
RETURN v_is_true;
END;
/
When creating, I got error: [error] ORA-00942 (44:19): PL/SQL: ORA-00942: table or view does not exist
How to use the values of the input variables on the table select statement names?
Hello
Here's a way you can use dynamic SQL statements for this task:
CREATE OR REPLACE FUNCTION IS_YDAYDATA_TO_TABLE
(
in_schema IN VARCHAR2,
in_tablename IN VARCHAR2,
in_datefield IN VARCHAR2,
in_first_date DATE DEFAULT SYSDATE - 1,.
in_last_date DATE by DEFAULT NULL
)
RETURNS INTEGER
AS
-IS_YDAYDATA_TO_TABLE returns 1 if in_schema.in_tablename.in_datefield
-contains all the dates in the in_first_date of the range through included in_last_date
- and it returns 0 if there is no such lines.
-If in_last_date is omitted, the search only the data on in_first_date.
-If in_first_date is omitted, it defaults to yesterday.
-Time parts of the in_first_date and in_last_date are ignored.
-Declaring variables
sql_txt VARCHAR2 (1000);
v_is_true INTEGER.
BEGIN
sql_txt: = 'SELECT COUNT (*).
|| 'FROM ' | in_schema | '.' || in_tablename
|| 'WHERE ' | in_datefield | ' > =: d1'
|| «AND» | in_datefield | '< > >
|| 'AND ROWNUM = 1';
dbms_output.put_line (sql_txt |) '= sql_txt in IS_YDAYDATA_TO_TABLE"); -For debugging
Sql_txt EXECUTE IMMEDIATE
IN v_is_true
With the HELP of TRUNC (in_first_date) - d1
TRUNC (NVL (in_last_date
in_first_date
)
) + 1 -- d2
;
RETURN v_is_true;
END is_ydaydata_to_table;
/
DISPLAY ERRORS
If you must use dynamic SQL statements, put all the SQL statement in a single string variable, such as sql_txt in the example above. In this way, you can easily see exactly what will be executed. Comment out the call to dbms_output under test is completed.
Try to write functions that will address not only the question that you have now, but similar questions that you may have in the future. For example, now that interest you only to the verification of the data of yesterday, but later, you might want to check another day or range of days. The above function combines the convenience of a function simple (looks like yesterday data if you don't tell him otherwise) with the power of a more complex function (you can use the same function to check any day or range of days).
-
Error PLS-00428: an INTO clause in this SELECT statement
Dear Experts,
I'm new to PL/SQL programming
I try to run the following query, I get the error message.
Please help me solve the error.
declare
var_cd number (20);
Start
If: P1_TYP_CAT is not null then
SELECT max (CAT_cd + 1) as var_cd from IM_AST_CAT by CAT_cd;
insert into IM_AST_CAT (CAT_NM, CAT_CD) values ((upper (:P1_TYP_CAT)),(:var_cd));
on the other
RAISE_APPLICATION_ERROR ('-20001,' both Department and location must be provided ");
end if;
end;
In PL/SQL, must be used IN the clause when using SELECT statements.
SELECT max (CAT_cd + 1) as var_cd
in variable - it is missing in your code
from IM_AST_CAT by CAT_cd;
Your code should be
declare
var_cd number (20);
Start
If: P1_TYP_CAT is not null then
SELECT max (CAT_cd + 1).
in var_cd
of IM_AST_CAT
order of CAT_cd;insert into IM_AST_CAT (CAT_NM, CAT_CD) values (upper(:P1_TYP_CAT), var_cd);
on the other
RAISE_APPLICATION_ERROR ('-20001,' both Department and location must be provided ");
end if;
end;
For example:
DECLARE
l_first_name varchar2 (100);
BEGIN
Select first_name
in l_first_name
employees
where employee_id = 100;
END;
Post edited by: Suri
Maybe you are looking for
-
I have a pc running Windows 7 64 bit. I have the latest Firefox V 10.0.1, automatically updated several days ago. Everything was fine until about an hour before, when I launched Firefox and all the Favicons for my favorites are blank dotted squares.
-
Toshiba 40TL900A: no connection to Toshiba Places
Hello I'm the Australia my model TV set is 40TL900A with the latest firmware. I have the same problems as the original since 13/01/2014 poster.I couldn't get past the Toshiba Places menu, it's just loading and loading with nothing happens.I updated t
-
Windows 8.1 battery drain
So when I'm with Windows 8, my battery can last up to 5 hours But now I've updated Windows 8.1 [(avec une installation propre) and the maximum is 3 hours.] HP 14 E019TX - laptop is 11 months old
-
Hello I collect the load data and discharge of a capacitor during different periods. Using the attached circuit, what the best way to define the sampling per channel and I can apply hours measuring without getting the slow operation systems. Thank yo
-
TMS 13.0.1 MXP upgrades
When I program updates through TMS, the status of activity shows that the upgrade was successful, but in reality no update has been made and I web in each system and the upgrade manually. I downloaded the file of the software of the same shared drive