sql

ORA-01722: invalid number

I'm getting the infamous invalid number Oracle error. Hibernate is issuing an INSERT with a lot of columns, I want to know just the name of the column giving the problem. Is it possible? I hate Oracle messages, in 15 years they haven't improved a bit (the reason why is beyond my imagination). FYI the insert is this: insert into GEM_INV...

Using parameters in stored procedures where the column may be null

I want to (loosely) have a stored procedure like select * from table where col1 like @var the default value of @var is '%', so if I don't have a value for @var it should return every row. However, the problem is it doesn't return rows where col1 is null. How do I return all rows if @var = '%' and rows that are like @var if it does hav...

Replacing cube with rollup in Oracle SQL

A homework assignment I have asks the following question: Show how to express \group by cube (a, b, c, d)" using rollup rather than cube. I really don't have the faintest clue how to do this. Where would I start or where could I look for some help? ...

Oracle MERGE does not INSERT

I have this simple example I can't seems to get working : MERGE INTO mytable mt USING dual ON (mt.id = 'AAA' ) WHEN MATCHED THEN UPDATE SET mt.name = 'updated' WHEN NOT MATCHED THEN INSERT (mt.id , mt.name ) VALUES ('AAA', 'Gooood' ); If a 'AAA' record exists in the table, it is updated successfully. But if does no...

Sybase: trying to lock a record on select so another caller does not get the same one

I have a simple table in Sybase, let's say it looks as follows: CREATE TABLE T ( name VARCHAR(10), entry_date datetime, in_use CHAR(1) ) I want to get the next entry based on order of "entry_date" and immediately update "in_use" to "Y" to indicate that the record is not available to the next query that comes in. The kicker i...

Deleting rows from a table cause index fragmentation?

I removed some rows from a very large table. Then I ran a query that usually runs within a few seconds and found it to be running very slowly after deleting the rows. I re-built my index and ran my query and found it to be fast again. Could deleting those rows caused the index to be fragmented? ...

DB2 - How to run an ad hoc select query with a parameter in IBM System i Access for Windows GUI Tool

I would like to run some ad hoc select statements in the IBM System I Navigator tool for DB2 using a variable that I declare. For example, in the SQL Server world I would easily do this in the SQL Server Management Studio query window like so: DECLARE @VariableName varchar(50); SET @VariableName = 'blah blah'; select * from TableName ...

How can I search all of the databases on my mysql server for a single string of information

I have around 150 different databases, with dozens of tables each on one of my servers. I am looking to see which database contains a specific person's name. Right now, i'm using phpmyadmin to search each database indvidually, but I would really like to be able to search all databases and all tables at once. Is this possible? How wou...

SQL: Quickly getting the value of column B wherever column A is minimum

I'm trying to do what seems like it should be a simple SQL operation, but I'm just not finding the right syntax to do it quickly. I'm using SQLite. The basic problem is that I have a table whose primary key is (objUid, time). It contains the columns objUid, time, and frame. For the purposes of this question, frame is an opaque value....

Convert SQL query to Django friendly format for application

I have an SQL query thats runs on the Postgres database of my Django based webapp. The query runs against the data stored by Django-Notifications (a reusable app) and returns a list of email addresses that have not opted out of a specific notice type. What I would really like to be able to do is to build an application that does this o...

SQL Server variables

Why do these queries return different values? The first returns a result set as expected, but the second (which as far as I can tell is exactly the same) does not. Any thoughts? 1: declare @c varchar(200) set @c = 'columnName' select top 1 * from myTable where @c is not null and len(convert(varchar, @c)) > 0 2: SELECT top...

COUNT() Function in conjunction with NOT IN clause not working properly with varchar field (T-SQL)

Hi all. I came across a weird situation when trying to count the number of rows that DO NOT have varchar values specified by a select statement. Ok, that sounds confusing even to me, so let me give you an example: Let's say I have a field "MyField" in "SomeTable" and I want to count in how many rows MyField values do not belong to a dom...

Oracle to Postgres Gotchas

I have been working on porting some Oracle DB code to Postgres, and I am noticing some nomenclature differences (Schemas vs Databases) etc. What are some good resources for dealing with these gotchas? Any tips? What needs to be kept in mind? ...

How to limit the return of a join to just one table?

Today at work we got into a discussion about which is the best way to do a query like this : For instance lets assume a users table : tblUsers ID = Autoint Name = String and a login table : tblLogin ID = AUtoint UserID = Int IP = String Browser = String OS = String timestamp = DateTime What would...

IS vs AS keywords for PL/SQL Oracle Function or Procedure Creation

I have been trying to find out what the difference is between the IS and AS keywords in PL/SQL when creating an Oracle function or procedure. I have searched and have been unable to find any information on this. Does anyone know the difference? ...

SQL - Selecting portion of a string

If I have a simple table where the data is such that the rows contains strings like: /abc/123/gyh/tgf/345/6yh/5er In SQL, how can I select out the data between the 5th and 6th slash? Every row I have is simply data inside front-slashes, and I will only want to select all of the characters between slash 5 and 6. ...

TSQL memory related queries

I need to find if /3GB switch and /PAE is enabled on a server. Also, I want to know the size of page file and physical RAM on the server. I can check them manually but how can I check them using TSQL on both SQL 2000 and SQL 2005? ...

Deleting top rows only. SQL Server

How do I delete only the top row of a table in SQL Server? I did: set rowcount 1; delete * from table; set rowcount 0; But I am not sure if its a good way to do it. Is there any better way to accomplish that? ...

trying to read sql statement c#

string queryStr = "select max(patient_history_date_bio) " + "as med_date, medication_name from biological where " + "(patient_id = " + patientID.patient_id + ") " + "group by medication_name;"; using (var conn = new SqlConnection(connStr)) using (var cmd = new SqlCommand(queryStr, conn)) { conn.Open(); using (SqlD...

Inserting one record at a time to multiple tables from a table

Hi, I have one flat MAIN_TABLE. I need to insert the records from this table to multiple TABLES. eg. MAIN_TABLE col1, col2, col3, col4, col5 PARENT1_TABLE PT1_ID(PK), col1,col2 PARENT2_TABLE PT2_ID(PK), col3,col4 PARENT2_CHILD_TABLE P2C_ID(PK), PT2_ID(FK), col5, col6 so on. The goal is, I have to move the record from that flat M...