How to replace Cursor in SQL Server?

When using PL/SQL objects i get a weird output...?

  • using the code: DROP TABLE OOAIRPORTS / CREATE OR REPLACE TYPE airport_object AS OBJECT ( CITY VARCHAR2(150), STATE VARCHAR2(150), AIRPORT VARCHAR2(150), ABBREV VARCHAR2(150) ); / CREATE TABLE OOAIRPORTS (AIRPORT_INFO airport_object) / DECLARE cursor airportimport IS SELECT * FROM AIRPORTS; ap airport_object; ci VARCHAR2(150); st VARCHAR2(150); air VARCHAR2(150); abb VARCHAR2(150); BEGIN open airportimport; --EXECUTE IMMEDIATE 'CREATE TABLE OOAIRPORTS (AIRPORT airport_object)'; loop fetch airportimport into ci, st, air, abb; --fetch airportimport into ap; exit when airportimport%notfound; insert into OOAIRPORTS values (airport_object(ci, st, air, abb)); end loop; close airportimport; END; / SELECT * FROM OOAIRPORTS i get the following output... AIRPORT ------------------------- oracle.sql.STRUCT@9557e1 oracle.sql.STRUCT@bc8ba5 oracle.sql.STRUCT@73fe03 etc. how kind of output is this? how do i format the output into normal terms? I should get: AIRPORT ------------------------- Gustavas AK Gustavus Airport GST

  • Answer:

    The only 'column' of OOAIRPORTS is of type airport_object. Since it's a structure instead of a regular vartype, Oracle doesn't know how to display it. What you'll probably have to do is create a UDF to format your structure for display by concatenating the various structure parts into one large string. Then instead of doing SELECT * (which is generally poor practice anyway), do something like SELECT display_airport_info_obj(airport_info) FROM ooairports

Palak at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

The only 'column' of OOAIRPORTS is of type airport_object. Since it's a structure instead of a regular vartype, Oracle doesn't know how to display it. What you'll probably have to do is create a UDF to format your structure for display by concatenating the various structure parts into one large string. Then instead of doing SELECT * (which is generally poor practice anyway), do something like SELECT display_airport_info_obj(airport_info) FROM ooairports

TheMadProfessor

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.