sql

ORA-00904: “Good”: invalid identifier ORA-06512

两盒软妹~` 提交于 2021-02-17 05:37:27
问题 1.getting invalid identifier error while updating row_val variable char value 'Good' into the table 2.while inserting number it's working fine but strings its getting errors 3. declare count_temp number; csv_data varchar2(1000); val varchar2(100); row_val varchar2(100); sqlcmd varchar2(3000); col_name varchar2(100); col_data varchar2(100); begin csv_data:='good,son,r,,happy'; col_data:='varchar2(100)'; select regexp_count(csv_data, ',') + 1 into count_temp from dual; dbms_output.put_line

Split a CSV field into different rows in SQL

亡梦爱人 提交于 2021-02-17 05:34:06
问题 A colleague of mines encountered this problem while working on a COBOL program and eventually solved it at the application level. Still I am curious if it is possible to solve it on the data access level, with SQL. This is somehow related to this other question, but I'd like to use only ANSI SQL. I'm looking for a single SQL select query that acts on a VARCHAR field that contains variable length CSV rows. The purpose of the query is to split every CSV field in its own result set row. Here is

Oracle [Procedure] - Sum function ignores WHERE clause

穿精又带淫゛_ 提交于 2021-02-17 05:32:06
问题 I have a problem with a ORACLE Procedure, it seems that SELECT SUM ignores my WHERE clause, and Sums up ALL of the columns instead of only those that i want to (deptno). However if i use one of this functions like this for example : select SUM(SAL) AS SALSUM FROM SCOTT.EMP WHERE SCOTT.EMP.DEPTNO = 10; It displays the proper SUM. What may be the problem? Thanks for help. CREATE OR REPLACE PROCEDURE PROCEDURE1(numerdept IN number, money OUT number) IS SALSUM NUMBER; COMMSUM NUMBER; WYJATEK

Summing up Hours and Minutes in MS Access - How to deal with huge datasets

荒凉一梦 提交于 2021-02-17 05:27:47
问题 So I have a Table in MS Access 2010 which looks like this: Date Pers. ID Dauer Tätigkeit 10.04.2016 10 01:15 11.05.2016 5 05:00 ... I want to get the total hours of "Dauer Tätigkeit". All entries in the "Dauer Tätigkeit" are in the Date Format. The formula below is supposed to do the job for listing the end in a Format like '1346:30'. It actually does the job for small datasets. The dataset I have to work with though has around 800 entries with an hourly average of 3 hours. So i am expecting

convert date yyyy-mm-dd to mmm-yy SQL Server 2016

随声附和 提交于 2021-02-17 05:20:25
问题 I want to convert date yyyy-mm-dd (stored as a date format) to mmm-yy format. There are no exact matches in the prior questions on the site. I have tried substrings and convert function, was considering creating a scalar function but its taking me a while and hoping someone has an easy solution. 回答1: You can construct the format using string operations: select left(datename(month, datecol), 3) + '-' + right(datename(year, datecol), 2) Or using format() : select format(datecol, 'MMM-yy') 回答2:

Row for each date from start date to end date

余生长醉 提交于 2021-02-17 05:18:25
问题 What I'm trying to do is take a record that looks like this: Start_DT End_DT ID 4/5/2013 4/9/2013 1 and change it to look like this: DT ID 4/5/2013 1 4/6/2013 1 4/7/2013 1 4/8/2013 1 4/9/2013 1 it can be done in Python but I am not sure if it is possible with SQL Oracle? I am having difficult time making this work. Any help would be appreciated. Thanks 回答1: connect by level is useful for these problems. suppose the first CTE named " table_DT " is your table name so you can use the select

Stored Procedure with multi value parameter behaving strangely

穿精又带淫゛_ 提交于 2021-02-17 05:10:12
问题 I created a stored procedure in sql server to feed SSRS to allow it to accept Multiple values. I have created it and when I used it in my report or execute it in sql server I have the following error message. Is there anything i am missing? Thanks Msg 207, Level 16, State 1, Line 35 Invalid column name 'London'. This is my sample data. feel free to create table with it DECLARE @MyTables AS TABLE (ID INT, City VARCHAR(100)) INSERT INTO @MyTables VALUES (1,'London'), (2,'Chester'), (3,'Luton'),

How to count the rows which contains non zero values in sql

最后都变了- 提交于 2021-02-17 05:09:16
问题 SELECT round(COUNT(dmd_1wk),2) AS NBR_ITEMS_1WK FROM table; Field dmd_1wk has so many zeros in it. How do I Count the non zero values? 回答1: Methinks bluefeets answer is probably what you are really looking for, as it sounds like you just want to count non-zeros; but this will get you a count of zero and non-zero items if that's not the case: SELECT ROUND(SUM(CASE NVL(dmd_1wk, 0) = 0 THEN 1 ELSE 0 END), 2) AS "Zeros", ROUND(SUM(CASE NVL(dmd_1wk, 0) != 0 THEN 1 ELSE 0 END), 2) AS "NonZeros"

Calculate difference using nearest (oldest date) using same column

左心房为你撑大大i 提交于 2021-02-17 04:48:09
问题 I have the (simplified) database table A below which holds both the Mother Batch Purity Value and the Batch Puritys (all batches are made from the previous "Mother Batch". I am trying to figure out how to pull out via SQL the Batch Purity and the Difference between the Batch Purity and the previous Mother Batch. The sample names always remain the same, but can be numerous batch numbers Table A Sample Name | Purity | Date (DD/MMM/YY) ---------------+-----------+----------------- Mother Batch |

Select data between 2 dates and average hourly output

别说谁变了你拦得住时间么 提交于 2021-02-17 03:55:32
问题 I am have a series of temperature data which is gathered every minute and put into a MySQL database. I want to write a query to select all temperatures for the last 24 hours then group and average them into hours. Is this possible via a SQL command? I think its a case of selecting all records between the two date/times, but thats the point I get stuck. Data Example: ID Temp Timestamp 3922 22 2015-11-17 14:12:23 3923 22 2015-11-17 14:13:23 3924 22.05 2015-11-17 14:14:23 3925 22.05 2015-11-17